Near field communication method and related apparatus

By synchronizing random numbers and encrypted data between NFC devices and NFC card readers, the access layer and application layer are bound together, solving the problem of intermediate devices relaying APDUs in NFC services and improving the security and reliability of NFC services.

WO2026237952A1PCT designated stage Publication Date: 2026-11-19HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2026/096461
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2025-05-14
Filing Date
2026-05-12
Publication Date
2026-11-19

AI Technical Summary

Technical Problem

When existing NFC devices and NFC card readers perform business operations, there is a tendency for intermediate devices to relay NFC application layer protocol data units (APDUs), which reduces the security of NFC services.

Method used

By synchronizing random numbers and encrypted data between NFC devices and NFC card readers, the access layer and application layer are bound together, preventing intermediate devices from relaying APDUs. This includes random number verification and encrypted data encryption/decryption processing.

Benefits of technology

It improves the security of NFC services, prevents intermediate devices from relaying NFC APDUs, and enhances the security and reliability of data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2026096461_19112026_PF_FP_ABST
    Figure CN2026096461_19112026_PF_FP_ABST
Patent Text Reader

Abstract

The present application discloses a near field communication (NFC) method and a related apparatus. An NFC apparatus and an NFC card reading device can synchronize a first random number at an NFC access layer, and synchronize a second random number at an NFC application layer. If the NFC apparatus verifies that a first random number and a second random number which are stored by the NFC apparatus are the same as a first random number and a second random number which are stored by the NFC card reading device, the NFC apparatus may execute an NFC service with the NFC card reading device. If the NFC apparatus verifies that the first random numbers respectively stored by the NFC apparatus and the NFC card reading device are different or the second random numbers respectively stored by the NFC apparatus and the NFC card reading device are different, the NFC apparatus prohibits executing the NFC service with the NFC card reading device. In this way, when the NFC apparatus executes the NFC service with the NFC card reading device, an intermediate device relaying NFC APDUs between the NFC apparatus and the NFC card reading device can be prevented, thereby improving the security of the NFC service.
Need to check novelty before this filing date? Find Prior Art

Description

A near-field communication method and related device

[0001] This application claims priority to Chinese Patent Application No. 202510622538.4, filed on May 14, 2025, entitled “A Near-Field Communication Method and Related Device”, the entire contents of which are incorporated herein by reference. Technical Field

[0002] This application relates to the field of wireless communication technology, and in particular to a near-field communication method and related apparatus. Background Technology

[0003] With the development of wireless communication technology, Near Field Communication (NFC) technology has been widely used. NFC technology evolved from the integration of contactless radio frequency identification (RFID) and interconnection technologies. In NFC technology, NFC-enabled devices can operate in three modes when communicating via NFC: Proximity Coupling Device (PCD) mode (also known as reader mode), Proximity Integrated Circuit Card (PICC) mode (also known as card emulation mode), and Point-to-Point (P2P) mode.

[0004] Currently, some NFC-enabled electronic devices (such as mobile phones, tablets, and wearable devices) support both PICC and PCD modes. Using multiple electronic devices allows an NFC reader to read data from an NFC device located outside the reader's radio frequency field, enabling NFC transactions and other NFC-based services. However, this reduces the security of NFC transactions. Summary of the Invention

[0005] This application provides a near-field communication method and related apparatus, which prevents the use of an intermediate device to relay NFC application protocol data units (APDUs) between the NFC device and the NFC card reader when performing NFC services, thereby improving the security of NFC services.

[0006] In a first aspect, embodiments of this application provide a near-field communication method applied to a near-field communication (NFC) device, comprising: receiving a first access layer command sent by an NFC card reader; sending a first access layer response to the NFC card reader, wherein the first access layer response carries a first random number; receiving a random number acquisition command sent by the NFC card reader; sending a random number acquisition response to the NFC card reader, wherein the random number acquisition response carries a second random number; receiving an authentication command sent by the NFC card reader, wherein the authentication command carries first encrypted data; and if the first encrypted data is successfully verified based on the first random number and the second random number, performing NFC services with the NFC card reader.

[0007] According to the near-field communication method provided in this application, an NFC device and an NFC reader can synchronize a first random number at the NFC access layer and a second random number at the NFC application layer. If the NFC device verifies that the first random number stored on the NFC device is the same as the first random number stored on the NFC reader, and the second random number stored on the NFC device is also the same as the second random number stored on the NFC reader, the NFC device can perform NFC services with the NFC reader. This prevents the need for an intermediary device to relay NFC APDUs between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0008] In one possible implementation, the method further includes: if verifying the first encrypted data based on the first random number and the second random number fails, prohibiting NFC transactions with the NFC reader. This allows prohibiting NFC transactions with the NFC reader when the NFC device verifies that the first random number stored on the NFC device differs from the first random number stored on the NFC reader, or that the second random number stored on the NFC device differs from the second random number stored on the NFC reader. This prevents the need for an intermediary device to relay NFC application protocol data units (APDUs) between the NFC device and the NFC reader during NFC transactions, thus improving the security of NFC transactions.

[0009] In one possible implementation, before receiving the random number acquisition command sent by the NFC reader, the method further includes: receiving a program selection command sent by the NFC reader, wherein the program selection command carries an identifier of a first applet; and sending a program selection response to the NFC reader, the program selection response indicating that the first applet has been successfully selected. In this way, the first applet that the NFC device interacts with at the application layer with the NFC reader can be selected.

[0010] In one possible implementation, if the verification of the first encrypted data based on the first random number and the second random number is successful, the method further includes: sending a first authentication response to the NFC card reader, the first authentication response carrying a first authentication result, the first authentication result being used to indicate successful authentication. This allows the NFC card reader to know that the NFC device has successfully authenticated, thereby enabling the NFC card reader to perform NFC transactions with the NFC device.

[0011] In one possible implementation, if verifying the first encrypted data based on the first random number and the second random number fails, the method further includes: sending a second authentication response to the NFC reader, the second authentication response carrying a second authentication result, the second authentication result indicating authentication failure. This allows the NFC reader to know that the NFC device's authentication has failed, thereby preventing the NFC reader and the NFC device from performing NFC services.

[0012] In one possible implementation, verifying the first ciphertext data based on the first random number and the second random number includes: generating a first parameter based on the first random number and the second random number; decrypting a second parameter from the first ciphertext data using a first key; and determining that the verification of the first ciphertext data was successful if the second parameter is the same as the first parameter. In this way, the second parameter can be decrypted from the first ciphertext data first, and then it can be determined whether the second parameter is the same as the first parameter, thereby achieving the verification of the first ciphertext data.

[0013] In one possible implementation, verifying the first ciphertext data based on the first random number and the second random number includes: generating a first parameter based on the first random number and the second random number; encrypting the first parameter using a first key to obtain second ciphertext data; and determining that the verification of the first ciphertext data was successful if the second ciphertext data is the same as the first ciphertext data. Thus, the verification of the first ciphertext data can be achieved by first generating the second ciphertext data based on the first parameter and then determining whether the second ciphertext data is the same as the first ciphertext data.

[0014] In one possible implementation, the first access layer command is an anti-collision command, and the first access layer response is an anti-collision response. This allows for the binding of the access layer and the application layer in certain NFC protocols, preventing the need for an intermediary device to relay NFC APDUs between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0015] In one possible implementation, the first access layer command is a probe frame, and the first access layer response is a probe ACK frame. This allows for the binding of the access layer and the application layer in certain NFC protocols, preventing the need for an intermediary device to relay NFC APDUs between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0016] Secondly, embodiments of this application provide another near-field communication method applied to an NFC card reader, comprising: sending a first access layer command to an NFC device; receiving a first access layer response sent by the NFC device, wherein the first access layer response carries a first random number; sending a random number acquisition command to the NFC device; receiving a random number acquisition response sent by the NFC device, wherein the random number acquisition response carries a second random number; encrypting the first random number and the second random number to obtain first ciphertext data; sending an authentication command to the NFC device, wherein the authentication command carries the first ciphertext data; and, if a first authentication response is received from the NFC device, performing NFC services with the NFC device, wherein the first authentication response carries a first authentication result, the first authentication result being used to indicate successful authentication.

[0017] In one possible implementation, the method further includes: if a second authentication response is received from the NFC device, prohibiting NFC business with the NFC device, wherein the second authentication response carries a second authentication result, which is used to indicate authentication failure.

[0018] In one possible implementation, before sending the random number acquisition command to the NFC device, the method further includes: sending an app selection command to the NFC device, wherein the app selection command carries an identifier of a first applet; and receiving an app selection response sent by the NFC device, the app selection response indicating that the first applet has been successfully selected.

[0019] In one possible implementation, encrypting the first random number and the second random number to obtain the first ciphertext data includes: generating a first parameter based on the first random number and the second random number; and encrypting the first parameter using a first key to obtain the first ciphertext data.

[0020] In one possible implementation, the first access layer command is an anti-collision command, and the first access layer response is an anti-collision response.

[0021] In one possible implementation, the first access layer command is a probe frame, and the first access layer response is a probe ACK frame.

[0022] The beneficial effects of the second aspect and any possible implementation thereof can be referred to the beneficial effects of the first aspect and any possible implementation thereof, and will not be repeated here.

[0023] Thirdly, embodiments of this application provide a near-field communication method applied to an NFC card reader, comprising: sending one or more application layer commands to the NFC device; receiving one or more application layer responses sent by the NFC device; determining a command execution duration based on the receiving time of the one or more application layer responses and the sending time of the one or more application layer commands; and performing NFC services with the NFC device if the command execution duration is less than or equal to a first duration threshold.

[0024] A near-field communication (NFC) method provided in the application embodiment can determine the command execution duration at the NFC application layer by considering the reception time of one or more application layer responses and the transmission time of the one or more application layer commands. The command execution duration is then compared with a first duration threshold. If the command execution duration is less than or equal to the first duration threshold, it indicates that there is no intermediate device relaying the APDU transmitted between the NFC device and the NFC reader at the application layer. Therefore, the NFC device and the NFC reader can perform NFC services. This prevents the existence of an intermediate device relaying NFC APDUs between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0025] In one possible implementation, the method further includes: if the command execution time exceeds a first time threshold, prohibiting NFC services with the NFC device. Thus, if the command execution time exceeds the first time threshold, it indicates that there is an intermediate device relaying the APDU transmitted between the NFC device and the NFC reader at the application layer; therefore, the NFC device and the NFC reader are prohibited from performing NFC services. This prevents the existence of an intermediate device relaying the NFC APDU between the NFC device and the NFC reader when performing NFC services, improving the security of NFC services.

[0026] In one possible implementation, the one or more application layer commands include a first application layer command, and the one or more application layer commands include a first application layer response; wherein the first application layer response is an application layer response replying to the first application layer command; determining the command execution duration based on the reception time of the one or more application layer responses and the transmission time of the one or more application layer commands includes: determining the command execution duration as the difference between the reception time of the first application layer response and the transmission time of the first application layer command. Thus, the NFC card reader can determine whether there is an intermediate device forwarding APDU between the NFC card reader and the NFC device by detecting the interval between the first application layer response and the first application layer command.

[0027] In one possible implementation, the first application layer command is a first speed measurement command, and the second application layer command is a first speed measurement response. In this way, the NFC reader can quickly determine the command execution duration between the NFC reader and the NFC device based on the reception time of the first speed measurement response and the transmission time of the first speed measurement command, thereby quickly determining whether there is an intermediate device relaying the NFC APDU between the NFC reader 200 and the NFC device 100.

[0028] In one possible implementation, the first application layer command can be the first application layer command sent by the NFC reader in the NFC application layer. The first application layer response can be the last application layer response sent by the NFC device before executing the NFC service. In this way, the NFC reader can comprehensively determine the total duration of the application layer interaction between the NFC reader and the NFC device before executing the NFC service based on the reception time of the last application layer response before executing the NFC service and the transmission time of the first application layer command, thereby accurately identifying whether there is an intermediate device relaying the NFC APDU between the NFC reader and the NFC device.

[0029] In one possible implementation, the first duration threshold is preset in the NFC reader device.

[0030] In one possible implementation, the first speed measurement response includes the first duration threshold.

[0031] In one possible implementation, the one or more application layer commands are M speed measurement commands, and the one or more application layer responses are M speed measurement responses, where M is a positive integer; determining the command execution duration based on the reception time of the one or more application layer responses and the transmission time of the one or more application layer commands includes: determining the command execution duration based on the reception time of the M speed measurement responses and the transmission time of the M speed measurement commands.

[0032] In this way, based on the reception times of M speed measurement responses and the transmission times of M speed measurement commands, the command execution duration between the NFC reader 200 and the NFC device 100 can be determined, thereby accurately identifying whether there is an intermediate device relaying NFC APDU between the NFC reader and the NFC device. This prevents the existence of an intermediate device relaying NFC APDU between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0033] In one possible implementation, the M speed measurement commands carry N index bits, where N is a positive integer; the M speed measurement responses carry N response bits. By including index bits in the speed measurement commands and response bits in the speed measurement responses, the interception or tampering of the speed measurement commands and responses by intermediate devices can be prevented, thus improving the security of the speed measurement process.

[0034] In one possible implementation, before sending one or more application layer commands to the NFC device, the method further includes: sending a third random number to the NFC device; receiving a second random number sent by the NFC device; and determining a first speed measurement sequence and a second speed measurement sequence based on a second key, the third random number, and the fourth random number.

[0035] In one possible implementation, before determining the command execution duration based on the receiving time of the M speed measurement responses and the sending time of the M speed measurement commands, the method further includes: encrypting the second random number using the second key to obtain a first ciphertext; sending an authentication command to the NFC device, the authentication command carrying the first ciphertext; if a first authentication response sent by the NFC device is received, the first authentication response carrying a second ciphertext, verifying the second ciphertext using the second key, the third random number, and the fourth random number, and verifying the N response bit values ​​using the first speed measurement sequence, the second speed measurement sequence, and the N index bit values; determining the command execution duration based on the receiving time of the M speed measurement responses and the sending time of the M speed measurement commands includes: if the verification of the second ciphertext is successful and the verification of the N response bit values ​​is successful, determining the command execution duration based on the receiving time of the M speed measurement responses and the sending time of the M speed measurement commands.

[0036] In this way, after receiving the index bit value in the speed measurement command, the NFC device only needs to query the speed measurement sequence to obtain the response bit value corresponding to the index bit value, which shortens the time difference between the NFC device receiving the speed measurement command and sending the speed measurement response, thereby improving the accuracy of speed measurement. It can more accurately identify the situation where there is an intermediate device between the NFC device and the NFC card reader to transfer the NFC APDU.

[0037] Furthermore, the NFC reader and the NFC device can exchange a third random number and a second random number. Then, at the NFC application layer, the NFC reader and the NFC device can determine a first speed measurement sequence and a second speed measurement sequence based on the third random number and the second random number. Then, the NFC device can determine N response bit values ​​based on the first speed measurement sequence, the second speed measurement sequence, and N index bit values, thereby completing the encrypted transmission of the speed measurement command and speed measurement response. This prevents the use of intermediate devices to relay the NFC APDU, thus improving the security of NFC services.

[0038] In one possible implementation, the method further includes: if a second authentication response is received from the NFC device, the second authentication response is used to indicate that the verification of the first ciphertext has failed and to prohibit NFC business with the NFC device.

[0039] In one possible implementation, the method further includes: if the verification of the second ciphertext fails or the verification of the N response bit values ​​fails, NFC business with the NFC device is prohibited.

[0040] In one possible implementation, determining the first speed measurement sequence and the second speed measurement sequence based on the second key, the third random number, and the fourth random number includes: encrypting the third random number and the fourth random number using the second key and the second encryption / decryption algorithm to obtain a third ciphertext; determining the first speed measurement sequence based on the third ciphertext; and determining the second speed measurement sequence based on the third ciphertext and the second key.

[0041] In one possible implementation, sending a third random number to the NFC device includes: sending a second access layer command to the NFC device, the second access layer command carrying the third random number; receiving a fourth random number sent by the NFC device includes: receiving a second access layer response sent by the NFC device, the second access layer response carrying the fourth random number.

[0042] In one possible implementation, sending a third random number to the NFC device includes: sending a random number acquisition command to the NFC device, the random number acquisition command carrying the third random number; receiving a fourth random number sent by the NFC device includes: receiving a random number acquisition response sent by the NFC device, the random number acquisition response carrying the fourth random number.

[0043] Fourthly, embodiments of this application provide a communication system, characterized in that it includes an NFC device and an NFC card reader; wherein the NFC device is used to execute the near-field communication method in the first aspect and any possible implementation thereof. The NFC card reader is used to execute the near-field communication method in the second aspect and any possible implementation thereof.

[0044] Fifthly, embodiments of this application provide an NFC device, including one or more processors, one or more memories, and a transceiver. The transceiver, the one or more memories, and the one or more processors are coupled together. The one or more memories are used to store a computer program, which, when executed by the one or more processors, implements the near-field communication method described in the first aspect and any possible implementation thereof.

[0045] Sixthly, embodiments of this application provide an NFC card reader device, including one or more processors, one or more memories, and a transceiver. The transceiver, the one or more memories, and the one or more memories are coupled to the one or more processors. The one or more memories are used to store a computer program. When the one or more processors execute the computer program, they implement the near-field communication method in the second aspect and any possible implementation of the second aspect, or the third aspect and any possible implementation of the third aspect.

[0046] In a seventh aspect, embodiments of this application provide a computer-readable storage medium storing a computer program that, when run on a processor, implements the near-field communication method described in the first aspect and any possible implementation thereof.

[0047] Eighthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed on a processor, implements the near-field communication method of the second aspect and any possible implementation thereof, or the third aspect and any possible implementation thereof.

[0048] Ninthly, embodiments of this application provide a computer program product, including a computer program that, when run on a processor, implements the near-field communication method in the first aspect and any possible implementation thereof.

[0049] In a tenth aspect, embodiments of this application provide a computer program product, including a computer program that, when run on a processor, implements the near-field communication method in the second aspect and any possible implementation of the second aspect or the third aspect and any possible implementation of the third aspect.

[0050] In one aspect, embodiments of this application provide a chip system including a processing circuit and an interface circuit. The interface circuit is used to receive code instructions and transmit them to the processing circuit. The processing circuit is used to run the code instructions to execute the near-field communication method in the first aspect and any possible implementation thereof.

[0051] In a twelfth aspect, embodiments of this application provide a chip system including a processing circuit and an interface circuit. The interface circuit is used to receive code instructions and transmit them to the processing circuit. The processing circuit is used to execute the code instructions to perform the near-field communication method in the second aspect and any possible implementation of the second aspect or the third aspect and any possible implementation of the third aspect. Attached Figure Description

[0052] Figure 1 is a schematic diagram of the working principle of NFC provided in an embodiment of this application;

[0053] Figure 2 is a schematic diagram of the architecture of an NFC system provided in an embodiment of this application;

[0054] Figure 3 is a schematic diagram of the structure of an NFC device provided in an embodiment of this application;

[0055] Figure 4 is a schematic diagram of an NFC protocol stack provided in an embodiment of this application;

[0056] Figure 5 is a schematic diagram of the process by which the NFC card reader provided in the embodiment of this application remotely reads data from the NFC device through multiple electronic devices;

[0057] Figure 6 is a schematic diagram of the process by which the NFC card reader provided in the embodiment of this application remotely reads data from the NFC device through multiple electronic devices to conduct payment transactions.

[0058] Figure 7 is a flowchart illustrating a near-field communication method provided in an embodiment of this application;

[0059] Figure 8 is a flowchart illustrating one implementation scenario of the near-field communication method provided in this application embodiment;

[0060] Figure 9 is a flowchart illustrating a near-field communication method provided in an embodiment of this application;

[0061] Figure 10 is a flowchart illustrating a near-field communication method provided in an embodiment of this application;

[0062] Figure 11 is a schematic diagram of the interaction of a transaction transfer service in the NFC application layer according to an embodiment of this application;

[0063] Figure 12 is a flowchart illustrating a near-field communication method according to another embodiment of this application;

[0064] Figure 13 is a flowchart illustrating a near-field communication method according to another embodiment of this application;

[0065] Figure 14 is a schematic diagram of the hardware structure of an NFC device provided in an embodiment of this application;

[0066] Figure 15 is a schematic diagram of the communication device provided in an embodiment of this application;

[0067] Figure 16 is a schematic diagram of the communication device provided in an embodiment of this application;

[0068] Figure 17 is a schematic diagram of the communication device provided in an embodiment of this application;

[0069] Figure 18 is a schematic diagram of the structure of the communication device provided in the embodiment of this application. Detailed Implementation

[0070] The technical solutions in the embodiments of this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; the word "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0071] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0072] The working principle of NFC in the embodiments of this application is described below.

[0073] Figure 1 shows a schematic diagram of the working principle of NFC provided in an embodiment of this application.

[0074] As shown in Figure 1, the two parties communicating using NFC technology can include a proximity coupling device (PCD) (also known as an NFC card reader) and a proximity smart card (PICC). The PCD can achieve contactless communication with the PICC in close proximity. The PCD and PICC can allow near-field communication at specific data rates (e.g., 106kbps, 212kbps, 424kbps, or 848kbps) and specific frequencies (e.g., 13.56MHz). Communication between the PCD and PICC can occur at close range, for example, within a range of approximately 2 to 4 centimeters.

[0075] The PCD (Polymer Capacitor) can generate high-frequency alternating current to produce a radio frequency (RF) field of a specified frequency (e.g., 13.56 MHz), and transmit data to the PICC (Peripherally Input Cell) via this RF field. When the PICC is near the PCD, it can sense the RF field emitted by the PCD. Upon entering the RF field, the PICC can obtain energy from the PCD's RF field through electromagnetic induction, and use this energy to generate electricity to drive the internal circuitry of the PICC, thus enabling data transmission from the PCD to the PICC. Alternatively, the PICC can also transmit data to the PCD by modulating the RF field with a load, achieving data transmission from the PICC to the PCD.

[0076] In the embodiments of this application, PICC can be a physical NFC tag card. Some NFC devices (e.g., mobile phones, tablets, smartwatches, and other electronic devices) can also simulate themselves as PICCs that conform to NFC-related standards through data from NFC emulation cards to realize the functions of PICCs and interact with PCD via NFC.

[0077] The following describes an NFC system provided in an embodiment of this application.

[0078] Figure 2 shows a schematic diagram of the architecture of an NFC system 10 provided in an embodiment of this application.

[0079] As shown in Figure 2, the NFC system 10 may include an NFC device 100 and an NFC card reader 200. The NFC device 100 can simulate itself as a PICC (Private Label Card) conforming to NFC standards by using data information from an NFC emulation card to achieve PICC functionality. The NFC card reader 200 can act as a PCD (Private Label Card) to interact with the NFC device 100 in PICC mode.

[0080] In one possible implementation, the NFC device 100 can support both PICC mode and PCD mode. In PCD mode, the NFC device 100 can act as the PCD transmitting radio frequency field to communicate with the PICC. In PICC mode, the NFC device 100 can act as the PICC passively receiving the radio frequency field transmitted by the PCD, and perform NFC interaction with the PCD through load modulation technology.

[0081] In this embodiment, after the NFC function is enabled, the NFC device 100 can be in PICC mode. If the NFC device 100 supports both PCD mode and PICC mode, it can switch between PICC mode and PCD mode in a time-sharing manner after the NFC function is enabled.

[0082] In this embodiment, the NFC device 100 can be any of the following: mobile phone, tablet computer, handheld computer, desktop computer, laptop computer, ultra-mobile personal computer (UMPC), netbook, cellular phone, personal digital assistant (PDA), smart home devices such as smart screens and smart speakers, wearable devices such as smart bracelets, smartwatches, and smart glasses, extended reality (XR) devices such as augmented reality (AR), virtual reality (VR), and mixed reality (MR), in-vehicle devices, or smart city devices.

[0083] The NFC card reader device 200 can be any of the following: mobile phone, tablet computer, handheld computer, desktop computer, laptop computer, super mobile personal computer, netbook, cellular phone, personal digital assistant, as well as smart home devices such as smart screens and smart speakers, wearable devices such as smart bracelets, smartwatches, and smart glasses, extended reality devices such as augmented reality, virtual reality, and mixed reality, vehicles, gates, smart locks, card readers, payment terminals, ticket purchase and / or ticket verification terminals, bank service terminals, and document card reading devices.

[0084] The following is a schematic diagram of the structure of an NFC device 100 provided in the embodiments of this application.

[0085] Figure 3 shows a schematic diagram of the structure of an NFC device 100 provided in an embodiment of this application.

[0086] As shown in Figure 3, the NFC device 100 may include a processor 101 and an NFC module 102. The processor 101 may run one or more applications. These applications may include one or more of the following: a wallet application, one or more host-based card emulation (HCE) applications, etc. Optionally, the NFC device 100 may also include a secure element (SE) 103 and / or a subscriber identity module (SIM) card. The processor 101 may be connected to the NFC module 102, the SE 103, and the SIM card 104, respectively. The NFC module 102 may also be connected to the SE 103 and the SIM card 104.

[0087] The NFC module 102 may include an NFC controller (not shown in Figure 3), an NFC transceiver (not shown in Figure 3), and an NFC memory (not shown in Figure 3). The NFC controller may be connected to the processor 101, and may also be connected to the NFC transceiver and the NFC memory, respectively.

[0088] The NFC controller is primarily used for modulation and demodulation of contactless communication signals, controlling the input and output of data in the NFC memory, and interacting with the processor 101. The NFC transceiver is used to transmit and receive NFC signals (e.g., 13.56MHz radio frequency signals), and may include an electromagnetic compatibility (EMC) filter circuit, a matching circuit, a receiving circuit, and an NFC antenna, where the NFC antenna may be a loop antenna, used to enable proximity-based contactless communication capabilities of the NFC module 102. The NFC memory can be used to store data sent by the NFC module 102 to the NFC reader device 200, as well as data received from the NFC reader device 200. In some embodiments, the NFC memory can be a shared memory that can be used by the various components in the NFC module 102; for example, some data in the NFC memory can be accessed by the NFC controller, while other data can be accessed by the SE 103.

[0089] In other embodiments, the NFC memory may be a collection of multiple memories. For example, the NFC controller may include a first memory among these multiple memories. The first memory may include instructions or data that the NFC controller has used or reused. If the NFC controller needs to use the instruction or data again, it can directly retrieve it from the first memory, thus reducing the waiting time of the NFC controller. SE103 may include a second memory among these multiple memories. The second memory may include card information such as that of the NFC emulator based on the secure element. Thus, if SE103 needs to read the card information of the NFC emulator, it can read the card information of the NFC emulator from the second memory in SE103. SIM card 104 may include a third memory among these multiple memories. The third memory may include card information such as that of the NFC emulator based on the SIM card. Thus, if SIM card 104 needs to read the card information of the NFC emulator, it can read the card information of the NFC emulator from the third memory in SIM card 104.

[0090] In some embodiments, the NFC memory described above can also store routing information. In some embodiments, this routing information can be controlled or managed by the NFC controller, and can include a routing table consisting of a list of routing rules. Each routing rule contains an applet identifier (AID) and a destination; the destination is the location where the applet used to implement the business logic of the NFC emulator card runs. The destination can include an HCE application running in the processor 101 of the NFC device 100, or an SE 103 or SIM card 104 connected to the NFC controller.

[0091] The SE103 and NFC module 102 can be two separate chips. Alternatively, the SE103 and NFC module 102 can be packaged into a single chip.

[0092] The NFC device 100 can activate one or more NFC emulator cards in an application based on user input, thereby enabling the NFC device 100 to support one or more NFC services. The service processing logic for the NFC emulator card within the NFC device 100 is specifically implemented by an applet. The applet can be stored and run in the corresponding hardware device or software module (e.g., HCE application, SIM card, SE, etc.) of the NFC emulator card.

[0093] The NFC device 100's card emulation mode can be divided into hardware-based virtual card mode and software-based HCE mode. Among them:

[0094] 1. In hardware-based virtual card mode, the NFC device 100 can provide the operating environment for the Applet corresponding to the NFC emulator card, as well as the storage and processing of the NFC emulator card's business data, through the SE103 or SIM card 104. The NFC module 102, acting as the front end of contactless communication, receives commands from the external PCD and forwards them to the SE103 or SIM card 104. The Applet in the SE103 or SIM card 104 then processes the commands and sends response data to the external PCD via the NFC module 102. Users can activate one or more NFC emulator cards in a wallet application, which can write the Applets and card data of one or more NFC emulator cards into the SE103. Alternatively, users can activate one or more NFC emulator cards in a SIM card application, which can write the Applets and card data of one or more NFC emulator cards into the SIM card 104 for storage.

[0095] 2. In software-based HCE mode, the HCE application running in processor 101 can provide the operating environment for the applet corresponding to the NFC emulator card, as well as the storage and processing of the NFC emulator card's business data. After receiving a command from an external PCD, NFC module 102 can send the command to the HCE application. The HCE application can process the command received by the NFC module through the applet running in the HCE application or a cloud server, and generate response data for the PCD. The HCE application can then send the response data to NFC module 102. NFC module 102 can then send the response data to the external PCD. Users can activate one or more NFC emulator cards in the HCE application. The HCE application can run one or more NFC emulator card applets and store the NFC emulator card data on the local memory of NFC device 100 or on a cloud server.

[0096] Optionally, the processor 101 can also run an NFC basic service module. The NFC basic service module can be used to provide common management functions for one or more NFC services. These common management functions may include file management, card activation, security management, service routing management, and other functions.

[0097] For example, in the card emulation scenario described above, the NFC device 100 has a native NFC-related application installed, and users can also download and install third-party applications from app stores. Generally, the native application can use a hardware-based virtual card solution, while the third-party application can use an HCE solution. The native application can be a wallet application, etc., and the third-party application can be, for example, Alipay, PayPal, WeChat, etc. The above examples are merely for explaining this application and should not be construed as limiting it.

[0098] The following describes an NFC protocol stack provided in an embodiment of this application.

[0099] Figure 4 shows a schematic diagram of an NFC protocol stack provided in an embodiment of this application.

[0100] As shown in Figure 4, the NFC protocol stack can include a physical layer, a radio frequency layer, an access layer, a transport layer, and an application layer.

[0101] The physical layer can be used to implement the physical characteristics of NFC technology communication.

[0102] The radio frequency (RF) layer can be used to implement RF specifications for NFC technology communication, such as data rate and RF signal frequency.

[0103] The access layer can be used to implement functions such as polling and device discovery, service result notification, card conflict management, transmission protocol negotiation, timeout and retransmission mechanism, PICC / PCD mode switching, and converged card selection.

[0104] The transport layer includes a high-speed data transmission protocol, which enables data transmission between the PCD and PICC at the application layer.

[0105] The application layer can be used to implement one or more NFC services (also known as NFC business processes) and one or more service management policies. The one or more NFC services may include codeless payment, electronic tickets, access control, digital ID cards, all-scenario contactless payment, and short-range data transmission. The one or more business management policies may include any one or more of the following: file management, card long-term activation, security management, and service routing management. The processing logic of the NFC services can be executed by Applets. In one possible implementation, the processing logic of the service management policies can be executed by the NFC basic service module.

[0106] The following describes the process by which an NFC card reader remotely reads data from an NFC device through multiple electronic devices.

[0107] Figure 5 illustrates a schematic diagram of the process by which the NFC card reader device provided in this application remotely reads data from an NFC device through multiple electronic devices.

[0108] As shown in Figure 5, the process of an NFC card reader remotely reading data from an NFC device through multiple electronic devices can be applied to a communication system 50. This communication system 50 may include an NFC device 100A, an electronic device 200A, an electronic device 100B, and an NFC card reader 200B.

[0109] NFC device 100A and electronic device 100B can operate in PICC mode, while electronic device 200A and NFC reader 200B can operate in PCD mode. Therefore, when NFC device 100A enters the radio frequency field of electronic device 200A, NFC device 100A can establish NFC link A with electronic device 200A through command interaction at the NFC access layer. When electronic device 100B enters the radio frequency field of NFC reader 200B, electronic device 100B can establish NFC link B with NFC reader 200B through command interaction at the NFC access layer. Electronic device 200A and electronic device 100B can establish a relay link through a server of a specified application.

[0110] 1. After the NFC card reader 200B and the electronic device 100B establish an NFC link B through command interaction at the NFC access layer, the NFC card reader 200B can send NFC application layer commands to the electronic device 100B through the NFC link B.

[0111] 2. Electronic device 100B can send NFC application layer commands to electronic device 200A via a relay link.

[0112] 3. Electronic device 200A can send NFC application layer commands to NFC device 100A via NFC link A.

[0113] 4. NFC device 100A can send an NFC application layer response to electronic device 200A via NFC link A.

[0114] 5. Electronic device 200A can send an NFC application layer response to electronic device 100B via a relay link.

[0115] 6. Electronic device 100B can send the NFC application layer response to NFC card reader 200B via NFC link B.

[0116] As shown in Figure 5, the NFC reader 200B can transmit NFC application protocol data units (APDUs) between electronic devices 100A and 200A, even at a distance from the NFC device 100A. The APDU includes application layer commands and / or application layer responses. Thus, even if the NFC device 100A is outside the radio frequency field of the NFC reader 100A, the NFC reader 200B can still read the NFC data of the NFC device 100A, thereby conducting NFC transactions. This reduces the security of NFC transactions. For example, when the NFC transaction is a money transfer, the NFC device 100A can be a bank card, and the NFC reader 200B can be a POS machine. When the NFC reader 200B remotely reads the NFC data of the NFC device 100A without distance limitations, it is easy for funds deposited in the user's bank account corresponding to the NFC device 100A to be remotely transferred, thereby compromising the user's financial security.

[0117] The following section describes in detail the process by which an NFC card reader remotely reads data from an NFC device through multiple electronic devices to conduct payment transactions, based on the aforementioned communication system 50.

[0118] Figure 6 illustrates the process by which the NFC card reader device provided in this embodiment of the application remotely reads data from the NFC device through multiple electronic devices to conduct payment transactions.

[0119] As shown in Figure 6, the process of an NFC card reader remotely reading data from an NFC device through multiple electronic devices to conduct payment transactions can include the following steps S1-S16.

[0120] S1. User A installs and registers the specified application A on electronic device 200A.

[0121] In this scenario, user B will call user A and instruct user A to install and register a specified application A on electronic device 200A, and guide user A to bring electronic device 200A close to NFC device 100A.

[0122] S2. User A brings electronic device 200A close to NFC device 100A to establish NFC link A between electronic device 200A and NFC device 100A.

[0123] When electronic device 200A is close to NFC device 100A, NFC device 100A enters the radio frequency field generated by electronic device 100A. NFC device 100A can establish NFC link A with electronic device 200B through command interaction at the NFC access layer.

[0124] S3. User B installs and registers the specified application B on electronic device 100B.

[0125] Among them, the designated application B installed on electronic device 100B and the designated application A installed on electronic device 200A can establish a relay link through the server.

[0126] S4. User B enters the transaction amount on the NFC card reader 200B.

[0127] S5. User B brings electronic device 100B close to NFC card reader 200B to establish an NFC link B between electronic device 100B and NFC card reader 200B.

[0128] When electronic device 100B is close to NFC card reader 200B, electronic device 100B enters the radio frequency field generated by NFC card reader 200B. Electronic device 100B can establish NFC link B with NFC card reader 200B through command interaction at the NFC access layer.

[0129] S6. The NFC card reader 200B sends NFC application layer commands to a designated application B on the electronic device 100B via the NFC link B.

[0130] S7. The designated application B on electronic device 100B sends an NFC application layer command to the designated application A on electronic device 200A via a relay link.

[0131] S8. A designated application A on electronic device 200A sends an NFC application layer command to NFC device 100A via NFC link A.

[0132] S9. NFC device 100A sends an NFC application layer response to a designated application A on electronic device 200A via NFC link A.

[0133] S10. Designated application A on electronic device 200A sends an NFC application layer response to designated application B on electronic device 100B via a relay link.

[0134] S11. Electronic device 100B sends an NFC application layer response to NFC card reader 200B via NFC link B.

[0135] The NFC card reader 200B can remotely read the NFC data of the NFC device 100A by sending NFC application layer commands to the NFC device 100A or receiving NFC application layer responses from the NFC device 100A through the electronic devices 100B and 200A.

[0136] S12. User A enters the payment password of NFC device 100A on electronic device 200A.

[0137] In this process, a designated application on electronic device 200A will guide user A to enter the payment password of NFC device 100A.

[0138] S13. Designated application A on electronic device 200A sends the payment password of NFC device 100A to designated application B on electronic device 100B via a relay link.

[0139] After obtaining the payment password of the NFC device 100A, the designated application A on the electronic device 200A will send the payment password of the NFC device 100A to the designated application B on the electronic device 100B via a relay link.

[0140] S14. Electronic device 100B displays the payment password of NFC device 100A.

[0141] S15. User B enters the payment password of NFC device 100A on NFC card reader 200B.

[0142] S16. The NFC card reader 200B transfers the transaction amount from bank account A corresponding to NFC device 100A to bank account B of NFC card reader 200B.

[0143] After obtaining the payment password and NFC data from the NFC device 100A, the NFC card reader 200B can transfer the transaction amount from bank account A corresponding to the NFC device 100A to bank account B corresponding to the NFC card reader 200B based on the payment password and NFC data from the NFC device 100A.

[0144] As shown in Figure 6, even if NFC device 100A is outside the radio frequency field of NFC card reader 100A, NFC card reader 200B can still obtain NFC data from NFC device 100A through the relay link established between electronic device 200A and electronic device 100B. This allows NFC card reader 200B to remotely read NFC data from NFC device 100A without distance limitations, potentially leading to the remote transfer of funds deposited by user A in bank account A corresponding to NFC device 100A, thus compromising the security of user A's funds.

[0145] Therefore, this application provides a near-field communication method in which an NFC device 100 and an NFC reader 200 can synchronize a first random number at the NFC access layer and a second random number at the NFC application layer. If the NFC device 100 verifies that the first random number stored on the NFC device 100 is the same as the first random number stored on the NFC reader 200 and that the second random number stored on the NFC device 100 is the same as the second random number stored on the NFC reader 200, the NFC device 100 can perform NFC services with the NFC reader 200. If the NFC device 100 verifies that the first random number stored on the NFC device 100 is different from the first random number stored on the NFC reader 200 or that the second random number stored on the NFC device 100 is different from the second random number stored on the NFC reader 200, the NFC device 100 prohibits performing NFC services with the NFC reader 200. This prevents the need for an intermediate device to relay NFC APDUs between the NFC device 100 and the NFC reader 200 when performing NFC services, thus improving the security of NFC services.

[0146] This application also provides a near-field communication (NFC) method. An NFC reader 200 can send one or more application-layer commands to an NFC device 100. The NFC reader 200 can also receive one or more application-layer responses sent by the NFC device 100. The NFC reader 200 can determine the command execution duration based on the sending time of the one or more application-layer commands and the receiving time of the one or more application responses. If the command execution duration is less than or equal to a first duration threshold, the NFC reader 200 can perform NFC services with the NFC device 100. If the command execution duration is greater than the first duration threshold, the NFC reader 200 and the NFC device 100 are prohibited from performing NFC services. This allows for accurate identification of whether there is an intermediate device relaying NFC APDU between the NFC reader 200 and the NFC device 100. This prevents the existence of an intermediate device relaying NFC APDU between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0147] In one possible implementation, the one or more application layer commands include a first application layer command, and the one or more application layer commands include a first application layer response; wherein the first application layer response is an application layer response replying to the first application layer command; determining the command execution duration based on the reception time of the one or more speed measurement responses and the transmission time of the one or more speed measurement commands includes: determining the command execution duration as the difference between the reception time of the first application layer response and the transmission time of the first application layer command.

[0148] In one possible implementation, the first application layer command is a first speed measurement command, and the second application layer command is a first speed measurement response. Determining the command execution duration based on the reception time of the one or more application layer responses and the transmission time of the one or more application layer commands includes: determining the command execution duration as the difference between the reception time of the first application layer response and the transmission time of the first application layer command. Optionally, the first application layer response may carry the aforementioned first duration threshold.

[0149] In one possible implementation, the one or more application layer commands are M speed measurement commands, and the one or more application layer responses are M speed measurement responses, where M is a positive integer. Determining the command execution duration based on the reception time of the one or more application layer responses and the transmission time of the one or more application layer commands includes: determining the command execution duration based on the reception time of the M speed measurement responses and the transmission time of the M speed measurement commands. The M speed measurement commands carry N index bit values, where N is a positive integer; the M speed measurement responses carry N response bit values.

[0150] The following describes a near-field communication method provided by an embodiment of this application.

[0151] Figure 7 shows a flowchart of a near-field communication method provided in an embodiment of this application.

[0152] As shown in Figure 7, this near-field communication method can be applied to a communication system including an NFC card reader 200 and an NFC device 100. The NFC device 100 may include an NFC module 102 and a first applet. The NFC card reader 200 is in PCD mode, and the NFC device 100 is in PICC mode. This near-field communication method may include steps S701 to S721.

[0153] In one example, steps S702 to S705 are steps of the NFC access layer. Steps S706 to S721 are steps of the NFC application layer.

[0154] S701. NFC device 100 enters the radio frequency field of NFC card reader 200.

[0155] In this scenario, a user can hold the NFC device 100 and actively bring the NFC antenna of the NFC device 100 close to the card-swiping area of ​​the NFC card reader 200, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200. Alternatively, the user can also actively hold the NFC card reader 200 and bring the card-swiping area of ​​the NFC card reader 200 close to the NFC antenna of the NFC device 100, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200.

[0156] S702. NFC card reader 200 sends a first access layer command to NFC device 100.

[0157] The NFC card reader 200 can send the first access layer command to the NFC module 102 in the NFC device 100.

[0158] S703.NFC device 100 obtains a first random number.

[0159] The first random number can be generated by the NFC module 102, or it can be preset in the NFC module 102, or it can be obtained from other modules (e.g., SE).

[0160] S704. NFC device 100 sends a first access layer response to NFC card reader 200, the first access layer response carrying a first random number.

[0161] The NFC module 102 in the NFC device 100 can send a first access layer response to the NFC card reader 200.

[0162] In one possible implementation, the first random number can be the UID of the NFC device 100. The first access layer command can be an anti-collision command in the Class A NFC protocol, and the first access layer response can be an anti-collision response. Optionally, before the NFC reader 200 sends the anti-collision command to the NFC module 102 of the NFC device 100, the NFC reader 200 also sends a Class A Request Command (REQA) to the NFC module 102 of the NFC device 100. After receiving the Class A Request Command, the NFC module 102 of the NFC device 100 sends a Class A Request Response (ATQA) to the NFC reader 200. Optionally, after the NFC reader 200 saves the first random number, the NFC reader 200 can also send a Select Unique Identifier (Select UID) command to the NFC module 102 of the NFC device 100. The NFC module 102 of the NFC device 100 can send a Select Acknowledge (SAK) command to the NFC reader 200. The SAK command sent by the NFC device 100 can be used to instruct the NFC device 100 to support application layer protocol processes.

[0163] In one possible implementation, the first random number may be generated by the NFC module 102 of the NFC device 100 or other modules. The first access layer command may be a probe frame, and the first access layer response may be a probe ACK frame. Optionally, after the NFC card reader 200 saves the first random number, the NFC card reader 200 may also send a notification frame to the NFC module 102 of the NFC device 100. The NFC module 102 of the NFC device 100 may return a notification ACK frame to the NFC card reader 200. Optionally, after receiving the Notify ACK frame, the NFC card reader 200 may send a parameter negotiation command to the NFC module 102 of the NFC device 100. The NFC module 102 of the NFC device 100 may send a parameter negotiation response to the NFC card reader 200.

[0164] S705.NFC card reader 200 stores the first random number.

[0165] S706. The NFC card reader 200 sends an Applet Selection (Select AID) command to the NFC device 100, wherein the Select AID command carries the identifier of the first Applet.

[0166] The applet selection command is used to select the first applet in the NFC device 100 to interact with the NFC card reader 200 at the NFC application layer.

[0167] The S707 NFC device 100 sends an applet selection response to the NFC card reader 200. The applet selection response indicates that the first applet has been successfully selected.

[0168] The first applet in the NFC device 100 can send an applet selection response to the NFC card reader 200 via the NFC module 102.

[0169] S708. NFC card reader 200 sends a random number acquisition (Get Challenge) command to NFC device 100.

[0170] The random number acquisition command can be sent to the first Applet via the NFC module 102 of the NFC device 100.

[0171] The S709 NFC device 100 generates a second random number via a first applet.

[0172] S710.NFC device 100 sends a random number acquisition response to NFC card reader 200 via a first applet, the random number acquisition response carrying a second random number.

[0173] The S711 NFC card reader 200 generates a first parameter based on a first random number and a second random number.

[0174] In this embodiment, the NFC card reader 200 can input a first random number and a second random number into a first calculation algorithm to obtain a first parameter. For example, the first calculation algorithm can be an XOR operation, that is, performing an XOR operation on the first random number and the second random number to obtain the first parameter. In this application embodiment, the first calculation algorithm can also be other calculation algorithms, which are not limited.

[0175] The S712 NFC card reader 200 uses a first key to encrypt the first parameter, thereby obtaining first ciphertext data.

[0176] In one example, the first key can be a symmetric key. The first key can be an application-ciphertext key. The first key can be decentralizedly derived from the public and private key pairs of the certification authority and the issuing bank.

[0177] The NFC card reader 200 can use the first key to encrypt the first parameter based on the first encryption and decryption algorithm to obtain the first ciphertext data.

[0178] In one example, the first encryption / decryption algorithm can be a MAC algorithm. The NFC reader device 200 can encrypt the first parameter based on the first key and the MAC algorithm to obtain first ciphertext data including encrypted ciphertext and a check value.

[0179] In the embodiments of this application, the first encryption algorithm may also be other encryption algorithms, which are not limited here.

[0180] The first Applet of the S713 NFC device 100 obtains a first random number.

[0181] The first applet can obtain a first random number from the NFC module 102.

[0182] In one possible implementation, the first random number can be stored in other modules of the NFC device 100 (e.g., SE). The first applet can obtain the first random number from other modules of the NFC device 100 (e.g., SE).

[0183] The S714 NFC device 100 generates a first parameter using a first applet based on a first random number and a second random number.

[0184] In this embodiment, the NFC device 100 can input a first random number and a second random number into a first calculation algorithm to obtain a first parameter. For example, the first calculation algorithm can be an XOR operation, that is, performing an XOR operation on the first random number and the second random number to obtain the first parameter. In this application embodiment, the first calculation algorithm can also be other calculation algorithms, which are not limited.

[0185] S715. NFC card reader 200 sends an authentication command to NFC device 100, the authentication command carrying first encrypted data.

[0186] In one possible implementation, steps S713 and S714 can be executed after S710, and steps S713 and S714 can also be executed after step S715.

[0187] The S716 NFC device 100 verifies the first encrypted data using a first key and first parameters via a first applet.

[0188] In one possible implementation, the first applet can use a first key and a first encryption / decryption algorithm to decrypt the second parameter from the first ciphertext data. The first applet can then determine whether the second parameter is the same as the first parameter. If the second parameter is the same as the first parameter, the first applet determines that the verification of the first ciphertext data was successful. If the second parameter is different from the first parameter, the first applet determines that the verification of the first ciphertext data failed.

[0189] For example, the first encryption / decryption algorithm can be a MAC algorithm. The first ciphertext data may include a first encrypted ciphertext and a checksum. The first applet in the NFC device 100 can verify whether the checksum in the first ciphertext data is correct based on the MAC algorithm, the first key, and the first encrypted ciphertext. If the checksum in the first ciphertext data is correct, it means that the first ciphertext data has not been tampered with, and the first applet can decrypt the second parameter from the first encrypted ciphertext based on the MAC algorithm and the first key. If the second parameter is the same as the first parameter, the first applet determines that the verification of the first ciphertext data was successful.

[0190] In one possible implementation, the first Applet can encrypt the first parameter using a first key and a first encryption / decryption algorithm to obtain second ciphertext data. The first Applet can then determine whether the second ciphertext data is the same as the first ciphertext data. If the second ciphertext data is the same as the first ciphertext data, the first Applet determines that the verification of the first ciphertext data was successful. If the second ciphertext data is different from the first ciphertext data, the first Applet determines that the verification of the first ciphertext data failed.

[0191] The S717 NFC device 100 determines whether the first encrypted data has been successfully verified using the first applet.

[0192] S718. If the verification of the first encrypted data is successful, the NFC device 100 sends a first authentication response to the NFC card reader 200 through the first applet. The first authentication response carries a first authentication result, which is used to indicate that the authentication was successful.

[0193] If the verification of the first encrypted data is successful, it indicates that the first random number stored on the NFC reader 200 is the same as the first random number stored on the NFC device 100, and the second random number stored on the NFC reader 200 is also the same as the second random number stored on the NFC device 100. Therefore, the NFC device 100 can determine that it is interacting with the same device in both the NFC access layer and application layer. That is, the NFC device 100 can determine that there are no other devices intermediary between it and the NFC reader 200 for relaying NFC application layer commands and responses, and the NFC device 100 can perform NFC services with the NFC reader 200.

[0194] After receiving the first authentication response, the S719 NFC reader device 200 performs NFC transactions with the first applet on the NFC device 100.

[0195] S720. If the verification of the first encrypted data fails, the NFC device 100 sends a second authentication response to the NFC card reader 200 through the first applet. The second authentication response carries a second authentication result, which is used to indicate that the authentication failed.

[0196] If the verification of the first encrypted data fails, it indicates that the first random number stored on the NFC reader 200 is different from the first random number stored on the NFC device 100, or the second random number stored on the NFC reader 200 is different from the second random number stored on the NFC device 100. Therefore, the NFC device 100 can determine that it is interacting with different devices at the NFC access layer and application layer. That is, the NFC device 100 can determine that there are other devices relaying NFC application layer commands and responses with the NFC reader 200. Therefore, the NFC device 100 and the NFC reader 200 are prohibited from performing NFC services.

[0197] S721. After receiving the second authentication response, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services.

[0198] NFC services can include any one or more of the following: codeless payment, electronic tickets, access control, digital ID cards, contactless payment across all scenarios, near-field data transmission, transaction transfer, car keys, and smart locks.

[0199] In some embodiments, after successfully verifying the first encrypted data, the NFC device 100 can generate a third parameter based on a first random number and a second random number. The NFC device 100 can encrypt the third parameter based on a first key to obtain the third encrypted data. The NFC device 100 can send a third authentication response to the NFC card reader 200, wherein the third authentication response carries the third encrypted data. After receiving the third authentication response, the NFC card reader 200 can generate the third parameter based on the first random number and the second random number. The NFC card reader 200 can verify the third encrypted data based on the first key and the third parameter. If the verification of the third encrypted data is successful, the NFC card reader 200 can perform NFC services with the NFC device 100. If the verification of the third encrypted data fails, the NFC card reader 200 prohibits the performance of NFC services with the NFC device 100. In this way, bidirectional verification between the NFC card reader 200 and the NFC device 100 can be achieved, thereby improving the security of NFC services.

[0200] In some embodiments, the NFC card reader 200 may omit steps S711 and S712. The NFC device 100 may omit steps S714, S716, and S717. After receiving a random number acquisition response, the NFC card reader 200 may send an authentication command to the NFC device 100, the authentication command not carrying the first encrypted data. After receiving the authentication command, the NFC device 100 may generate a third parameter based on the first and second random numbers. The NFC device 100 may encrypt the third parameter using the first key to obtain the third encrypted data. The NFC device 100 may also send a third authentication response to the NFC card reader 200, the third authentication response carrying the third encrypted data. After receiving the third authentication response, the NFC card reader 200 may generate the third parameter using the first and second random numbers. The NFC card reader 200 may verify the third encrypted data based on the first key and the third parameter. If the verification of the third encrypted data is successful, the NFC reader 200 can perform NFC transactions with the NFC device 100. If the verification of the third encrypted data fails, the NFC reader 200 will prohibit NFC transactions with the NFC device 100. This allows the NFC reader 200 to complete one-way verification of the NFC device 100, enabling it to decide whether to perform NFC transactions based on the verification result. This improves the security of NFC transactions.

[0201] According to the near-field communication method provided in this application embodiment, NFC device 100 and NFC card reader 200 can synchronize a first random number at the NFC access layer and a second random number at the NFC application layer. If NFC device 100 verifies that the first random number stored on NFC device 100 is the same as the first random number stored on NFC card reader 200 and the second random number stored on NFC device 100 is the same as the second random number stored on NFC card reader 200, NFC device 100 can perform NFC services with NFC card reader 200. If NFC device 100 verifies that the first random number stored on NFC device 100 is different from the first random number stored on NFC card reader 200 or the second random number stored on NFC device 100 is different from the second random number stored on NFC card reader 200, NFC device 100 prohibits performing NFC services with NFC card reader 200. In this way, the need for an intermediate device to relay NFC APDUs between NFC device 100 and NFC card reader 200 when performing NFC services can be prevented, thus improving the security of NFC services.

[0202] The following section describes in detail the implementation scenario when there are other devices relaying application layer commands and responses between the NFC device and the NFC card reader, based on the near-field communication method shown in Figure 7 above.

[0203] Figure 8 shows a flowchart illustrating one implementation scenario of the near-field communication method provided in this application embodiment.

[0204] As shown in Figure 8, the flow of one implementation scenario of the near-field communication method is applied to a communication system including an NFC card reader 200B, an electronic device 100B, an electronic device 200A, and an NFC device 100A. In one example, the NFC device 100A may include an NFC module 102A and a first applet. The NFC card reader 200B and the electronic device 200A are in PCD mode, while the electronic device 100B and the NFC device 100A are in PICC mode. The flow of this near-field communication method implementation scenario may include the following steps S801 to S825.

[0205] In one example, steps S804 to S811 are steps of the NFC access layer. Steps S812 to S825 are steps of the NFC application layer.

[0206] S801. Electronic device 100B and electronic device 200A establish a relay link.

[0207] Specifically, electronic device 100B can have a designated application B installed, and electronic device 200A can have a designated application A installed. Both designated application A and designated application B can communicate with a designated server. Therefore, designated application B on electronic device 100B and designated application A on electronic device 200A can establish a relay link through the designated server.

[0208] S802. Electronic device 100B enters the radio frequency field of NFC card reader 200B.

[0209] In this method, a user can hold electronic device 100B and actively bring the NFC antenna of electronic device 100B close to the card-swiping area of ​​NFC card reader 200B, thereby allowing electronic device 100B to enter the radio frequency field of NFC card reader 200B. Alternatively, a user can also actively hold NFC card reader 200B and bring the card-swiping area of ​​NFC card reader 200B close to the NFC antenna of electronic device 100B, thereby allowing electronic device 100B to enter the radio frequency field of NFC card reader 200B.

[0210] The S803.NFC device 100A enters the radio frequency field of the electronic device 200A.

[0211] In this method, the user can hold the NFC device 100A and actively bring the NFC antenna of the NFC device 100A close to the card-swiping area of ​​the electronic device 200A, thereby allowing the NFC device 100A to enter the radio frequency field of the electronic device 200A. Alternatively, the user can also actively hold the electronic device 200A and bring the card-swiping area of ​​the electronic device 200A close to the NFC antenna of the NFC device 100A, thereby allowing the NFC device 100A to enter the radio frequency field of the electronic device 200A.

[0212] S804. NFC card reader 200B sends access layer command B to electronic device 100B.

[0213] S805. Electronic device 100B obtains a random number r1.

[0214] The random number r1 can be generated by the NFC module of the electronic device 100B, or it can be pre-installed in the NFC module of the electronic device 100B, or it can be obtained from other modules of the electronic device 100B (e.g., SE).

[0215] S806. Electronic device 100B sends access layer response B to NFC card reader 200B, the access layer response B carrying a random number r1.

[0216] In one possible implementation, the random number r1 can be the UID of the electronic device 100B. The access layer command B can be an anti-collision command in the Class A NFC protocol, and the access layer response B can be an anti-collision response. Optionally, before sending the anti-collision command to the electronic device 100B, the NFC reader 200B also sends a Class A request command (REQA) to the electronic device 100B. After receiving the Class A request command, the electronic device 100B sends a Class A request response (ATQA) to the NFC reader 200B. Optionally, after saving the random number r1, the NFC reader 200B can also send a Select UID command to the electronic device 100B. The electronic device 100B can send a Select Acknowledge (SAK) command to the NFC reader 200B. The SAK command sent by the electronic device 100B can be used to indicate that the electronic device 100B supports the application layer protocol process.

[0217] In one possible implementation, the random number r1 can be generated by the NFC module or other modules of the electronic device 100B. The access layer command B can be a probe frame, and the access layer response B can be a probe ACK frame. Optionally, after the NFC reader 200B saves the random number r1, the NFC reader 200B can also send a notification frame to the electronic device 100B. The electronic device 100B can return a notification ACK frame to the NFC reader 200B. Optionally, after receiving the Notify ACK frame, the NFC reader 200B can send a parameter negotiation command to the electronic device 100B. The electronic device 100B can send a parameter negotiation response to the NFC reader 200B.

[0218] The S807 NFC card reader 200B stores a random number r1.

[0219] S808. Electronic device 200A sends access layer command A to NFC device 100A.

[0220] Among them, electronic device 200A can send access layer command A to NFC module 102A in NFC device 100A.

[0221] S809.NFC device 100A obtains random number r2.

[0222] The random number r2 can be generated by the NFC module 102A of the NFC device 100A, or it can be pre-installed in the NFC module 102A of the NFC device 100A, or it can be obtained from other modules of the NFC device 100A (e.g., SE).

[0223] S810.NFC device 100A sends access layer response A to electronic device 200A, and access layer response A carries a random number r2.

[0224] Among them, the NFC module 102A in the NFC device 100A can send an access layer response A to the electronic device 200A.

[0225] In one possible implementation, the random number r2 can be the UID of the NFC device 100A. The access layer command A can be an anti-collision command in the Class A NFC protocol, and the access layer response A can be an anti-collision response. Optionally, before the electronic device 200A sends the anti-collision command to the NFC module 102A of the NFC device 100A, the NFC reader device 200B also sends a Class A request command (REQA) to the NFC module 102A of the NFC device 100A. After receiving the Class A request command, the NFC module 102A of the NFC device 100A sends a Class A request response (ATQA) to the electronic device 200A. Optionally, after the electronic device 200A saves the random number r2, the electronic device 200A can also send a Select UID command to the NFC module 102A of the NFC device 100A. The NFC module 102A of the NFC device 100A can send a Select Acknowledge (SAK) command to the electronic device 200A. The SAK command sent by the NFC device 100A can be used to instruct the NFC device 100A to support the application layer protocol process.

[0226] In one possible implementation, the random number r2 can be generated by the NFC module 102A of the NFC device 100A or other modules. The access layer command A can be a probe frame, and the access layer response A can be a probe ACK frame. Optionally, after the electronic device 200A saves the first random number, the electronic device 200A can also send a notification frame to the NFC module 102A of the NFC device 100A. The NFC module 102A of the NFC device 100A can return a notification ACK frame to the electronic device 200A. Optionally, after receiving the Notify ACK frame, the electronic device 200A can send a parameter negotiation command to the NFC module 102A of the NFC device 100A. The NFC module 102A of the NFC device 100A can send a parameter negotiation response to the electronic device 200A.

[0227] S811. Electronic device 200A stores random number r2.

[0228] S812. The NFC card reader 200B sends a Select AID command to the NFC device 100A through the electronic device 100B and the electronic device 200A. The Select AID command carries the identifier of the first Applet.

[0229] The applet selection command is used to select the first applet in the NFC device 100A to interact with the NFC card reader 200B at the application layer of the NFC protocol.

[0230] NFC card reader 200B can send a mini-program selection command to electronic device 100B via NFC. Electronic device 100B can send the mini-program selection command to electronic device 200A via a relay link. Electronic device 200A can send the mini-program selection command to the NFC module 102A of NFC device 100A via NFC. NFC module 102A can then send the mini-program selection command to the first Applet.

[0231] S813. NFC device 100A sends an applet selection response to NFC card reader 200B through electronic device 200A and electronic device 100B. The applet selection response is used to indicate that the first applet has been successfully selected.

[0232] In this device, the first applet in NFC device 100A can send a applet selection response to NFC module 102A. NFC module 102A can send an applet selection response to electronic device 200A via NFC. Electronic device 200A can send an applet selection response to electronic device 100B via a relay link. Electronic device 100B can send an applet selection response to NFC card reader 200B via NFC.

[0233] S814. NFC card reader 200B sends a random number acquisition (Get Challenge) command to NFC device 100A through electronic device 100B and electronic device 200A.

[0234] Specifically, NFC card reader 200B can send a random number retrieval command to electronic device 100B via NFC. Electronic device 100B can send a random number retrieval command to electronic device 200A via a relay link. Electronic device 200A can send a random number retrieval command to NFC module 102A of NFC device 100A via NFC. NFC module 102A of NFC device 100A can send a random number retrieval command to the first Applet.

[0235] The S815 NFC device 100A generates a random number r3 using the first applet.

[0236] S816. NFC device 100A sends a random number acquisition response to NFC card reader 200B through electronic device 200A and electronic device 100B. The random number acquisition response carries a random number r3.

[0237] Specifically, the first applet of NFC device 100A can send a random number to NFC module 102A to obtain a response. NFC module 102A can send a random number to electronic device 200A via NFC to obtain a response. Electronic device 200A can send a random number to electronic device 100B via a relay link to obtain a response. Electronic device 100B can send a random number to NFC card reader 200B via NFC to obtain a response.

[0238] The S817 NFC card reader 200B generates parameter m1 based on random numbers r1 and r3.

[0239] In this embodiment, the NFC card reader 200B can input random numbers r1 and r3 into the first calculation algorithm to obtain parameter m1. For example, the first calculation algorithm can be an XOR operation, that is, performing an XOR operation on random numbers r1 and r3 to obtain parameter m1. In this application embodiment, the first calculation algorithm can also be other calculation algorithms, without limitation.

[0240] The S818 NFC reader 200B uses the key Key to encrypt parameter m1, obtaining the first ciphertext data.

[0241] In one example, the key can be a symmetric key. The key can also be an application-encrypted key. The key can be decentralizedly derived from the public and private key pairs of the certification authority and the issuing bank.

[0242] Among them, the NFC card reader device 200B can use the key Key to encrypt the parameter m1 based on the first encryption and decryption algorithm to obtain the first ciphertext data.

[0243] In one example, the first encryption / decryption algorithm can be a MAC algorithm. The NFC reader device 200B can encrypt the parameter m1 based on the key Key and the MAC algorithm to obtain first ciphertext data including encrypted ciphertext and a check value.

[0244] The S819 NFC device 100A obtains a random number r2 via the first Applet.

[0245] The first applet can obtain a random number r2 from the NFC module 102A.

[0246] In one example, the random number r2 may be stored in another module (e.g., SE) of the NFC device 100A. The first applet can obtain the random number r2 from the other module (e.g., SE) of the NFC device 100A.

[0247] The S820 NFC device 100A generates parameter m2 using a first Applet based on random numbers r2 and r3.

[0248] In this embodiment, the NFC device 100A can input random numbers r2 and r3 into the first calculation algorithm to obtain parameter m2. For example, the first calculation algorithm can be an XOR operation, that is, performing an XOR operation on random numbers r2 and r3 to obtain parameter m2. In this application embodiment, the first calculation algorithm can also be other calculation algorithms, which are not limited.

[0249] S821. The NFC card reader 200B sends an authentication command to the NFC device 100A through the electronic device 100B and the electronic device 200A. The authentication command carries the first encrypted data.

[0250] Specifically, NFC card reader 200B can send authentication commands to electronic device 100B via NFC. Electronic device 100B can send authentication commands to electronic device 200A via a relay link. Electronic device 200A can send authentication commands to the NFC module 102A of NFC device 100A via NFC. NFC module 102A can send authentication commands to the first applet.

[0251] In one possible implementation, steps S819 and S820 can be executed after S816, and steps S819 and S820 can also be executed after step S821.

[0252] The S822.NFC device 100A verifies the first encrypted data using the key Key and parameter m2 via the first Applet.

[0253] In one possible implementation, the first applet can use a key `Key` and a first encryption / decryption algorithm to decrypt parameter `m3` from the first ciphertext data. The first applet can then determine whether parameter `m3` is the same as parameter `m2`. If parameter `m3` is the same as parameter `m2`, the first applet determines that the verification of the first ciphertext data was successful. If parameter `m3` is different from parameter `m2`, the first applet determines that the verification of the first ciphertext data failed.

[0254] In one possible implementation, the first Applet can encrypt parameter m2 using a key and a first encryption / decryption algorithm to obtain second ciphertext data. The first Applet can then determine whether the second ciphertext data is the same as the first ciphertext data. If the second ciphertext data is the same as the first ciphertext data, the first Applet determines that the verification of the first ciphertext data was successful. If the second ciphertext data is different from the first ciphertext data, the first Applet determines that the verification of the first ciphertext data failed.

[0255] The S823.NFC device 100A determines through the first Applet that the verification of the first encrypted data has failed.

[0256] Since the random number r1 was obtained by electronic device 100B and sent to NFC card reader 200B, and the random number r2 was obtained by NFC device 100A, random number r1 and random number r2 are different. Parameter m1 is generated based on random numbers r1 and r3 using the first calculation algorithm, and parameter m2 is generated based on random numbers r2 and r3 using the same algorithm. Therefore, parameter m2 is also different from parameter m1, causing the first Applet to fail to verify the first encrypted data.

[0257] S824. The NFC device 100A sends a second authentication response to the NFC card reader 200B through the electronic devices 200A and 100B. The second authentication response carries a second authentication result, which is used to indicate authentication failure.

[0258] Specifically, the first applet of NFC device 100A can send a second authentication response to the NFC module 102A of NFC device 100A. NFC module 102A can send a second authentication response to electronic device 200A via NFC. Electronic device 200A can send a second authentication response to electronic device 100B via a relay link. Electronic device 100B can send a second authentication response to NFC card reader 200B via NFC.

[0259] S825. NFC card reader 200B and NFC device 100A are prohibited from performing NFC services.

[0260] NFC services can include any one or more of the following: codeless payment, electronic tickets, access control, digital ID cards, contactless payment across all scenarios, near-field data transmission, transaction transfer, car keys, and smart locks.

[0261] Through the flowchart of one implementation scenario of the near-field communication method provided in this application embodiment, it can be seen that when there are other devices relaying application layer commands and responses between the NFC device and the NFC reader, because the NFC device and the NFC reader interact with different devices at the access layer, the random numbers stored by the NFC device and the NFC reader at the access layer are different. This causes the authentication of the NFC device and the NFC reader at the application layer to fail. In this way, the need for an intermediate device to relay NFC APDUs between the NFC device and the NFC reader when performing NFC services can be prevented, thus improving the security of NFC services.

[0262] The following describes another embodiment of a near-field communication method provided by this application.

[0263] Figure 9 shows a flowchart of a near-field communication method provided in an embodiment of this application.

[0264] As shown in Figure 9, this near-field communication method can be applied to a communication system including an NFC card reader 200 and an NFC device 100. The NFC device 100 may include an NFC module 102 and a first applet. The NFC card reader 200 is in PCD mode, and the NFC device 100 is in PICC mode. This near-field communication method may include steps S901 to S912.

[0265] In one example, steps S903 to S912 can be steps of the NFC application layer.

[0266] S901. NFC device 100 enters the radio frequency field of NFC card reader 200.

[0267] In this scenario, a user can hold the NFC device 100 and actively bring the NFC antenna of the NFC device 100 close to the card-swiping area of ​​the NFC card reader 200, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200. Alternatively, the user can also actively hold the NFC card reader 200 and bring the card-swiping area of ​​the NFC card reader 200 close to the NFC antenna of the NFC device 100, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200.

[0268] S902. The NFC card reader 200 and the NFC device 100 perform access layer command interaction.

[0269] In one possible implementation, the access layer command interaction process may include the following steps: 1.1 The NFC reader 200 sends a probe frame to the NFC device 100. 1.2 The NFC device 100 sends a probe ACK frame to the NFC reader 200. 1.3 The NFC reader 200 sends a notification frame to the NFC device 100. The NFC device 100 sends a notification ACK frame to the NFC reader 200. The NFC reader 200 sends a parameter negotiation command to the NFC device 100. The NFC device 100 sends a parameter negotiation response to the NFC reader 200.

[0270] In one possible implementation, the command interaction process at the access layer may include the following steps: 2.1 NFC reader 200 sends a Type A Request Command (REQA) to NFC device 100. 2.2 NFC device 100 sends a Type A Request Response (ATQA) to NFC reader 200. 2.3 NFC reader 200 sends an Anti-Collision Command (SDD REQ) to NFC device 100. 2.4 NFC device 100 sends an Anti-Collision Response (SDD RES) to NFC reader 200. NFC reader 200 may also send a Select Unique Identifier (Select UID) command to NFC module 102 of NFC device 100. NFC module 102 of NFC device 100 may send a Select Confirmation (SAK) command to NFC reader 200. The SAK command sent by NFC device 100 can be used to indicate that NFC device 100 supports application layer protocol procedures.

[0271] S903. The NFC reader 200 can send a Select AID command to the NFC device 100, the Select AID command carrying the identifier of the first Applet.

[0272] The applet selection command is used to select the first applet in the NFC device 100 to interact with the NFC card reader 200 at the NFC application layer.

[0273] The NFC card reader 200 can send a mini-program selection command to the NFC module 102 of the NFC device 100. The NFC module 102 can send the mini-program selection command to the first Applet.

[0274] S904. The NFC device 100 sends an applet selection response to the NFC card reader 200, wherein the applet selection response is used to indicate that the first applet has been successfully selected.

[0275] The first applet can send the applet selection response to the NFC module 102. The NFC module 102 can then send the applet selection response to the NFC reader device 200.

[0276] S905. NFC card reader 200 sends a first speed measurement command to NFC device 100.

[0277] The NFC reader 200 can send a speed measurement command to the NFC module 102 of the NFC device 100. The NFC module 102 can send a first speed measurement command to the first applet.

[0278] The S906 NFC card reader 200 records the time t1 when the first speed measurement command is sent.

[0279] S907.NFC device 100 acquires the first duration threshold T.

[0280] The first duration threshold T can be the duration from sending an application layer command to the NFC device 100 to receiving an application layer response from the NFC device 100 in response to the application layer command.

[0281] In one example, the first duration threshold T can be obtained through testing before the NFC device 100 leaves the factory and is preset in the NFC device 100.

[0282] S908. NFC device 100 sends a first speed measurement response to NFC card reader 200, the first speed measurement response carrying a first duration threshold T.

[0283] The first applet of NFC device 100 can send a first speed test response to NFC module 102. NFC module 102 can send a first speed test response to NFC card reader 200.

[0284] In one possible implementation, to prevent the first speed measurement response from being intercepted by an intermediate device and having its first duration threshold T altered, the first applet of the NFC device 100 can encrypt the first duration threshold T in the first speed measurement response using a first designated key. The NFC card reader 200 can then decrypt the first duration threshold T from the first speed measurement response using a second designated key. Wherein, if a symmetric encryption algorithm is used, the first designated key and the second designated key are the same. If an asymmetric encryption algorithm is used, the first designated key and the second designated key are a public-private key pair, with the first designated key being the public key and the second designated key being the private key.

[0285] The S909 NFC reader 200 records the reception time t2 of the first speed measurement response.

[0286] The S910 NFC reader 200 determines whether the difference between the receiving time t2 and the sending time t1 is less than or equal to a first duration threshold T.

[0287] S911. If the difference between the receiving time t2 and the sending time t1 is less than or equal to the first duration threshold T, then the NFC card reader 200 and the NFC device 100 perform NFC services.

[0288] S912. If the difference between the receiving time t2 and the sending time t1 is greater than the first duration threshold T, then the NFC card reader 200 and the NFC device 100 shall be prohibited from performing NFC services.

[0289] Because there are other devices relaying NFC application layer commands (including speed measurement commands) or NFC application layer responses (including speed measurement responses) between the NFC reader device 200 and the NFC device 100, the transmission latency of NFC application commands or responses will increase. Therefore, if the difference between the receiving time t2 and the sending time t1 is less than or equal to the first duration threshold T, it indicates that there are no other devices relaying NFC application layer commands or NFC application layer responses between the NFC reader device 200 and the NFC device 100. Therefore, the NFC reader device 200 can perform NFC services with the NFC device 100. If the difference between the receiving time t2 and the sending time t1 is greater than the first duration threshold T, it indicates that there are other devices relaying NFC application layer commands or NFC application layer responses between the NFC reader device 200 and the NFC device 100. Therefore, the NFC reader device 200 and the NFC device 100 are prohibited from performing NFC services.

[0290] NFC services can include any one or more of the following: codeless payment, electronic tickets, access control, digital ID cards, contactless payment across all scenarios, near-field data transmission, transaction transfer, car keys, and smart locks.

[0291] In one possible implementation, step S907 is optional. The first speed measurement response may not carry the first duration threshold T, and the first duration threshold T may be preset and stored in the NFC card reader 200.

[0292] According to the near-field communication method provided in this application embodiment, an NFC card reader 200 can send a speed measurement command to an NFC device 100 at the NFC application layer and receive a first speed measurement response from the NFC device 100 in response to the first speed measurement command. The NFC card reader 200 can determine whether the difference between the time of receiving the first speed measurement response and the time of sending the first speed measurement command is less than or equal to a first duration threshold. If the difference is less than or equal to the first duration threshold, the NFC card reader 200 can perform NFC services with the NFC device 100. If the difference is greater than the first duration threshold, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services. This prevents the need for an intermediate device to relay NFC APDUs between the NFC device 100 and the NFC card reader 200 when performing NFC services, thus improving the security of NFC services.

[0293] In some embodiments, the embodiments shown in FIG7 and FIG9 can be implemented in combination. If the NFC device 100 determines through the first applet that the verification of the first encrypted data is successful and the NFC card reader 200 determines that the difference between the reception time t2 of the first speed measurement response and the transmission time t1 of the first speed measurement command is less than or equal to the first duration threshold T, then the NFC card reader 200 and the NFC device 100 perform NFC services. If the NFC device 100 fails to verify the first encrypted data through the first applet or the NFC card reader 200 determines that the difference between the reception time t2 of the second speed measurement response and the transmission time t1 of the speed measurement command is greater than the first duration threshold T, then the NFC card reader 200 and the NFC device 100 prohibit the performance of NFC services.

[0294] For example, after executing steps S701 to S718 in the embodiment shown in FIG7, steps S905 to S912 in the embodiment shown in FIG9 can be executed. That is, if the NFC device 100 successfully verifies the first encrypted data through the first Applet, the NFC device 100 can send a first authentication response to the NFC card reader 200. The first authentication response carries a first authentication result, which is used to indicate successful authentication. After receiving the first authentication response, the NFC card reader 200 can send a first speed test command to the NFC device 100 and record the sending time t1 of the first speed test command. The NFC device 100 can return a first speed test response to the NFC card reader 200, wherein the first speed test response carries a first duration threshold T. The NFC card reader 200 can record the receiving time t2 of the speed test response. If the NFC reader 200 determines that the difference between the reception time t2 of the first speed measurement response and the transmission time t1 of the first speed measurement command is less than or equal to the first duration threshold T, then the NFC reader 200 can perform NFC services with the NFC device 100. If the NFC reader 200 determines that the difference between the reception time t2 of the first speed measurement response and the transmission time t1 of the first speed measurement command is greater than the first duration threshold T, then the NFC reader 200 and the NFC device 100 are prohibited from performing NFC services.

[0295] If the NFC device 100 verifies the first encrypted data through the first applet, the NFC device 100 can send a second authentication response to the NFC card reader 200. The second authentication response carries a second authentication result, which indicates that authentication has failed. After receiving the second authentication response, the NFC card reader 200 will prevent the NFC device 100 from performing NFC services.

[0296] In this way, NFC device 100 can verify the consistency between the random number stored by NFC reader 200 in NFC access layer and the random number obtained by NFC device 100 in NFC access layer at the NFC application layer. NFC reader 200 can also verify at the NFC application layer whether the timeout period for NFC device 100 to reply to application layer commands has expired. Thus, through multiple mechanisms, the security of NFC services is improved by preventing the intermediary of other devices relaying NFC APDUs between NFC device 100 and NFC reader 200 when they are performing NFC services.

[0297] The following describes another embodiment of a near-field communication method provided by this application.

[0298] Figure 10 shows a flowchart of a near-field communication method provided in an embodiment of this application.

[0299] As shown in Figure 10, this near-field communication method can be applied to a communication system including an NFC card reader 200 and an NFC device 100. The NFC device 100 may include an NFC module 102 and a first applet. The NFC card reader 200 is in PCD mode, and the NFC device 100 is in PICC mode. This near-field communication method may include steps S1001 to S1008.

[0300] In one example, steps S1003 to S1008 can be steps of the NFC application layer.

[0301] S1001. The NFC device 100 enters the radio frequency field of the NFC card reader 200.

[0302] In this scenario, a user can hold the NFC device 100 and actively bring the NFC antenna of the NFC device 100 close to the card-swiping area of ​​the NFC card reader 200, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200. Alternatively, the user can also actively hold the NFC card reader 200 and bring the card-swiping area of ​​the NFC card reader 200 close to the NFC antenna of the NFC device 100, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200.

[0303] S1002. The NFC card reader 200 and the NFC device 100 perform NFC access layer command interaction process.

[0304] In one possible implementation, the access layer command interaction process may include the following steps: 1.1 The NFC reader 200 sends a probe frame to the NFC device 100. 1.2 The NFC device 100 sends a probe ACK frame to the NFC reader 200. 1.3 The NFC reader 200 sends a notification frame to the NFC device 100. The NFC device 100 sends a notification ACK frame to the NFC reader 200. The NFC reader 200 sends a parameter negotiation command to the NFC device 100. The NFC device 100 sends a parameter negotiation response to the NFC reader 200.

[0305] In one possible implementation, the command interaction process at the access layer may include the following steps: 2.1 NFC reader 200 sends a Type A Request Command (REQA) to NFC device 100. 2.2 NFC device 100 sends a Type A Request Response (ATQA) to NFC reader 200. 2.3 NFC reader 200 sends an Anti-Collision Command (SDD REQ) to NFC device 100. 2.4 NFC device 100 sends an Anti-Collision Response (SDD RES) to NFC reader 200. NFC reader 200 may also send a Select Unique Identifier (Select UID) command to NFC module 102 of NFC device 100. NFC module 102 of NFC device 100 may send a Select Confirmation (SAK) command to NFC reader 200. The SAK command sent by NFC device 100 can be used to indicate that NFC device 100 supports application layer protocol procedures.

[0306] S1003. The NFC card reader 200 sends one or more application layer commands to the NFC device 100.

[0307] S1004. The NFC device 100 sends one or more application layer responses to the NFC card reader 200.

[0308] In this process, the NFC card reader 200 sends an application-layer command to the NFC device 100 each time, and the NFC device 100 sends an application-layer response to the NFC card reader 200 each time. After sending an application-layer command, the NFC card reader 200 needs to wait for the NFC device 100 to reply with an application-layer response before sending the next application-layer command.

[0309] S1005. NFC card reader 200 determines whether the difference between the reception time of the first application layer response in one or more application layer responses and the transmission time of the first application layer command in one or more application layer commands is less than or equal to a first duration threshold.

[0310] If the difference between the receiving time of the first application layer response and the sending time of the first application layer command is less than or equal to the first duration threshold, then step S1006 is executed.

[0311] In one possible implementation, the first application layer response can be an application layer response from the NFC device 100 to the first application layer command. Since the APDU (including application layer command and application layer response) transmitted between the NFC reader 200 and the NFC device 100 increases the APDU propagation delay when forwarded by an intermediate device, the NFC reader 200 can determine whether an intermediate device is forwarding an APDU between the NFC reader 200 and the NFC device 100 by detecting the interval between two adjacent APDUs (i.e., the first application layer command and the first application layer response). In this way, the NFC reader 200 can accurately identify whether an intermediate device is forwarding an APDU between the NFC reader 200 and the NFC device 100.

[0312] In one possible implementation, the first application layer command can be the first application layer command sent by the NFC reader 200 in the NFC application layer. The first application layer response can be the last application layer response sent by the NFC device 100 before executing the NFC service. Since the APDU transmitted between the NFC reader 200 and the NFC device 100 will increase the APDU propagation delay when forwarded by an intermediate device, the NFC reader 200 can determine whether there is an intermediate device forwarding the APDU between the NFC reader 200 and the NFC device 100 by detecting the total interaction time of the APDU in the NFC application layer. In this way, the NFC reader 200 can accurately identify whether there is an intermediate device forwarding the APDU between the NFC reader 200 and the NFC device 100.

[0313] In one possible implementation, the first application layer command can be the first speed measurement command in the embodiment shown in Figure 9 above, and the first application layer response can be the first speed measurement response in the embodiment shown in Figure 9 above.

[0314] S1006. The NFC card reader 200 can perform NFC services with the NFC device 100.

[0315] If the difference between the receiving time of the first application layer response and the sending time of the first application layer command is greater than the first duration threshold, then step S1007 is executed.

[0316] S1007. NFC card reader 200 and NFC device 100 are prohibited from performing NFC services.

[0317] In some embodiments, the method may further include step S1008.

[0318] S1008. NFC device 100 can determine whether the difference between the reception time of the second application layer command in one or more application layer commands and the transmission time of the second application layer response in one or more application layer responses is less than or equal to a second duration threshold.

[0319] If the difference between the receiving time of the first application layer response and the sending time of the first application layer command is less than or equal to the first duration threshold, and the difference between the receiving time of the second application layer command in one or more application layer commands and the sending time of the second application layer response in one or more application layer responses is less than or equal to the second duration threshold, then step S1006 is executed.

[0320] If the difference between the receiving time of the first application layer response and the sending time of the first application layer command is greater than the first duration threshold, or if the difference between the receiving time of the second application layer command in one or more application layer commands and the sending time of the second application layer response in one or more application layer responses is greater than the second duration threshold, then step S1007 is executed.

[0321] In one possible implementation, the second application layer command can be an application layer command sent by the NFC reader 200 after receiving the second application layer response. Since the APDU (including application layer command and application layer response) transmitted between the NFC reader 200 and the NFC device 100 increases the APDU propagation delay when forwarded by an intermediate device, the NFC device 100 can determine whether an intermediate device is forwarding an APDU between the NFC reader 200 and the NFC device 100 by detecting the interval between two adjacent APDUs (i.e., the second application layer response and the second application layer command). In this way, the NFC device 100 can accurately identify whether an intermediate device is forwarding an APDU between the NFC reader 200 and the NFC device 100.

[0322] In one possible implementation, the second application layer response can be the first application layer response sent by the NFC device 100 in the NFC application layer. The second application layer command can be the last application layer command sent by the NFC reader 200 before executing the NFC service in the NFC application layer. Since the APDU transmission between the NFC reader 200 and the NFC device 100 increases the APDU propagation delay when forwarded by an intermediate device, the NFC device 100 can determine whether there is an intermediate device forwarding the APDU between the NFC reader 200 and the NFC device 100 by detecting the total interaction time of the APDU in the NFC application layer. In this way, the NFC device 100 can accurately identify whether there is an intermediate device forwarding the APDU between the NFC reader 200 and the NFC device 100.

[0323] In some embodiments, the method may include steps S1001 to S1004 and steps S1006 to S1008, but does not include step S1005.

[0324] If the difference between the receiving time of the second application layer command in one or more application layer commands and the sending time of the second application layer response in one or more application layer responses is less than or equal to the second duration threshold, then the above step S1006 is executed.

[0325] If the difference between the receiving time of the second application layer command in one or more application layer commands and the sending time of the second application layer response in one or more application layer responses is greater than the second duration threshold, then the above step S1007 is executed.

[0326] According to the near-field communication method provided in this embodiment, the NFC card reader 200 can determine whether an intermediate device forwards an APDU between the NFC card reader 200 and the NFC device 100 by detecting the interval between the first application layer response and the first application layer command. The NFC device 100 can also determine whether an intermediate device forwards an APDU between the NFC card reader 200 and the NFC device 100 by detecting the interval between the second application layer command and the second application layer response. If no intermediate device forwards an APDU between the NFC card reader 200 and the NFC device 100, the NFC card reader 200 and the NFC device 100 can perform NFC services. If an intermediate device forwards an APDU between the NFC card reader 200 and the NFC device 100, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services. In this way, it is possible to accurately identify whether an intermediate device relays an NFC APDU between the NFC card reader 200 and the NFC device 100. This prevents the need for an intermediary device to relay NFC APDUs between the NFC device and the NFC reader when performing NFC services, thus improving the security of NFC services.

[0327] The near-field communication method in the embodiment shown in Figure 10 above will be explained in detail below with reference to the transaction transfer business.

[0328] Figure 11 shows a schematic diagram of the interaction of a transaction transfer service in the NFC application layer according to an embodiment of this application.

[0329] For example, as shown in Figure 11, NFC services can be transaction transfer services. The interaction process between the NFC card reader 200 and the NFC device 100 at the application layer can include the following steps:

[0330] S1101. The NFC card reader 200 sends a Select AID command to the NFC device 100, the Select AID command carrying the identifier of the first Applet.

[0331] The NFC card reader 200 can send a mini-program selection command to the NFC module 102 of the NFC device 100, and the NFC module 102 can send the mini-program selection command to the first Applet of the NFC device 100.

[0332] S1102. The NFC device 100 sends an applet selection response to the NFC card reader 200, wherein the applet selection response is used to indicate that the first applet has been successfully selected.

[0333] The first applet can send a program selection response to the NFC module 102, and the NFC module 102 can send a program selection response to the NFC card reader 200.

[0334] S1103. NFC card reader 200 sends a Read Record command 1 to NFC device 100.

[0335] The NFC card reader 200 can send a read record command 1 to the NFC module 102 of the NFC device 100. The NFC module 102 can then send the read record command 1 to the first applet.

[0336] The read record command 1 can be used to read records in the payment system environment of the NFC device 100.

[0337] S1104. NFC device 100 sends a Read Record response 1 to NFC card reader 200.

[0338] The first applet of the NFC device 100 can send a read record response 1 to the NFC module 102. The NFC module 102 can send a read record response 1 to the NFC card reader 200.

[0339] The record read response 1 can carry records in the payment system environment of the NFC device 100.

[0340] S1105. The NFC card reader 200 sends a Get Process Option command to the NFC device 100.

[0341] The NFC card reader 200 can send a command to the NFC module 102 of the NFC device 100 to request processing feedback. The NFC module 102 can send a command to the first Applet to request processing feedback.

[0342] The "Get Processing Feedback" command can be used to notify NFC device 100 to initiate a transfer transaction.

[0343] S1106. NFC device 100 sends a Get Process Option response to NFC card reader 200.

[0344] The first applet of the NFC device 100 can send a request for processing feedback to the NFC module 102. The NFC module 102 can send a request for processing feedback to the NFC card reader 200.

[0345] The response to receive processing feedback may carry application interaction features. These application interaction features are used to indicate the functions supported by the first applet in the NFC device 100.

[0346] S1107. NFC card reader 200 sends a Read Record command 2 to NFC device 100.

[0347] The NFC card reader 200 can send a read record command 2 to the NFC module 102 of the NFC device 100. The NFC module 102 can send the read record command 2 to the first applet.

[0348] The Read Record command 2 is used to read the application data required in the transfer transaction processing.

[0349] S1108. NFC device 100 sends a Read Record response 2 to NFC card reader 200.

[0350] The first applet of the NFC device 100 can send a read record response 2 to the NFC module 102. The NFC module 102 can send a read record response 2 to the NFC card reader 200.

[0351] The record read response 2 carries the application data required for the transfer transaction processing.

[0352] S1109. NFC card reader 200 sends an internal authentication command to NFC device 100.

[0353] The NFC reader 200 can send an internal authentication command to the NFC module 102 of the NFC device 100. The NFC module 102 can send the internal authentication command to the first applet.

[0354] S1110. NFC device 100 sends an internal authentication response to NFC card reader 200.

[0355] The first applet of the NFC device 100 can send an internal authentication response to the NFC module 102. The NFC module 102 can send an internal authentication response to the NFC card reader 200.

[0356] Internal authentication commands and responses are used by NFC reader 200 and NFC device 100 to complete internal authentication.

[0357] S1111. The NFC card reader 200 sends a Get Data command to the NFC device 100.

[0358] The NFC card reader 200 can send a data acquisition command to the NFC module 102 of the NFC device 100. The NFC module 102 can send a data acquisition command to the first applet.

[0359] The data acquisition command can be used to retrieve the value of the ATC register from the last online transaction.

[0360] S1112. NFC device 100 sends a Get Data response to NFC card reader 200.

[0361] The first applet of the NFC device 100 can send data to the NFC module 102 to obtain a response. The NFC module 102 can send data to the NFC card reader 200 to obtain a response.

[0362] The data acquisition response carries the value of the ATC register from the last online transaction.

[0363] S1113. The NFC reader 200 sends a command to the NFC device 100 to generate application cryptogram (Generate AC).

[0364] Specifically, the NFC card reader 200 can send a command to generate application ciphertext 1 to the NFC module 102 of the NFC device 100. The NFC module 102 can send the command to generate application ciphertext 1 to the first Applet.

[0365] S1114. NFC device 100 sends a Generate Application Ciphertext (Generate AC) response 1 to NFC card reader 200.

[0366] Application ciphertext command 1 can be used to request NFC device 100 to allow online transactions and generate application ciphertext.

[0367] The first applet of the NFC device 100 can send a "Generate Application Ciphertext Response 1" to the NFC module 102. The NFC module 102 can send a "Generate Application Ciphertext Response 1" to the NFC card reader 200.

[0368] Application ciphertext response 1 carries application ciphertext.

[0369] S1115. The NFC card reader 200 sends an external authentication command to the NFC device 100.

[0370] The NFC card reader 200 can send external authentication commands to the NFC module 102 of the NFC device 100. The NFC module 102 can send external authentication commands to the first applet.

[0371] S1116. NFC device 100 sends an External Auth response to NFC card reader 200.

[0372] The first applet of the NFC device 100 can send an external authentication response to the NFC module 102. The NFC module 102 can send an external authentication response to the NFC card reader 200.

[0373] The external authentication command and external authentication response are used to complete the external authentication between the NFC device 100 and the bank server corresponding to the NFC device 100 when the NFC device 100 needs to connect to the bank server for a transaction.

[0374] After completing external authentication between the NFC device 100 and the corresponding bank server, the NFC device 100 can complete transaction transfers with the bank server using the NFC card reader 200.

[0375] S1117. The NFC card reader 200 sends a Generate Application Ciphertext (Generate AC) command 2 to the NFC device 100.

[0376] Specifically, the NFC card reader 200 can send a command to generate application encrypted text 2 to the NFC module 102 of the NFC device 100. The NFC module 102 can send the command to generate application encrypted text 2 to the first Applet.

[0377] The application ciphertext command 2 can be used to request the NFC device 100 to perform a final check and generate the final application ciphertext.

[0378] S1118. NFC device 100 sends a Generate Application Ciphertext (Generate AC) response 2 to NFC card reader 200.

[0379] The first applet of the NFC device 100 can send a generated application encrypted response 2 to the NFC module 102. The NFC module 102 can send a generated application encrypted response 2 to the NFC card reader device 200.

[0380] Application ciphertext response 2 carries the final application ciphertext. Upon receiving application ciphertext response 2, NFC reader 200 can terminate the transaction process.

[0381] The NFC device 100 and the NFC card reader 200 may perform transaction transfer services by executing steps S1113 to S1118 as described above.

[0382] In one possible implementation, the first application layer response can be an application layer response from the NFC device 100 to the first application layer command. For example, the first application layer command can be a mini-program selection command in the embodiment shown in FIG11, and the first application layer response can be a mini-program selection response in the embodiment shown in FIG11. Another example is that the first application layer command can be a read record command 1 in the embodiment shown in FIG11, and the first application layer response can be a read record response 1 in the embodiment shown in FIG11. Yet another example is that the first application layer command can be a get processing opinion command 1 in the embodiment shown in FIG11, and the first application layer response can be a get processing opinion response 1 in the embodiment shown in FIG11. Yet another example is that the first application layer command can be a read record command 2 in the embodiment shown in FIG11, and the first application layer response can be a read record response 2 in the embodiment shown in FIG11. Yet another example is that the first application layer command can be an internal authentication command in the embodiment shown in FIG11, and the first application layer response can be an internal authentication response in the embodiment shown in FIG11. Yet another example is that the first application layer command can be a data acquisition command in the embodiment shown in FIG11, and the first application layer response can be a data acquisition response in the embodiment shown in FIG11.

[0383] In one possible implementation, the first application layer command can be the first application layer command sent by the NFC reader device 200 in the NFC application layer. The first application layer response can be the last application layer response sent by the NFC device 100 before executing the NFC service. For example, the first application layer command can be a mini-program selection command, and the first application layer response can be a data acquisition response.

[0384] If the NFC reader 200 determines that the difference between the reception time of the first application layer response and the transmission time of the first application layer command is less than or equal to a first duration threshold, the NFC reader 200 and the NFC device 100 can execute steps S1113 and S1118 to perform the transaction transfer. If the NFC reader 200 determines that the difference between the reception time of the first application layer response and the transmission time of the first application layer command is greater than the first duration threshold, the NFC reader 200 and the NFC device 100 will not execute steps S1113 and S1118, thereby prohibiting the execution of the transaction transfer.

[0385] In one example, the first duration threshold is related to the first application layer command and the first application layer response. For example, the first application layer command is a mini-program selection command, in which the identifier of the first applet carried is the UnionPay Applet's AID, and the first application layer response is a mini-program selection response. The first duration threshold can be 21ms. As another example, the first application layer command is a command to obtain processing opinions, and the first application layer response is a processing opinion retrieval response. The first duration threshold can be 48ms. Yet another example, the first application layer command is a mini-program selection command, and the first application layer response is a data retrieval response; the first duration threshold can be 200ms. The above values ​​of the first duration threshold are merely illustrative examples of the embodiments of this application and should not be construed as limiting the embodiments of this application.

[0386] In one possible implementation, the second application layer command can be an application layer command sent by the NFC reader device 200 after receiving the second application layer response. For example, the second application layer response can be a mini-program selection response, and the second application layer command can be a read record command 1. Alternatively, the second application layer response can be a read record response 1, and the second application layer command can be a get processing opinion command. Another example is that the second application layer response can be a get processing opinion response, and the second application layer command can be a read record command 2. Yet another example is that the second application layer response can be a read record response 2, and the second application layer command can be an internal authentication command. Finally, the second application layer response can be an internal authentication response, and the second application layer command can be a data acquisition command.

[0387] In one possible implementation, the second application layer response can be the first application layer response sent by the NFC device 100 in the NFC application layer. For example, the second application layer response can be a mini-program selection response, and the second application layer command can be a data acquisition command.

[0388] If the NFC device 100 determines that the difference between the reception time of the second application layer command and the transmission time of the second application layer response is less than or equal to the second duration threshold, the NFC device 100 and the NFC card reader 200 can execute steps S1113 and S1118 to perform the transaction transfer. If the NFC device 100 determines that the difference between the reception time of the second application layer command and the transmission time of the second application layer response is greater than the second duration threshold, the NFC device 100 and the NFC card reader 200 will not execute steps S1113 and S1118, thereby prohibiting the execution of the transaction transfer.

[0389] In one possible implementation, if the NFC card reader 200 determines that the difference between the reception time of the first application layer response and the transmission time of the first application layer command is less than or equal to a first duration threshold, and the NFC device 100 determines that the difference between the reception time of the second application layer command and the transmission time of the second application layer response is less than or equal to a second duration threshold, then the NFC device 100 and the NFC card reader 200 can execute steps S1113 and S1118 to perform a transaction transfer. If the NFC card reader 200 determines that the difference between the reception time of the first application layer response and the transmission time of the first application layer command is greater than the first duration threshold, or the NFC device 100 determines that the difference between the reception time of the second application layer command and the transmission time of the second application layer response is greater than the second duration threshold, then the NFC device 100 and the NFC card reader 200 do not execute steps S1113 and S1118, thereby prohibiting the execution of the transaction transfer.

[0390] The following describes another embodiment of a near-field communication method provided by this application.

[0391] Figure 12 shows a flowchart of a near-field communication method provided in another embodiment of this application.

[0392] As shown in Figure 12, this near-field communication method can be applied to a communication system including an NFC card reader 200 and an NFC device 100. The NFC device 100 may include an NFC module 102 and a first applet. The NFC card reader 200 is in PCD mode, and the NFC device 100 is in PICC mode. This near-field communication method may include steps S1201 to S1232.

[0393] In one example, steps S1202 to S1207 can be steps of the NFC access layer.

[0394] In one example, steps S1208 to S1232 can be steps of the NFC application layer.

[0395] S1201. The NFC device 100 enters the radio frequency field of the NFC card reader 200.

[0396] In this scenario, a user can hold the NFC device 100 and actively bring the NFC antenna of the NFC device 100 close to the card-swiping area of ​​the NFC card reader 200, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200. Alternatively, the user can also actively hold the NFC card reader 200 and bring the card-swiping area of ​​the NFC card reader 200 close to the NFC antenna of the NFC device 100, thereby allowing the NFC device 100 to enter the radio frequency field of the NFC card reader 200.

[0397] S1202.NFC card reader 200 generates a random number Nv.

[0398] S1203. The NFC card reader 200 sends a second access layer command to the NFC device 100, the second access layer command carrying a random number Nv.

[0399] S1204.NFC device 100 obtains a random number Np.

[0400] The random number Np can be generated by the NFC module 102, or it can be preset in the NFC module 102, or it can be obtained from other modules (e.g., SE).

[0401] S1205. The NFC device 100 sends a second access layer response to the NFC card reader 200, the second access layer response may carry a random number Np.

[0402] The S1206 NFC card reader 200 stores random number Nv and random number Np.

[0403] The S1207 NFC device 100 stores a random number Nv and a random number Np.

[0404] S1208. The NFC card reader 200 sends a Select AID command to the NFC device 100, the Select AID command carrying the identifier of the first Applet.

[0405] The applet selection command is used to select the first applet in the NFC device 100 to interact with the NFC card reader 200 at the NFC application layer.

[0406] The NFC card reader 200 can send the applet selection command to the first applet of the NFC device 100 via the NFC module 102 of the NFC device 100.

[0407] S1209. NFC device 100 sends an applet selection response to NFC card reader 200. The applet selection response is used to indicate that the first applet has been successfully selected.

[0408] The first applet can send the applet selection response to the NFC reader device 200 via the NFC module 102.

[0409] The S1210 NFC card reader 200 uses key K and a second encryption / decryption algorithm to encrypt random numbers Nv and Np to obtain ciphertext C.

[0410] For example, the second encryption / decryption algorithm can be a MAC algorithm. The ciphertext C can be determined by the following formula (1).

[0411] C = MAC K Formula (1) for (Np, Nv)

[0412] The S1211.NFC card reader 200 determines the speed measurement sequence Z0 based on the ciphertext C.

[0413] For example, the speed measurement sequence Z0 can be the binary sequence corresponding to the ciphertext C, which can be written as Z0 = C.

[0414] The S1212 NFC reader device 200 determines the speed measurement sequence Z1 based on the ciphertext C and the key K.

[0415] For example, the speed measurement sequence Z1 can be the binary sequence after XORing the ciphertext C and the key K, which can be denoted as Z1=C⊕K.

[0416] S1213.NFC card reader 200 generates N index bit values, where N is a positive integer.

[0417] The data length of speed measurement sequence Z0 is the same as that of speed measurement sequence Z1, and both the data length of speed measurement sequence Z0 and speed measurement sequence Z1 are greater than or equal to N bits.

[0418] S1214. NFC device 100 acquires random number Nv and random number Np.

[0419] The first applet can obtain random numbers Nv and Np from the NFC module 102.

[0420] In one possible implementation, the random number Nv and the random number Np can be stored in other modules (e.g., SE) of the NFC device 100. The first applet can obtain the random number Nv and the random number Np from the other modules (e.g., SE) of the NFC device 100.

[0421] S1215. NFC device 100 uses key K and a second encryption / decryption algorithm to encrypt random numbers Nv and Np to obtain ciphertext C.

[0422] The first applet can use a key K and a second encryption / decryption algorithm to obtain ciphertext C from random numbers Nv and Np.

[0423] For example, the second encryption / decryption algorithm can be the MAC algorithm. The ciphertext C can be determined by the above formula (1), which will not be repeated here.

[0424] S1216.NFC device 100 determines the speed measurement sequence Z0 based on ciphertext C.

[0425] For example, the speed measurement sequence Z0 can be the binary sequence corresponding to the ciphertext C, which can be written as Z0 = C.

[0426] S1217.NFC device 100 determines speed measurement sequence Z1 based on ciphertext C and key K.

[0427] For example, the speed measurement sequence Z1 can be the binary sequence after XORing the ciphertext C and the key K, which can be denoted as Z1=C⊕K.

[0428] S1218. The NFC card reader 200 sends M speed measurement commands to the NFC device 100. The M speed measurement commands carry N index bit values, where M is a positive integer and M≤N.

[0429] S1219. NFC device 100 queries N response bit values ​​from speed measurement sequence Z0 and speed measurement sequence Z1 based on N index bit values.

[0430] The response bit value can be determined by the following formula (2):

[0431] In formula (2) above, ri can be used to represent the i-th response bit value, ci can be used to represent the i-th index bit value, Z0[i] can be used to represent the value of the i-th bit in the speed measurement sequence Z0, and Z1[i] can be used to represent the value of the i-th bit in the speed measurement sequence Z1. i is a positive integer, and 1≤i≤N.

[0432] S1220. NFC device 100 sends M speed measurement responses to NFC card reader 200, with each M speed measurement response carrying N response bit values.

[0433] Each speed measurement command carries one or more index bit values, each of which can be 0 or 1.

[0434] The NFC reader 200 sends a speed measurement command to the NFC device 100 each time. Upon receiving a speed measurement command, the NFC device 100 can query one or more response bit values ​​corresponding to one or more index bit values ​​in the speed measurement sequence Z0 and Z1, based on one or more index bit values ​​carried in the command. Each index bit value corresponds to one response bit value. After retrieving the one or more response bit values ​​corresponding to one or more index bit values ​​in the speed measurement command, the NFC device 100 can send a speed measurement response corresponding to the command. The speed measurement response carries one or more response bit values, and these response bit values ​​correspond to one or more index bit values ​​in the speed measurement command.

[0435] In one possible implementation, the NFC reader device 200 can generate N index bit values ​​at a time.

[0436] In one possible implementation, the NFC reader 200 may also generate one or more index bit values ​​before each speed measurement command is sent. Since there are M speed measurement commands, the NFC reader 200 can generate N index bit values ​​in M ​​separate steps.

[0437] After sending a speed test command, the NFC card reader 200 needs to wait for the NFC device 100 to reply with a speed test response before sending the next speed test command.

[0438] For example, the speed measurement sequence Z0 can be "010101", and the speed measurement sequence Z1 can be "111000". The NFC card reader 200 can send speed measurement command 1 to the NFC device 100, where speed measurement command 1 can carry an index bit value c1, which can be "1". The NFC device 100 can reply to the NFC card reader 200 with speed measurement response 1, which carries a response bit value r1, which can be "1". The NFC card reader 200 can send speed measurement command 2 to the NFC device 100, where speed measurement command 2 can carry an index bit value c2, which can be "0". The NFC device 100 can reply to the NFC card reader 200 with speed measurement response 2, which carries a response bit value r2, which can be "1". The NFC card reader 200 can send speed measurement command 3 to the NFC device 100, where speed measurement command 3 can carry an index bit value c3, which can be "1". NFC device 100 can respond to NFC card reader 200 with a speed test response 3, which carries a response bit value r3, and r3 can be "1". NFC card reader 200 can send a speed test command 4 to NFC device 100, where the speed test command 4 can carry an index bit value c4, and c4 can be "0". NFC device 100 can respond to NFC card reader 200 with a speed test response 4, which carries a response bit value r4, and r4 can be "1". NFC card reader 200 can send a speed test command 5 to NFC device 100, where the speed test command 5 can carry an index bit value c5, and c5 can be "1". NFC device 100 can respond to NFC card reader 200 with a speed test response 5, which carries a response bit value r5, and r5 can be "0". NFC card reader 200 can send a speed test command 6 to NFC device 100, where the speed test command 6 can carry an index bit value c6, and c6 can be "0". The NFC device 100 can reply with a speed measurement response 6 to the NFC card reader 200. The speed measurement response 6 carries a response bit value r6, which can be "1". That is, the index bits c0 to c6 can be "101010" and the response bits r1 to r6 can be "111101".

[0439] The S1221 NFC card reader 200 records the sending time of M speed measurement commands and the receiving time of M speed measurement responses.

[0440] The S1222.NFC card reader 200 uses key K to encrypt a random number Np to obtain ciphertext Vv.

[0441] Among them, the NFC card reader 200 can use key K to encrypt the random number Np based on the third encryption and decryption algorithm to obtain ciphertext Vv.

[0442] For example, the third encryption / decryption algorithm can be a MAC algorithm, and the ciphertext Vv can be determined by the following formula (3):

[0443] Vv = MAC K (Np) formula (3)

[0444] S1223. The NFC card reader 200 sends an authentication command to the NFC device 100, the authentication command carrying the encrypted text Vv.

[0445] S1224. NFC device 100 uses key K and random number Np to verify ciphertext Vv.

[0446] In this process, the first Applet of the NFC device 100 can use the key K to decrypt the random number Np' from the ciphertext Vv based on the third encryption and decryption algorithm. If the random number Np' is the same as the random number Np, it is determined that the verification of the ciphertext Vv is successful. If the random number Np' is different from the random number Np, it is determined that the verification of the ciphertext Vv is unsuccessful.

[0447] S1225. After verifying the ciphertext Vv, the NFC device 100 uses key K to encrypt N index bit values, random number Np, and random number Nv to obtain ciphertext Vp.

[0448] The first Applet of the NFC device 100 can use key K to encrypt N index bit values, random number Np and random number Nv based on the fourth encryption and decryption algorithm to obtain ciphertext Vp.

[0449] For example, the fourth encryption / decryption algorithm can be a MAC algorithm, and the ciphertext Vp can be determined by the following formula (4):

[0450] Vp = MAC K Formula (4) (c1,…,cN,Np,Nv)

[0451] In the above formula (4), c1, ..., cN are N index bit values.

[0452] S1226. NFC device 100 sends authentication response 1 to NFC card reader 200, and authentication response 1 carries encrypted text Vp.

[0453] The first applet of the NFC device 100 can send an authentication response 1 to the NFC reader device 200 via the NFC module 102.

[0454] In one possible implementation, if the first applet of the NFC device 100 fails to verify the ciphertext Vv, the first applet can send an authentication response 2 to the NFC reader device 200 via the NFC module 102. The authentication response 2 indicates that the verification of the ciphertext Vv has failed. Upon receiving the authentication response 2, the NFC reader device 200 prohibits NFC transactions with the NFC device 100.

[0455] After receiving the authentication response 1, the S1227.NFC card reader 200 uses the key K, random number Np, random number Nv and N index bit values ​​to verify the ciphertext Vp.

[0456] The NFC reader 200 can use a key K, a random number Np, a random number Nv, and N index bits to decrypt the plaintext from the ciphertext Vp using a fourth encryption / decryption algorithm. If the ciphertext includes the random number Np, the random number Nv, and the N index bits, the NFC reader 200 can determine that the verification of the ciphertext Vp was successful. If the ciphertext does not include the random number Np, the random number Nv, or the N index bits, the NFC reader 200 can determine that the verification of the ciphertext Vp failed.

[0457] The S1228.NFC card reader 200 verifies N response bit values ​​in M ​​speed measurement responses using speed measurement sequence Z0, speed measurement sequence Z1, and N index bit values.

[0458] The NFC card reader 200 can verify whether the N response bit values ​​in the M speed measurement responses are correct based on the above formula (2). If the N response bit values ​​in the M speed measurement responses are correct, the verification of the N response bit values ​​in the M speed measurement responses is successful. If the N response bit values ​​in the M speed measurement responses are incorrect, the verification of the N response bit values ​​in the M speed measurement responses fails.

[0459] After successfully verifying the ciphertext Vp and N response bit values, the S1229.NFC card reader 200 determines the command execution duration Δt based on the sending time of M speed measurement commands and the receiving time of M speed measurement responses.

[0460] The command execution duration Δt can be used to indicate the time from the start of sending an application layer command to the NFC device 100 to the receipt of an application layer response from the NFC device 100 in response to the application layer command.

[0461] In one possible implementation, the NFC reader 200 can determine the difference between the reception time of the j-th speed measurement response and the transmission time of the j-th speed measurement command to obtain the j-th speed measurement time tcj. Here, j can take the value of a positive integer from 1 to M. Therefore, the NFC reader 200 can determine M speed measurement times based on the transmission times of M speed measurement commands and the reception times of M speed measurement responses. The NFC reader 200 can determine the command execution duration Δt based on the M speed measurement times. For example, the command execution duration Δt can be the average of the M speed measurement times. Alternatively, the command execution duration Δt can be the median value of the M speed measurement times.

[0462] In one possible implementation, if the NFC card reader 200 fails to verify the ciphertext Vp or fails to verify N response bit values, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services.

[0463] S1230.NFC card reader 200 determines whether the command execution duration Δt is less than or equal to the first duration threshold T.

[0464] S1231. If the command execution duration Δt is less than or equal to the first duration threshold T, the NFC card reader 200 can perform NFC services with the NFC device 100.

[0465] S1232. If the command execution time Δt is greater than the first time threshold T, the NFC card reader 200 and the NFC device 100 shall be prohibited from performing NFC services.

[0466] Because there are intermediaries between the NFC reader device 200 and the NFC device 100 that relay NFC application layer commands (including speed measurement commands) or NFC application layer responses (including speed measurement responses), the transmission latency of NFC application commands or responses will increase. Therefore, if the command execution duration Δt is less than or equal to the first duration threshold T, it indicates that there are no intermediaries between the NFC reader device 200 and the NFC device 100 relaying NFC application layer commands and responses. Therefore, the NFC reader device 200 can perform NFC services with the NFC device 100. If the command execution duration Δt is greater than the first duration threshold T, it indicates that there are intermediaries between the NFC reader device 200 and the NFC device 100 relaying NFC application layer commands and responses. Therefore, the NFC reader device 200 and the NFC device 100 are prohibited from performing NFC services.

[0467] NFC services can include any one or more of the following: codeless payment, electronic tickets, access control, digital ID cards, contactless payment across all scenarios, near-field data transmission, transaction transfer, car keys, and smart locks.

[0468] According to the near-field communication method provided in this application embodiment, an NFC card reader 200 can send M speed measurement commands to an NFC device 100 at the NFC application layer, and each of the M speed measurement commands carries N index bit values. The NFC device 100 can send M speed measurement responses to the NFC card reader 200 in response to the M speed measurement commands, where each of the M speed measurement responses carries N response bit values. After successfully verifying the N response bit values ​​based on the N bit values, the NFC card reader 200 can determine the command execution duration between the NFC card reader 200 and the NFC device 100 based on the reception time of the M speed measurement responses and the transmission time of the M speed measurement commands. If the command execution duration is less than or equal to a first duration threshold, the NFC card reader 200 can perform NFC services with the NFC device 100. If the command execution duration is greater than the first duration threshold, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services.

[0469] This prevents the NFC device 100 and the NFC card reader 200 from having an intermediate device to relay the NFC APDU when performing NFC services, thus improving the security of NFC services.

[0470] Furthermore, by including an index bit value in the speed measurement command and a response bit value in the speed measurement response, the speed measurement command and response can be prevented from being intercepted or tampered with by intermediate devices, thereby improving the security of the speed measurement process.

[0471] In addition, since the NFC device 100 only needs to query the speed measurement sequence to obtain the response bit value corresponding to the index bit value after receiving the speed measurement command, the time difference between the NFC device 100 receiving the speed measurement command and sending the speed measurement response is shortened, thereby improving the accuracy of speed measurement. It can more accurately identify the situation where there is an intermediate device between the NFC device 100 and the NFC card reader 200 to transfer the NFC APDU.

[0472] Furthermore, the NFC reader 200 and the NFC device 100 can exchange random numbers Np and Nv at the NFC access layer. Then, at the NFC application layer, the NFC reader 200 and the NFC device 100 can determine the speed measurement sequence Z0 and the speed measurement sequence Z1 based on the random numbers Np and Nv. Then, the NFC device 100 can determine N response bit values ​​based on the speed measurement sequence Z0, the speed measurement sequence Z1, and N index bit values, thereby completing the encrypted transmission of the speed measurement command and speed measurement response. This also binds the interaction at the NFC access layer and the interaction at the application layer to the same two devices, preventing the use of intermediate devices to relay NFC APDUs and improving the security of NFC services.

[0473] In one example of the embodiments of this application, the key K in the embodiment shown in FIG12 above can be referred to as the second key, the random number Nv can be referred to as the third random number, the random number Np can be referred to as the fourth random number, the speed measurement sequence Z0 can be referred to as the first speed measurement sequence, the speed measurement sequence Z1 can be referred to as the second speed measurement sequence, the ciphertext Vv can be referred to as the first ciphertext, the ciphertext Vp can be referred to as the second ciphertext, the ciphertext C can be referred to as the third ciphertext, the authentication response 1 can be referred to as the first authentication response, and the authentication response 2 can be referred to as the second authentication response.

[0474] Figure 13 shows a flowchart of a near-field communication method provided in another embodiment of this application.

[0475] As shown in Figure 13, this near-field communication method can be applied to a communication system including an NFC card reader 200 and an NFC device 100. The NFC device 100 may include an NFC module 102 and a first applet. The NFC card reader 200 is in PCD mode, and the NFC device 100 is in PICC mode. This near-field communication method may include steps S1301 to S1330.

[0476] In one example, steps S1303 to S1330 can be steps of the NFC application layer.

[0477] S1301. NFC device 100 enters the radio frequency field of NFC card reader 200.

[0478] S1302. The NFC card reader 200 and the NFC device 100 perform command interaction at the access layer.

[0479] S1303. The NFC card reader 200 sends a Select AID command to the NFC device 100, the Select AID command carrying the identifier of the first Applet.

[0480] The applet selection command is used to select the first applet in the NFC device 100 to interact with the NFC card reader 200 at the NFC application layer.

[0481] The NFC card reader 200 can send the applet selection command to the first applet of the NFC device via the NFC module 102 of the NFC device 100.

[0482] S1304. The NFC device 100 sends an applet selection response to the NFC card reader 200. The applet selection response is used to indicate that the first applet has been successfully selected.

[0483] The first applet can send the applet selection response to the NFC reader device 200 via the NFC module 102.

[0484] S1305.NFC card reader 200 generates a random number Nv.

[0485] S1306. The NFC card reader 200 sends a random number acquisition command to the NFC device 100, wherein the random number acquisition command may carry a random number Nv.

[0486] S1307.NFC device 100 generates a random number Np.

[0487] The first applet can generate a random number Np.

[0488] S1308. NFC device 100 sends a random number acquisition response to NFC card reader 200, wherein the random number acquisition response carries a random number Np.

[0489] The first applet can send a random number to the NFC reader 200 via the NFC module 102 to obtain a response.

[0490] The S1309 NFC reader device 200 uses key K and a second encryption / decryption algorithm to encrypt random numbers Nv and Np to obtain ciphertext C.

[0491] The S1310 NFC reader 200 determines the speed measurement sequence Z0 based on the ciphertext C.

[0492] The S1311.NFC reader device 200 determines the speed measurement sequence Z1 based on the ciphertext C and the key K.

[0493] S1312.NFC card reader 200 generates N index bit values, where N is a positive integer.

[0494] S1313.NFC device 100 uses key K and a second encryption / decryption algorithm to encrypt random numbers Nv and Np to obtain ciphertext C.

[0495] S1314.NFC device 100 determines the speed measurement sequence Z0 based on ciphertext C.

[0496] S1315.NFC device 100 determines the speed measurement sequence Z1 based on ciphertext C and key K.

[0497] S1316. The NFC card reader 200 sends M speed measurement commands to the NFC device 100. The M speed measurement commands carry N index bit values, where M is a positive integer and M≤N.

[0498] S1317.NFC device 100 queries N response bit values ​​from speed measurement sequence Z0 and speed measurement sequence Z1 based on N index bit values.

[0499] S1318. The NFC device 100 sends M speed measurement responses to the NFC card reader 200, and the M speed measurement responses carry N response bit values.

[0500] The S1319 NFC reader 200 records the sending time of M speed measurement commands and the receiving time of M speed measurement responses.

[0501] The S1320 NFC reader device 200 uses key K to encrypt a random number Np to obtain ciphertext Vv.

[0502] S1321. The NFC card reader 200 sends an authentication command to the NFC device 100, the authentication command carrying the encrypted text Vv.

[0503] S1322. NFC device 100 uses key K and random number Np to verify ciphertext Vv.

[0504] S1323. After verifying the ciphertext Vv, the NFC device 100 uses key K to encrypt N index bit values, random number Np, and random number Nv to obtain ciphertext Vp.

[0505] S1324. NFC device 100 sends authentication response 1 to NFC card reader 200, and authentication response 1 carries encrypted text Vp.

[0506] In one possible implementation, if the first applet of the NFC device 100 fails to verify the ciphertext Vv, the first applet can send an authentication response 2 to the NFC reader device 200 via the NFC module 102. The authentication response 2 indicates that the verification of the ciphertext Vv has failed. Upon receiving the authentication response 2, the NFC reader device 200 prohibits NFC transactions with the NFC device 100.

[0507] After receiving the authentication response 1, the S1325 NFC card reader 200 uses the key K, random number Np, random number Nv and N index bit values ​​to verify the ciphertext Vp.

[0508] S1326.NFC card reader 200 verifies N response bit values ​​in M ​​speed measurement responses using speed measurement sequence Z0, speed measurement sequence Z1, and N index bit values.

[0509] After successfully verifying the ciphertext Vp and N response bit values, the S1327.NFC card reader 200 determines the command execution duration Δt based on the sending time of M speed measurement commands and the receiving time of M speed measurement responses.

[0510] S1328.NFC card reader 200 determines whether the command execution duration Δt is less than or equal to the first duration threshold T.

[0511] S1329. If the command execution duration Δt is less than or equal to the first duration threshold T, the NFC card reader 200 can perform NFC services with the NFC device 100.

[0512] S1330. If the command execution time Δt is greater than the first time threshold T, the NFC card reader 200 and the NFC device 100 shall prohibit the execution of NFC services.

[0513] The steps S1309 to S1330 mentioned above can be referred to as steps S1210 to S1213 and steps S1215 to S1232 in the embodiment shown in Figure 12, and will not be repeated here.

[0514] According to the near-field communication method provided in this application embodiment, an NFC card reader 200 can send M speed measurement commands to an NFC device 100 at the NFC application layer, and each of the M speed measurement commands carries N index bit values. The NFC device 100 can send M speed measurement responses to the NFC card reader 200 in response to the M speed measurement commands, where each of the M speed measurement responses carries N response bit values. After successfully verifying the N response bit values ​​based on the N bit values, the NFC card reader 200 can determine the command execution duration between the NFC card reader 200 and the NFC device 100 based on the reception time of the M speed measurement responses and the transmission time of the M speed measurement commands. If the command execution duration is less than or equal to a first duration threshold, the NFC card reader 200 can perform NFC services with the NFC device 100. If the command execution duration is greater than the first duration threshold, the NFC card reader 200 and the NFC device 100 are prohibited from performing NFC services.

[0515] This prevents the NFC device 100 and NFC card reader 200 from having other devices relaying NFC APDUs when performing NFC services, thus improving the security of NFC services.

[0516] Furthermore, by including an index bit value in the speed measurement command and a response bit value in the speed measurement response, the speed measurement command and response can be prevented from being intercepted or tampered with by intermediate devices, thereby improving the security of the speed measurement process.

[0517] In addition, since the NFC device 100 only needs to query the speed measurement sequence to obtain the response bit value corresponding to the index bit value after receiving the speed measurement command, the time difference between the NFC device 100 receiving the speed measurement command and sending the speed measurement response is shortened, thereby improving the accuracy of speed measurement. It can more accurately identify the situation where there is an APDU for NFC relay between the NFC device 100 and the NFC card reader 200 through other devices.

[0518] Furthermore, the NFC card reader 200 and the NFC device 100 can exchange random numbers Np and Nv at the NFC application layer. Then, based on the random numbers Np and Nv, the NFC card reader 200 and the NFC device 100 can determine the speed measurement sequence Z0 and the speed measurement sequence Z1 at the NFC application layer. Then, the NFC device 100 can determine N response bit values ​​based on the speed measurement sequence Z0, the speed measurement sequence Z1, and N index bit values, thereby completing the encrypted transmission of the speed measurement command and the speed measurement response.

[0519] In one possible implementation, the random number Nv can be sent from the NFC reader 200 to the NFC device 100 at the NFC access layer. The random number Np can be sent from the NFC device 100 to the NFC reader 200 at the NFC application layer.

[0520] In one possible implementation, the random number Np can be sent from NFC device 100 to NFC device 200 at the NFC access layer. The random number Nv can be sent from NFC card reader 200 to NFC device 100 at the NFC application layer.

[0521] In one example of the embodiments of this application, the key K in the embodiment shown in FIG13 above can be referred to as the second key, the random number Nv can be referred to as the third random number, the random number Np can be referred to as the fourth random number, the speed measurement sequence Z0 can be referred to as the first speed measurement sequence, the speed measurement sequence Z1 can be referred to as the second speed measurement sequence, the ciphertext Vv can be referred to as the first ciphertext, the ciphertext Vp can be referred to as the second ciphertext, the ciphertext C can be referred to as the third ciphertext, the authentication response 1 can be referred to as the first authentication response, and the authentication response 2 can be referred to as the second authentication response.

[0522] The following describes another hardware structure of an NFC device 100 provided in the embodiments of this application.

[0523] Figure 14 shows a schematic diagram of the hardware structure of an NFC device 100 provided in an embodiment of this application.

[0524] The following description uses NFC device 100 as an example to illustrate the embodiment. It should be understood that the NFC device 100 shown in FIG. 14 is merely an example, and the NFC device 100 may have more or fewer components than shown in FIG. 14, may combine two or more components, or may have different component configurations. The various components shown in FIG. 14 can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.

[0525] The NFC device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include one or more of the following: pressure sensor 180A, gyroscope sensor 180B, barometric pressure sensor 180C, magnetic sensor 180D, accelerometer sensor 180E, distance sensor 180F, proximity sensor 180G, fingerprint sensor 180H, temperature sensor 180J, touch sensor 180K, ambient light sensor 180L, bone conduction sensor 180M, etc.

[0526] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the NFC device 100. In other embodiments of this application, the NFC device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0527] Processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors. The controller can generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. Processor 110 may also include memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that processor 110 has just used or is recurring. If processor 110 needs to reuse the instruction or data, it can directly retrieve it from the memory. This avoids repeated access, reduces the waiting time of processor 110, and thus improves system efficiency.

[0528] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0529] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the NFC device 100. In other embodiments of this application, the NFC device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0530] The charging management module 140 receives charging input from the charger. The power management module 141 connects to the battery 142, and the charging management module 140 connects to the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, internal memory 121, external memory, display 194, camera 193, and wireless communication module 160, etc.

[0531] The wireless communication function of the NFC device 100 can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the NFC device 100 can be used to cover one or more communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with a tuning switch.

[0532] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the NFC device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via the antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to the modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via the antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.

[0533] The wireless communication module 160 can provide solutions for wireless communication applications on the NFC device 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0534] In some embodiments, antenna 1 of NFC device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling NFC device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).

[0535] The NFC device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0536] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD). The display panel can also be manufactured using organic light-emitting diodes (OLEDs), active-matrix organic light-emitting diodes (AMOLEDs), flexible light-emitting diodes (FLEDs), miniled, microled, micro-oled, quantum dot light-emitting diodes (QLEDs), etc. In some embodiments, the NFC device 100 may include one or N displays 194, where N is a positive integer greater than 1.

[0537] The NFC device 100 can perform shooting functions through an ISP, camera 193, video codec, GPU, display 194, and application processor.

[0538] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the NFC device 100. The internal memory 121 can be used to store computer-executable program code, including instructions. The processor 110 executes various functional applications and data processing of the NFC device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of the NFC device 100 (such as audio data, phonebook, etc.). Furthermore, the internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0539] The NFC device 100 can implement audio functions, such as music playback and recording, through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, and an application processor.

[0540] Pressure sensor 180A senses pressure signals and converts them into electrical signals. Gyroscope sensor 180B determines the motion posture of NFC device 100. Barometric pressure sensor 180C measures air pressure. Magnetic sensor 180D includes a Hall effect sensor. Accelerometer sensor 180E detects the magnitude of acceleration of NFC device 100 in various directions (typically three axes). Distance sensor 180F measures distance. Proximity sensor 180G may include, for example, a light-emitting diode (LED) and a photodetector, such as a photodiode. Ambient light sensor 180L senses ambient light intensity. Fingerprint sensor 180H collects fingerprints. Temperature sensor 180J detects temperature. Touch sensor 180K, also called a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also called a "touch screen." Touch sensor 180K detects touch operations applied to or near it. A touch sensor can transmit detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided via display screen 194. In some embodiments, touch sensor 180K may also be located on the surface of NFC device 100, in a different position than display screen 194. Bone conduction sensor 180M can acquire vibration signals. Buttons 190 include a power button, volume buttons, etc. Motor 191 can generate vibration cues. Indicator 192 may be an indicator light, used to indicate charging status, battery level changes, or to indicate messages, missed calls, notifications, etc.

[0541] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 195 to make contact with and separate from the NFC device 100. The NFC device 100 can support one or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 195 simultaneously. The multiple cards can be of the same or different types. The SIM card interface 195 is also compatible with different types of SIM cards. The SIM card interface 195 is also compatible with external memory cards. The NFC device 100 interacts with the network through the SIM card to realize functions such as calls and data communication. In some embodiments, the NFC device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the NFC device 100 and cannot be separated from the NFC device 100.

[0542] In some embodiments, the wireless communication module 160 can specifically be used to establish a short-range wireless communication link with the NFC card reader 200, so that the two can perform short-range wireless data transmission with each other. Exemplarily, the aforementioned short-range wireless communication link can be a Bluetooth link, a Wi-Fi link, an NFC link, etc. Therefore, the wireless communication module 160 can specifically include a Bluetooth communication module, a Wi-Fi communication module, or an NFC module. The NFC module can include any suitable components for implementing proximity-based contactless communication between the NFC device 100 and the NFC card reader 200, thereby providing NFC functionality to the NFC device 100. A description of the NFC module can be found in the embodiment shown in FIG3 above, and will not be repeated here.

[0543] The foregoing details the method provided in this application. In order to facilitate better implementation of the above-described solutions in the embodiments of this application, the embodiments of this application also provide corresponding devices or equipment.

[0544] This application embodiment can divide the NFC device 100 and NFC card reader 200 into functional modules according to the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.

[0545] The communication device of the present application embodiment will now be described in detail with reference to Figures 15 to 18.

[0546] Referring to FIG15, which is a schematic diagram of the structure of a communication device 1500 provided in an embodiment of this application, the communication device 1500 can be the NFC device 100 or an NFC tag card as described in the above embodiments. Optionally, the communication device 1500 can be a chip / chip system, such as an NFC chip. As shown in FIG15, the communication device 1500 may include a transceiver unit 1510 and a processing unit 1520.

[0547] The transceiver unit 1510 can also be used to perform NFC sending and NFC receiving functions performed by the NFC device 100 in the above embodiments of this application.

[0548] Optionally, the processing unit 1520 can also be used to perform the functional steps related to NFC protocol parsing and encapsulation, NFC service processing flow and display performed by the NFC device 100 in the above embodiments of this application.

[0549] It should be understood that the communication device 1500 in this design can perform the method steps performed by the NFC device 100 in the aforementioned embodiment, and for the sake of brevity, it will not be described again here.

[0550] Referring to FIG16, which is a schematic diagram of the structure of a communication device 1600 provided in an embodiment of this application, the communication device 1600 can be the NFC card reader 200 in the above embodiments. As shown in FIG16, the communication device 1600 may include a transceiver unit 1610 and a processing unit 1620.

[0551] Optionally, the transceiver unit 1610 can also be used to perform the NFC sending and NFC receiving functions performed by the NFC card reader 200 in the above embodiments of this application.

[0552] Optionally, the processing unit 1620 can also be used to execute the functional steps related to NFC protocol parsing and encapsulation and NFC service processing flow executed by the NFC card reader 200 in the above embodiments of this application.

[0553] It should be understood that the communication device 1600 in this design can perform the method steps executed by the NFC card reader 200 in the aforementioned embodiment, and for the sake of brevity, it will not be described again here.

[0554] The NFC device 100 and NFC card reader 200 of the present application embodiments have been described above. It should be understood that any product with the functions of the NFC device 100 described in FIG15 above, or any product with the functions of the NFC card reader 200 described in FIG16 above, falls within the protection scope of the present application embodiments.

[0555] As a possible product form, the NFC device 100 described in this application embodiment can be implemented using a general bus architecture.

[0556] Referring to Figure 17, which is a schematic diagram of the structure of the communication device 1700 provided in an embodiment of this application, the communication device 1700 can be an NFC device 100 or an NFC tag card, or a device within an NFC device 100 or an NFC tag card. As shown in Figure 17, the communication device 1700 includes a processor 1701 and a transceiver 1702 internally connected and communicating with the processor 1701. The processor 1701 can be a general-purpose processor or a dedicated processor, for example, a central processing unit and / or an NFC controller. The transceiver 1702 can be referred to as a transceiver unit, transceiver, or transceiver circuit, etc., and is used to implement transceiver functions. The transceiver 1702 can include a receiver and a transmitter. The receiver can be referred to as a receiver or receiving circuit, etc., and is used to implement a receiving function, such as an NFC receiving function; the transmitter can be referred to as a transmitter or transmitting circuit, etc., and is used to implement a transmitting function, such as an NFC transmitting function. Optionally, the communication device 1700 may also include an antenna 1703 and / or a radio frequency unit (not shown in FIG. 17), such as an NFC antenna, wherein the NFC antenna may be a coil-type antenna. The antenna 1703 and / or the radio frequency unit may be located inside the communication device 1700 or may be separate from the communication device 1700, that is, the antenna 1703 and / or the radio frequency unit may be remotely or distributedly deployed.

[0557] Optionally, the communication device 1700 may include one or more memories 1704, which may store instructions, which may be computer programs, that can be executed on the communication device 1700 to cause the communication device 1700 to perform the method steps described in the above embodiments of this application. Optionally, the memory 1704 may also store data. The communication device 1700 and the memory 1704 may be provided separately or integrated together.

[0558] The processor 1701, transceiver 1702, and memory 1704 can be connected via a communication bus.

[0559] In one design, the communication device 1700 can be used to perform the functions of the NFC device 100 in the foregoing embodiments: the processor 1701 can be used to perform the functional steps related to NFC protocol parsing and encapsulation, NFC service processing flow and display performed by the NFC device 100 in the foregoing embodiments of this application and / or other processes used in the technology described herein; the transceiver 1702 can be used to perform the functional steps related to NFC sending and NFC receiving performed by the NFC device 100 in the foregoing embodiments of this application and / or other processes used in the technology described herein.

[0560] In any of the above designs, the processor 1701 may include a transceiver for implementing receive and transmit functions. For example, the transceiver may be a transceiver circuit, an interface, or an interface circuit. The transceiver circuit, interface, or interface circuit for implementing receive and transmit functions may be separate or integrated. The aforementioned transceiver circuit, interface, or interface circuit may be used for reading and writing code / data, or it may be used for transmitting or relaying signals.

[0561] In any of the above designs, the processor 1701 may store instructions, which may be computer programs. These computer programs, running on the processor 1701, cause the communication device 1700 to execute the method steps performed by the NFC device 100 in the above embodiments of this application. The computer program may be embedded in the processor 1701; in this case, the processor 1701 may be implemented in hardware.

[0562] In one implementation, the communication device 1700 may include circuitry capable of performing the functions of transmitting, receiving, or communicating as described in the foregoing method embodiments. The processor and transceiver described in this application can be implemented on integrated circuits (ICs), analog ICs, radio frequency integrated circuits (RFICs), mixed-signal ICs, application-specific integrated circuits (ASICs), printed circuit boards (PCBs), electronic devices, etc. The processor and transceiver can also be manufactured using various IC process technologies, such as complementary metal-oxide-semiconductor (CMOS), n-metal-oxide-semiconductor (NMOS), p-type metal-oxide-semiconductor (PMOS), bipolar junction transistors (BJTs), bipolar CMOS (BiCMOS), silicon-germanium (SiGe), gallium arsenide (GaAs), etc.

[0563] The scope of the communication device described in this application is not limited thereto, and the structure of the communication device is not limited to that shown in FIG17. Communication device 1700 may be a standalone device or part of a larger device. For example, the communication device 1700 may be:

[0564] (1) A standalone integrated circuit IC, or chip, or chip system or subsystem; (2) A collection of one or more ICs, optionally including storage components for storing data or computer programs; (3) An ASIC, such as an NFC chip; (4) A module that can be embedded in other devices; (5) A receiver, terminal, smart terminal, cellular phone, wireless device, handheld device, mobile unit, vehicle device, network device, cloud device, artificial intelligence device, etc.; (6) Others, etc.

[0565] As a possible product form, the NFC card reader 200 described in this application embodiment can be implemented using a general bus architecture.

[0566] Referring to Figure 18, which is a schematic diagram of the structure of a communication device 1800 provided in an embodiment of this application, the communication device 1800 may be an NFC card reader device 200, or a device therein. As shown in Figure 18, the communication device 1800 includes a processor 1801 and a transceiver 1802 internally connected and communicating with the processor 1801. The processor 1801 may be a general-purpose processor or a dedicated processor, for example, an NFC controller. The transceiver 1802 may be referred to as a transceiver unit, transceiver, or transceiver circuit, etc., and is used to implement transceiver functions. The transceiver 1802 may include a receiver and a transmitter. The receiver may be referred to as a receiver or receiving circuit, etc., and is used to implement a receiving function; the transmitter may be referred to as a transmitter or transmitting circuit, etc., and is used to implement a transmitting function. Optionally, the communication device 1800 may also include an antenna 1803 and / or a radio frequency unit (not shown in the figure). The antenna 1803 and / or radio frequency unit may be located inside the communication device 1800 or separate from the communication device 1800, that is, the antenna 1803 and / or radio frequency unit may be deployed remotely or in a distributed manner.

[0567] Optionally, the communication device 1800 may include one or more memories 1804, which may store instructions, which may be computer programs, that can be executed on the communication device 1800 to cause the communication device 1800 to perform the method steps described in the above embodiments of this application. Optionally, the memory 1804 may also store data. The communication device 1800 and the memory 1804 may be provided separately or integrated together.

[0568] The processor 1801, transceiver 1802, and memory 1804 can be connected via a communication bus.

[0569] In one design, the communication device 1800 can be used to perform the functions of the NFC card reader 200 in the foregoing embodiments: the processor 1801 can be used to perform the functional steps related to NFC protocol parsing and encapsulation, NFC service processing flow and / or other processes used in the technology described herein, performed by the NFC card reader 200 in the foregoing embodiments; the transceiver 1802 can be used to perform the functional steps related to NFC sending and NFC receiving performed by the NFC card reader 200 in the foregoing embodiments and / or other processes used in the technology described herein.

[0570] In any of the above designs, the processor 1801 may include a transceiver for implementing receive and transmit functions. For example, the transceiver may be a transceiver circuit, an interface, or an interface circuit. The transceiver circuit, interface, or interface circuit for implementing receive and transmit functions may be separate or integrated. The aforementioned transceiver circuit, interface, or interface circuit may be used for reading and writing code / data, or it may be used for transmitting or relaying signals.

[0571] In any of the above designs, the processor 1801 may store instructions, which may be computer programs. These computer programs, running on the processor 1801, cause the communication device 1800 to execute the method steps performed by the NFC card reader 200 in the above method embodiments. The computer program may be embedded in the processor 1801; in this case, the processor 1801 may be implemented in hardware.

[0572] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the steps performed by the NFC device 100 in the above-described method embodiments.

[0573] This application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps performed by the NFC card reader 200 in the above-described method embodiments.

[0574] This application also provides a computer program product, including a computing program, which, when run on a computer, enables the computer to perform the steps executed by the NFC device 100 in the above-described method embodiments.

[0575] This application also provides a computer program product, including a computing program, which, when run on a computer, enables the computer to perform the steps executed by the NFC card reader 200 in the above-described method embodiments.

[0576] This application also provides a chip system, which includes a processing circuit interface circuit. The interface circuit receives code instructions and transmits them to the processing circuit. The processing circuit executes the code instructions to enable the chip system to perform the steps executed by the NFC device 100 in any method embodiment of this application. The chip system can be a single chip or a chip module composed of multiple chips.

[0577] This application also provides a chip system, which includes a processing circuit interface circuit. The interface circuit receives code instructions and transmits them to the processing circuit. The processing circuit executes the code instructions to enable the chip system to perform the steps executed by the NFC card reader 200 in any method embodiment of this application. The chip system can be a single chip or a chip module composed of multiple chips.

[0578] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A near-field communication method, applied to a near-field communication (NFC) device, characterized in that, The method comprises: receiving a first access layer command sent by an NFC card reader; sending a first access layer response to the NFC card reader, wherein the first access layer response carries a first random number; receiving a random number acquisition command sent by the NFC card reader; sending a random number acquisition response to the NFC card reader, wherein the random number acquisition response carries a second random number; receiving an authentication command sent by the NFC card reader, wherein the authentication command carries first cipher text data; if the first cipher text data is verified successfully based on the first random number and the second random number, performing an NFC service with the NFC card reader.

2. The method of claim 1, wherein, The method further comprises: if the first cipher text data fails to be verified based on the first random number and the second random number, prohibiting the NFC service from being performed with the NFC card reader.

3. The method according to claim 1 or 2, characterized in that, Before the receiving of the random number acquisition command sent by the NFC card reader, the method further comprises: receiving an applet selection command sent by the NFC card reader, wherein the applet selection command carries an identifier of a first applet; sending an applet selection response to the NFC card reader, wherein the applet selection response is used to indicate that the selection of the first applet is successful.

4. The method according to any one of claims 1 to 3, characterized in that, If the first cipher text data is verified successfully based on the first random number and the second random number, the method further comprises: sending a first authentication response to the NFC card reader, wherein the first authentication response carries a first authentication result, and the first authentication result is used to indicate that the authentication is successful.

5. The method of claim 2, wherein, If the first cipher text data fails to be verified based on the first random number and the second random number, the method further comprises: sending a second authentication response to the NFC card reader, wherein the second authentication response carries a second authentication result, and the second authentication result is used to indicate that the authentication fails.

6. The method according to any one of claims 1-5, characterized in that, The verification of the first cipher text data based on the first random number and the second random number comprises: generating a first parameter based on the first random number and the second random number; decrypting a second parameter from the first cipher text data by using a first key; if the second parameter is the same as the first parameter, it is determined that the first cipher text data is verified successfully.

7. The method according to any one of claims 1-5, characterized in that, The verification of the first cipher text data based on the first random number and the second random number comprises: generating a first parameter based on the first random number and the second random number; encrypting the first parameter by using a first key to obtain second cipher text data; if the second cipher text data is the same as the first cipher text data, it is determined that the first cipher text data is verified successfully.

8. The method according to any one of claims 1-7, characterized in that, The first access layer command is an anti-collision command, and the first access layer response is an anti-collision response.

9. The method according to any one of claims 1-7, characterized in that, The first access layer command is a probe frame, and the first access layer response is a probe acknowledgement (Probe ACK) frame.

10. A near field communication method applied to an NFC card reading device, characterized in that, The method comprises: sending a first access layer command to an NFC device; receiving a first access layer response sent by the NFC device, wherein the first access layer response carries a first random number; sending a random number acquisition command to the NFC device; receiving a random number obtaining response sent by the NFC device, wherein the random number obtaining response carries a second random number; encrypting the first random number and the second random number to obtain first cipher text data; sending an authentication command to the NFC device, wherein the authentication command carries the first cipher text data; if a first authentication response sent by the NFC device is received, performing an NFC service with the NFC device, wherein the first authentication response carries a first authentication result, and the first authentication result is used to indicate that the authentication is successful.

11. The method of claim 10, wherein, The method further comprises: if a second authentication response sent by the NFC device is received, prohibiting the NFC service with the NFC device, wherein the second authentication response carries a second authentication result, and the second authentication result is used to indicate that the authentication is failed.

12. The method according to claim 10 or 11, characterized in that, Before the random number obtaining command is sent to the NFC device, the method further comprises: sending an applet selection command to the NFC device, wherein the applet selection command carries an identifier of a first Applet; receiving an applet selection response sent by the NFC device, wherein the applet selection response is used to indicate that the first Applet is selected successfully.

13. The method according to any one of claims 10-12, characterized in that, The encryption of the first random number and the second random number to obtain the first cipher text data comprises: generating a first parameter based on the first random number and the second random number; encrypting the first parameter using a first key to obtain the first cipher text data.

14. The method according to any one of claims 10-13, characterized in that, The first access layer command is a collision avoidance command, and the first access layer response is a collision avoidance response.

15. The method according to any one of claims 10-14, characterized in that, The first access layer command is a probe frame, and the first access layer response is a probe acknowledgement (Probe ACK) frame.

16. A near field communication method applied to an NFC card reading device, characterized in that, comprises: sending one or more application layer commands to the NFC device; receiving one or more application layer responses sent by the NFC device; determining a command execution duration based on a receiving time of the one or more application layer responses and a sending time of the one or more application layer commands; if the command execution duration is less than or equal to a first duration threshold, performing the NFC service with the NFC device.

17. The method of claim 16, wherein, The method further comprises: if the command execution duration is greater than the first duration threshold, prohibiting the NFC service with the NFC device.

18. The method according to claim 16 or 17, characterized in that, The one or more application layer commands comprise a first application layer command, and the one or more application layer responses comprise a first application layer response; The determination of the command execution duration based on the receiving time of the one or more application layer responses and the sending time of the one or more application layer commands comprises: determining a difference between the receiving time of the first application layer response and the sending time of the first application layer command as the command execution duration.

19. The method of claim 18, wherein, The first application layer command is a first speed measurement command, and the second application layer command is a first speed measurement response.

20. The method of any one of claims 16-19, wherein, The first duration threshold is preset in the NFC card reading device.

21. The method of any one of claim 19, wherein, The first speed measurement response comprises the first duration threshold.

22. The method of claim 16 or 17, wherein, The one or more application layer commands are M speed measurement commands, and the one or more application layer responses are M speed measurement responses, where M is a positive integer; The determining of the command execution duration based on the time of receiving the one or more application layer responses and the time of sending the one or more application layer commands comprises: The determining of the command execution duration based on the time of receiving the M speed measurement responses and the time of sending the M speed measurement commands.

23. The method of claim 22, wherein, The M speed measurement commands carry N index bit values, and the M speed measurement responses carry N response bit values.

24. The method of claim 23, wherein, Before the sending of the one or more application layer commands to the NFC device, the method further comprises: sending a third random number to the NFC device; receiving a second random number sent by the NFC device; determining a first speed measurement sequence and a second speed measurement sequence based on a second key, the third random number and the fourth random number.

25. The method of claim 24, wherein, Before the determining of the command execution duration based on the time of receiving the M speed measurement responses and the time of sending the M speed measurement commands, the method further comprises: encrypting the second random number using the second key to obtain a first cipher text; sending an authentication command to the NFC device, where the authentication command carries the first cipher text; if a first authentication response sent by the NFC device is received, where the first authentication response carries a second cipher text, verifying the second cipher text using the second key, the third random number and the fourth random number, and verifying the N response bit values using the first speed measurement sequence, the second speed measurement sequence and the N index bit values; The determining of the command execution duration based on the time of receiving the M speed measurement responses and the time of sending the M speed measurement commands comprises: if the verification of the second cipher text is successful and the verification of the N response bit values is successful, determining the command execution duration based on the time of receiving the M speed measurement responses and the time of sending the M speed measurement commands.

26. The method of claim 25, wherein, The method further comprises: if a second authentication response sent by the NFC device is received, where the second authentication response is used to indicate that the verification of the first cipher text fails, prohibiting the NFC service from being executed with the NFC device.

27. The method of claim 25 or 26, wherein, The method further comprises: if the verification of the second cipher text fails or the verification of the N response bit values fails, prohibiting the NFC service from being executed with the NFC device.

28. The method of any one of claims 24-27, wherein, The determining of the first speed measurement sequence and the second speed measurement sequence based on the second key, the third random number and the fourth random number comprises: encrypting the third random number and the fourth random number using the second key and a second encryption and decryption algorithm to obtain a third cipher text; determining the first speed measurement sequence based on the third cipher text; determining the second speed measurement sequence based on the third cipher text and the second key.

29. The method of any one of claims 24-28, wherein, The sending of the third random number to the NFC device comprises: sending a second access layer command to the NFC device, where the second access layer command carries the third random number; The receiving of the fourth random number sent by the NFC device comprises: The receiving the second access layer response sent by the NFC device, the second access layer response carrying the fourth random number.

30. The method of any one of claims 24-28, wherein, The sending a third random number to the NFC device comprises: sending a random number obtaining command to the NFC device, the random number obtaining command carrying the third random number; The receiving the fourth random number sent by the NFC device comprises: The receiving the random number obtaining response sent by the NFC device, the random number obtaining response carrying the fourth random number.

31. A communication system, characterized by Comprise: An NFC device and an NFC card reading device; wherein, The NFC device is configured to perform the method of any one of claims 1-9. The NFC card reading device is configured to perform the method of any one of claims 10-15.

32. An NFC device, characterized in that, Comprise: One or more processors, one or more memories, and a transceiver, wherein the transceiver, the one or more memories, and the one or more processors are coupled, the one or more memories are configured to store a computer program, and the transceiver is configured to send and / or receive signals, and when the one or more processors execute the computer program, implement the near field communication method of any one of claims 1-9.

33. An NFC card reading device, characterized by Comprise: One or more processors, one or more memories, and a transceiver, wherein the transceiver, the one or more memories, and the one or more processors are coupled, the one or more memories are configured to store a computer program, and the transceiver is configured to send and / or receive signals, and when the one or more processors execute the computer program, implement the near field communication method of any one of claims 10-15 or 16-30.

34. A computer-readable storage medium, characterized in that, The computer program is stored and when executed by a processor, implements the near field communication method of any one of claims 1-9.

35. A computer readable storage medium, characterized in that, The computer program is stored and when executed by a processor, implements the near field communication method of any one of claims 10-15 or 16-30.

36. A computer program product, characterised in that, The computer program is included and when executed by a processor, implements the near field communication method of any one of claims 1-9.

37. A computer program product, characterised in that, The computer program is included and when executed by a processor, implements the near field communication method of any one of claims 10-15 or 16-30.

38. A chip system, characterized by Comprise a processing circuit and an interface circuit, the interface circuit is configured to receive code instructions and transmit to the processing circuit, and the processing circuit is configured to run the code instructions to perform the near field communication method of any one of claims 1-9.

39. A chip system, characterized by Comprise a processing circuit and an interface circuit, the interface circuit is configured to receive code instructions and transmit to the processing circuit, and the processing circuit is configured to run the code instructions to perform the near field communication method of any one of claims 10-15 or 16-30.