Search

CN-121979827-A - Smart card equipment management and instruction interaction method and device

CN121979827ACN 121979827 ACN121979827 ACN 121979827ACN-121979827-A

Abstract

The application provides a method and a device for managing intelligent card equipment and interacting instructions, and relates to the technical field of intelligent cards. The method comprises the steps of monitoring a USB device event reported by an operating system, starting an event merging process flow in response to the event, generating a trigger signal after the event merging process flow is merged within a preset time window, responding to the trigger signal, executing device discovery through a PC/SC interface to obtain a unique identifier of smart card equipment, updating an equipment resource table, applying for exclusive lock and obtaining persistent communication connection for target equipment after receiving a service request containing an APDU instruction, sequentially sending the APDU instruction and receiving a result through the persistent connection during the period of holding the exclusive lock, and releasing the exclusive lock and returning the result after completion. The application solves the problems of resource consumption and instantaneity of timing polling, avoids event storm through event merging processing, and ensures the correctness and efficiency of high concurrency service through exclusive lock and persistent connection.

Inventors

  • Lei Weiqi
  • XIA ZHENGGANG
  • JIANG BO
  • ZHAO CHENXI

Assignees

  • 上海雪球数智科技有限公司

Dates

Publication Date
20260505
Application Date
20260114

Claims (9)

  1. 1. A smart card device management and instruction interaction method, comprising: Monitoring and receiving a USB device event reported by an operating system, wherein the USB device event is associated with the physical connection state change of the intelligent card device; In response to receiving the USB device event, starting an event merging process flow, wherein the event merging process flow comprises the steps of continuously collecting subsequent USB device events in a preset waiting time window and generating an event processing trigger signal after the waiting time window is finished; Responding to the event processing trigger signal, and executing device discovery operation, wherein the device discovery operation comprises the steps of acquiring a currently connected smart card device list through a personal computer/smart card PC/SC protocol interface, and interacting with smart card devices in the list to acquire unique identifiers thereof; updating and maintaining a smart card device resource table available in a system based on the unique identifier; Receiving an external service request, wherein the service request designates target smart card equipment and comprises at least one Application Protocol Data Unit (APDU) instruction; applying for exclusive lock for the target smart card device, and establishing or acquiring persistent communication connection with the target smart card device; sequentially transmitting the at least one APDU instruction in the service request to the target smart card device and receiving the instruction execution result returned by the target smart card device through the persistent communication connection during the period of holding the exclusive lock And after the service request is completed, releasing the exclusive lock, and returning the instruction execution result.
  2. 2. The method of claim 1, wherein the initiating an event merge process flow specifically comprises: Storing the received USB device event into an event channel; starting or waking up an event consumption thread, wherein the event consumption thread waits for the end of the preset waiting time window after detecting that an event exists in the event channel; Inserting a custom termination mark event into the event channel after the waiting time window is finished, and And the event consuming thread sequentially consumes the events in the event channel until the termination mark event is read, and then triggers the event processing trigger signal.
  3. 3. The method according to claim 1, wherein the performing of the device discovery operation, interacting with the smart card device to obtain its unique identifier, is performed by sending specific application protocol data unit APDU instructions to the smart card device and parsing its response.
  4. 4. Method according to claim 1, characterized in that said establishing or obtaining a persistent communication connection with said target smart card device is in particular: When the system is initialized or the target smart card device is used for the first time, a logic connection is established with the target smart card device through a PC/SC protocol interface, and the logic connection is multiplexed in a subsequent service request.
  5. 5. The method according to claim 4, wherein the method further comprises: When an APDU command is transmitted through the persistent communication connection, if a connection abnormality is detected, a connection restoration operation is performed, including releasing an old logical connection and attempting to reestablish a new logical connection.
  6. 6. The method of claim 1, wherein said applying for exclusive locks for said target smart card device is performed by maintaining a exclusive lock associated with said unique identifier within the system to ensure that only one service request can access the target smart card device at a time.
  7. 7. A smart card device management and instruction interaction apparatus, comprising: The event monitoring module is used for monitoring and receiving USB equipment events reported by the operating system, wherein the USB equipment events are associated with the physical connection state change of the intelligent card equipment; The event processing module is used for responding to the received USB equipment event, and starting an event merging processing flow, wherein the event merging processing flow comprises the steps of continuously collecting the subsequent USB equipment event in a preset waiting time window and generating an event processing trigger signal after the waiting time window is ended; The device discovery module is used for responding to the event processing trigger signal and executing device discovery operation, wherein the device discovery operation comprises the steps of acquiring a currently connected smart card device list through a personal computer/smart card PC/SC protocol interface, and interacting with smart card devices in the list to acquire unique identifiers thereof; A resource management module for updating and maintaining a smart card device resource table available in a system based on the unique identifier; the request receiving module is used for receiving an external service request, wherein the service request designates target smart card equipment and comprises at least one Application Protocol Data Unit (APDU) instruction; The connection and lock management module is used for applying exclusive lock for the target intelligent card equipment and establishing or acquiring durable communication connection with the target intelligent card equipment; An instruction execution module for sequentially sending the at least one APDU instruction in the service request to the target smart card device and receiving the instruction execution result returned by the target smart card device through the persistent communication connection during the period of holding the exclusive lock, and And the result return module is used for releasing the exclusive lock after the service request is completed and returning the instruction execution result.
  8. 8. The apparatus of claim 7, wherein the event processing module is specifically configured to implement the event merge process flow, including configuring an event channel and an event consuming thread for inserting termination marker events and sequentially consuming events after the end of a latency window to trigger device discovery.
  9. 9. The apparatus of claim 7, wherein the connection and lock management module is further configured to perform a connection restoration operation when the instruction execution module detects an anomaly in the persistent communication connection, including releasing an old logical connection and attempting to reestablish a new logical connection.

Description

Smart card equipment management and instruction interaction method and device Technical Field The present application relates to the field of smart cards, and in particular, to a method and apparatus for managing smart card devices and interacting instructions. Background Smart card devices, particularly devices based on Universal Serial Bus (USB) interfaces and supporting the personal computer/smart card (PC/SC) protocol, are widely used in the fields of finance, identity authentication, etc. When interacting with such smart card devices, it is often necessary to send Application Protocol Data Unit (APDU) instructions over the PC/SC protocol interface to perform specific business operations. In practical applications, it is a basic premise to manage the connection status of these smart card devices. One common way of device management is for an application to periodically invoke functions provided by the PC/SC interface through timed tasks to scan and enumerate all currently connected smart card devices to discover newly inserted or extracted devices. However, the timing polling method has inherent defects that if the polling interval is set to be longer, the plugging event of the device cannot be timely sensed, so that the system state is updated and delayed, the user experience and the real-time property of the service are affected, and if the polling interval is set to be too short, the scanning operation is frequently executed, and a large amount of Central Processing Unit (CPU) resources are continuously consumed even if the state of the device is not changed, so that unnecessary performance waste is caused. Furthermore, a user may perform quick and repetitive plugging and unplugging in a short time while operating the USB device, which may generate dense device state change events, so-called "event storms". If the system immediately triggers a complete, possibly time-consuming, device discovery procedure for each event, the system load will rise dramatically and a large number of redundant calculations will be performed. Therefore, in the aspect of discovery and management of smart card devices, the prior art solution is difficult to consider real-time response and economy of system resources, and lacks an effective processing mechanism for abnormal events (such as event storm) in actual use scenarios. Disclosure of Invention The application mainly aims to provide a method and a device for managing intelligent card equipment and interacting instructions, and aims to solve the problem that resource consumption and instantaneity of the intelligent card equipment are difficult to be compatible through a timing polling mode in the prior art. In order to achieve the above object, the present application provides a smart card device management and instruction interaction method, including: Monitoring and receiving a USB device event reported by an operating system, wherein the USB device event is associated with the physical connection state change of the intelligent card device; In response to receiving the USB device event, starting an event merging process flow, wherein the event merging process flow comprises the steps of continuously collecting subsequent USB device events in a preset waiting time window and generating an event processing trigger signal after the waiting time window is finished; Responding to the event processing trigger signal, and executing device discovery operation, wherein the device discovery operation comprises the steps of acquiring a currently connected smart card device list through a personal computer/smart card PC/SC protocol interface, and interacting with smart card devices in the list to acquire unique identifiers thereof; updating and maintaining a smart card device resource table available in a system based on the unique identifier; Receiving an external service request, wherein the service request designates target smart card equipment and comprises at least one Application Protocol Data Unit (APDU) instruction; applying for exclusive lock for the target smart card device, and establishing or acquiring persistent communication connection with the target smart card device; sequentially transmitting the at least one APDU instruction in the service request to the target smart card device and receiving the instruction execution result returned by the target smart card device through the persistent communication connection during the period of holding the exclusive lock And after the service request is completed, releasing the exclusive lock, and returning the instruction execution result. Thus, by listening for USB device events instead of timing polling, a quick response to device state changes is achieved. Meanwhile, the event merging processing flow can effectively remove jitter, merge multiple equipment plugging events in a short time into one-time processing, avoid system resource waste caused by 'event storm', and realize balance of response instantaneity and resou