CN107784243B - Method and device for realizing communication of card reader equipment in android system - Google Patents

Method and device for realizing communication of card reader equipment in android system Download PDF

Info

Publication number
CN107784243B
CN107784243B CN201710944163.9A CN201710944163A CN107784243B CN 107784243 B CN107784243 B CN 107784243B CN 201710944163 A CN201710944163 A CN 201710944163A CN 107784243 B CN107784243 B CN 107784243B
Authority
CN
China
Prior art keywords
card reader
format
instruction
module
equipment
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710944163.9A
Other languages
Chinese (zh)
Other versions
CN107784243A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Feitian Technologies Co Ltd filed Critical Feitian Technologies Co Ltd
Priority to CN201710944163.9A priority Critical patent/CN107784243B/en
Publication of CN107784243A publication Critical patent/CN107784243A/en
Application granted granted Critical
Publication of CN107784243B publication Critical patent/CN107784243B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/0008General problems related to the reading of electronic memory record carriers, independent of its reading method, e.g. power transfer

Landscapes

  • Engineering & Computer Science (AREA)
  • Artificial Intelligence (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Telephonic Communication Services (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a method and a device for realizing communication of card reader equipment in an android system, and relates to the field of computers. The method comprises the following steps: when the communication module receives an instruction for searching for the card reader equipment sent by a user application, the instruction format for searching for the card reader equipment is converted, and then an instruction for acquiring the information of the card reader equipment is sent to a card reader equipment manager; when the communication module receives a power-on instruction for the card reader equipment, converting the format of the power-on instruction and then sending the power-on instruction to a card reader equipment manager, and analyzing response data returned by the card reader equipment to judge the card type; when the communication module receives the operation instruction, after the operation instruction format is converted, the communication module carries out protocol encapsulation on the operation instruction and then sends the operation instruction to the card reader equipment manager; according to the technical scheme, the communication of the card reader equipment can be realized in the android system, the development and maintenance cost is reduced, the development efficiency is improved, the use by a user is facilitated, and the user experience is better.

Description

Method and device for realizing communication of card reader equipment in android system
Technical Field
The invention relates to the field of computers, in particular to a method and a device for realizing communication of card reader equipment in an android system.
Background
The android system is a semi-open source operating system based on Linux and is mainly used for mobile equipment. The great advantage of the android system is the remarkable openness and rich hardware resources, so that the android system has more developers to research and use. The CCID (USB Chip/Smart Card Interface Devices-USB) protocol provides a possibility that the Smart Card read-write device and the host can realize mutual communication, and specifies that the CCID device is a Chip/Smart Card Interface device, the device is connected with the host through a USB Interface to carry out data communication conforming to the CCID protocol, and meanwhile, the device is communicated with the Smart Card through an Interface conforming to the 7816 standard protocol.
When operating a CCID type card reader device on the android system, there is no ready interface, the protocol can only be encapsulated and communicated according to some specific card reader devices and cards, and because the CCID protocol is complex, it is difficult to be compatible with all card reader devices and cards.
Disclosure of Invention
The invention aims to solve the technical problems in the prior art and provides a method and a device for realizing communication of card reader equipment in an android system.
The technical scheme adopted by the invention is as follows:
in one aspect, the present invention provides a method for implementing card reader device communication in an android system, including:
step S1: when the communication module receives an instruction for searching for the card reader sent by the user application, executing step S2; when the communication module receives a power-on instruction sent by the user application to the card reader, the power-on instruction format is converted, and then step S3 is executed; when the communication module receives the operation instruction sent by the user application, the step S4 is executed after the operation instruction format is converted;
step S2: the communication module acquires an equipment list and judges whether a preset equipment identifier can be acquired in the equipment list, if so, an instruction for acquiring information of the card reader equipment corresponding to the preset equipment identifier is sent to a card reader equipment manager, the card reader equipment manager performs format conversion on the instruction for acquiring the information of the card reader equipment, the instruction after format conversion is sent to the card reader equipment, after the card reader equipment manager receives the card reader information returned by the card reader equipment, the format of the converted card reader information is converted and sent to the communication module, the communication module analyzes the card reader information after format conversion, the format of the analyzed result is converted and returned to a user for application, and if not, an error is reported;
step S3: the communication module sends a power-on instruction to the card reader device manager, the card reader device manager converts the format of the power-on instruction and sends the converted format to the card reader device, the card reader device manager receives response data returned by the card reader device and converts the format of the response data and sends the converted format of the response data to the communication module, and the communication module analyzes the card type according to the response data, converts the format of a result of analyzing the card type and returns the result to a user for application;
step S4: the communication module carries out protocol encapsulation on the operation instruction and then sends the operation instruction to the card reader equipment manager, the card reader equipment manager converts the format of the operation instruction and then sends the operation instruction to the card reader equipment, the card reader equipment manager receives operation response data returned by the card reader equipment and then converts the format and sends the converted operation response data to the communication module, and the communication module carries out protocol unpacking and then converts the unpacked data into the format and returns the format to a user for application.
In another aspect, the present invention provides an apparatus for implementing card reader device communication in an android system, where the apparatus includes: a communication module and a card reader device manager;
the communication module specifically comprises:
the first receiving module is used for receiving an instruction sent by a user application and data returned by the card reader equipment manager;
the acquisition module is used for acquiring an equipment list when the first receiving module receives an instruction for searching for the card reader equipment sent by a user application;
the first judging module is used for judging whether a preset device identifier can be acquired from the device list acquired by the acquiring module;
the first sending module is used for sending an instruction for obtaining the information of the card reader equipment corresponding to the preset equipment identifier to the card reader equipment manager when the first judging module judges that the preset equipment identifier can be obtained in the equipment list; the analysis result after the format conversion of the first format conversion module is sent to the user application; the power-on instruction is used for sending a power-on instruction after the format conversion of the first format conversion module to the card reader equipment manager; the card type conversion module is used for converting the format of the card type into a first format conversion module; the card reader equipment manager is used for sending the operation instruction packaged by the packaging module to the card reader equipment manager; the data processing module is used for returning the unpacked data after the format conversion of the first format conversion module to the user application;
the first analysis module is used for analyzing the card reader equipment information after format conversion when the data returned by the card reader equipment manager received by the first receiving module is the card reader information after format conversion;
the first format conversion module is used for converting the format of the analysis result obtained by the first analysis module; the first receiving module is used for converting the format of a power-on instruction when receiving the power-on instruction sent by a user application to the card reader equipment; the first receiving module is used for converting the format of an operation instruction when the first receiving module receives the operation instruction sent by the user application; the card type conversion module is used for converting the result of the card type obtained by the analysis of the second analysis module into a format; the data conversion module is also used for converting the format of the unpacked data;
the second analysis module is used for analyzing the card type according to the response data after the format conversion to obtain a card type result when the first receiving module receives the response data after the format conversion;
the packaging module is used for carrying out protocol packaging on the operation instruction after the format conversion of the first format conversion module;
the unpacking module is used for unpacking the protocol when the first receiving module receives the operation response data after the format conversion;
card reader equipment manager specifically includes:
the second receiving module is used for receiving the instruction sent by the communication module and the response returned by the card reader equipment;
the second format conversion module is used for converting the format of the instruction which is sent by the first sending module and used for acquiring the information of the card reader equipment corresponding to the preset equipment identifier; the format conversion module is used for converting the format of the card reader equipment information received by the second receiving module and returned by the card reader equipment; the power-on instruction conversion module is used for converting the format of the power-on instruction received by the second receiving module; the format conversion module is used for converting the response data received by the second receiving module and returned by the card reader equipment and then converting the format; the second receiving module is also used for converting the format of the operation instruction after receiving the packaged operation instruction; the second receiving module is used for converting the format after receiving operation response data returned by the card reader equipment;
the second sending module is used for sending the instruction for acquiring the information of the card reader equipment after the format is converted by the second format conversion module to the card reader equipment; the card reader equipment information after the format conversion of the second format conversion module is sent to the communication module; the power-on instruction is used for sending the power-on instruction after the format conversion of the second format conversion module to the card reader equipment; the response data after the format conversion of the second format conversion module is sent to the communication module; the operation instruction after the format conversion of the second format conversion module is sent to the card reader equipment; and the operation response data after the format conversion of the second format conversion module is sent to the communication module.
The beneficial effects obtained by the invention are as follows:
by adopting the technical scheme of the invention, the communication of the card reader equipment can be realized in the android system, the communication of the card reader equipment of all CCID types can be compatible, the development and maintenance cost is reduced, the development efficiency is improved, the use by a user is facilitated, and the user experience is better.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flowchart of a method for implementing communication of a card reader device in an android system according to a second embodiment of the present invention;
fig. 2 is a schematic diagram of an apparatus for implementing communication of a card reader device in an android system according to a third embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
The embodiment provides a method for realizing communication of a card reader device in an android system, which comprises the following steps:
step S1: when the communication module receives an instruction for searching for the card reader sent by the user application, executing step S2; when the communication module receives a power-on instruction sent by the user application to the card reader, the power-on instruction format is converted, and then step S3 is executed; when the communication module receives the operation instruction sent by the user application, the step S4 is executed after the operation instruction format is converted;
step S2: the communication module acquires an equipment list and judges whether a preset equipment identifier can be acquired in the equipment list, if so, an instruction for acquiring information of the card reader equipment corresponding to the preset equipment identifier is sent to a card reader equipment manager, the card reader equipment manager performs format conversion on the instruction for acquiring the information of the card reader equipment, the instruction after format conversion is sent to the card reader equipment, after the card reader equipment manager receives the card reader information returned by the card reader equipment, the format of the converted card reader information is converted and sent to the communication module, the communication module analyzes the card reader information after format conversion, the format of the analyzed result is converted and returned to a user for application, and if not, an error is reported;
step S3: the communication module sends a power-on instruction to the card reader device manager, the card reader device manager converts the format of the power-on instruction and sends the converted format to the card reader device, the card reader device manager receives response data returned by the card reader device and converts the format of the response data and sends the converted format of the response data to the communication module, and the communication module analyzes the card type according to the response data, converts the format of a result of analyzing the card type and returns the result to a user for application;
step S4: the communication module carries out protocol encapsulation on the operation instruction and then sends the operation instruction to the card reader equipment manager, the card reader equipment manager converts the format of the operation instruction and then sends the operation instruction to the card reader equipment, the card reader equipment manager receives operation response data returned by the card reader equipment and then converts the format and sends the converted operation response data to the communication module, and the communication module carries out protocol unpacking and then converts the unpacked data into the format and returns the format to a user for application.
In this embodiment, the format of the instruction for converting power-on specifically includes: the communication module converts the format of the power-on instruction into a character string;
converting the format of the operation instruction, specifically: the communication module converts the format of the operation instruction into a character string;
the card reader equipment manager performs format conversion on the instruction for acquiring the card reader equipment information, and specifically comprises the following steps: the card reader equipment manager converts the format of the instruction for acquiring the card reader equipment information into a binary system;
converting the information format of the card reader specifically comprises the following steps: the card reader equipment manager converts the format of the card reader information into a character string;
converting the format of the analysis result, specifically: the communication module converts the format of the analysis result into a binary system;
the card reader equipment manager converts the power-on command into a format, specifically: the card reader equipment manager converts the format of the power-on instruction into a binary system;
the card reader equipment manager converts the format after receiving the response data returned by the card reader equipment, and specifically comprises the following steps: after receiving response data returned by the card reader equipment, the card reader equipment manager converts the format of the response data into a character string;
converting the format of the result of analyzing the card type, specifically: the communication module converts the format of the result of analyzing the card type into a binary system;
the card reader equipment manager converts the format of the operation instruction, and specifically comprises the following steps: the card reader equipment converts the format of the operation instruction into a binary system;
the card reader equipment manager converts the format after receiving the response data returned by the card reader equipment, and specifically comprises the following steps: after receiving response data returned by the card reader equipment, the card reader equipment manager converts the format of the response data returned by the card reader equipment into a character string;
converting the format of the unpacked data, specifically: and the communication module converts the format of the unpacked data into a binary system.
In this embodiment, the communication module obtains the device list, specifically: and the communication module sends an instruction for acquiring the equipment list to the card reader equipment manager and receives the equipment list returned by the card reader equipment manager.
Further comprising: after receiving the instruction for acquiring the device list, the card reader device manager calls a UsbManager.
Or,
call bluetooth adapter.
Specifically, the communication module acquires the device list and determines whether the preset device identifier can be acquired in the device list, specifically:
and traversing the equipment list after the communication module acquires the equipment list, judging whether the preset equipment identifier can be acquired in the equipment list, if so, sending an instruction for acquiring the information of the card reader equipment corresponding to the preset equipment identifier to the card reader equipment manager, and otherwise, reporting an error.
In this embodiment, the instruction after format conversion is sent to the card reader device, specifically: the card reader device manager calls a UsbDeviceConnection.controlTransfer system function to send a command of converting the format to the card reader device; and after receiving the instruction, the card reader equipment calls a UsbDeviceConnection.
Preferably, in step S3, the card reader device manager converts the format of the power-on command and sends the converted power-on command to the card reader device, specifically:
the card reader equipment manager calls a UsbDeviceConnection. bulk transfer system function to send a power-on instruction to the card reader equipment; sending the response data after format conversion to a communication module, specifically: the card reader device manager calls a UsbDeviceConnection. bulk transfer system function to send response data after format conversion to the communication module;
or,
the card reader equipment manager calls a writecard feature system function to send a power-on instruction to the card reader equipment; sending the response data after format conversion to a communication module, specifically: and the card reader device manager calls a readcharateristic system function to send the response data after format conversion to the communication module.
Preferably, before the communication module parses the card type according to the response data in step S3, the method further includes: the communication module judges whether a card exists according to response data returned by the card reader equipment manager, if so, the communication module analyzes the card type according to the response data, and if not, an error is reported.
In this embodiment, before the communication module analyzes the card type according to the response in step S3, the communication module further determines whether the card reader can accelerate, and if so, sends an instruction for accelerating the card reader to the card reader device manager, and if not, the communication module directly analyzes the card information according to the response.
Wherein, send the instruction of card reader acceleration to card reader equipment manager, specifically do: the communication module calls a UsbDeviceConnection. bulk transfer system function to send a speed-up instruction to the card reader device.
In this embodiment, the determining, by the communication module, whether the card reader device can speed up specifically includes: the communication module judges whether the card reader equipment can accelerate according to the information whether the card reader equipment supports acceleration contained in the descriptor in the card reader information, and if the descriptor contains the information that the card reader equipment supports acceleration, the card reader equipment can accelerate; if the descriptor contains information that the card reader device does not support speed increasing, the card reader device cannot speed up.
Preferably, in step S3, the card type is analyzed, specifically: the communication module analyzes the type of the card according to the information of the card type in the response data.
The communication module analyzes the type of the card according to the information of the card type in the response data, and specifically comprises the following steps: the communication module analyzes the type of the card based on the state information specific to the T0 protocol and the state information specific to the T1 protocol in the response data.
Specifically, step S4 is preceded by: and the communication module analyzes the exchange protocol type supported by the card reader according to the information of the card reader.
Further, in step S4, the communication module performs protocol encapsulation on the operation instruction, specifically: and the communication module carries out protocol encapsulation on the operation instruction according to the card type and the exchange protocol supported by the card reader.
Preferably, step S1 further includes: when the communication module receives an instruction for starting the card reader service sent by the user application, the communication module executes the step S0 after converting the format of the instruction for starting the card reader service; when the communication module receives a power-off instruction sent by the user application to the card reader, the power-off instruction format is converted, and then the step S5 is executed; when the communication module receives an instruction for stopping the card reader service sent by the user application, the communication module executes the step S6 after converting the format of the instruction for stopping the card reader service;
step S0: the communication module starts the card reader service and returns corresponding state information to the user application;
step S5: the communication module sends a power-off instruction to the card reader device manager, the card reader device manager converts the format of the power-on instruction and sends the converted format to the card reader device, the card reader device manager receives response data returned by the card reader device and converts the format of the response data and sends the converted format of the response data to the communication module, and the communication module converts the format of the format-converted response data and returns the converted format of the response data to the user for application;
step S6: the communication module stops the card reader service and returns corresponding state information to the user application.
In step S0, the corresponding status information specifically includes: information of success or failure of the card reader service opening; the corresponding status information in step S6 is specifically: the card reader service stops the success or failure information.
Example two
In this embodiment, both the communication module and the card reader device manager are the inventions of this patent. In this embodiment, the card reader device may be a USB card reader device, or may be a bluetooth card reader device; correspondingly, the card reader device manager can be a USB card reader device manager or a Bluetooth card reader device manager.
The embodiment provides a method for realizing communication of a card reader device in an android system, as shown in fig. 1, including:
step 101: the communication module waits for receiving an instruction from a user application, and when the instruction for starting the card reader equipment service from the user application is received, the instruction format for starting the card reader equipment service is converted to execute step 102; when receiving an instruction for acquiring a device list from a user application, converting the instruction format of the acquired device list to execute step 103; when a power-on instruction from a user application is received, converting the power-on instruction format to execute step 106; when receiving an operation instruction from a user application, converting the format of the operation instruction to execute step 111; when a power-down instruction from a user application is received, converting the power-down instruction format to execute step 114; when receiving an instruction for stopping the card reader device service from the user application, converting the format of the instruction for stopping the card reader device service to execute step 116;
in this embodiment, the command sent by the user application is in a binary format, and the communication module converts the received command into a format of a character string.
Step 102: the communication module starts the service of the card reader equipment by using exec, returns the state information to the user application and returns to the step 101;
in this embodiment, when the scardrestablecontext function in the user application is called, the user application sends a start instruction to the communication module, the communication module receives the start instruction and returns corresponding state information to the user application, the user application returns the corresponding state information to the application program by calling the scardrestablecontext function, the application program judges whether the USB card reader device is successfully started according to the state information, if so, the step 101 is returned, otherwise, the error information is returned.
Step 103: after converting the instruction format of the device list, the communication module sends an instruction for acquiring the device list to the card reader device manager;
in this embodiment, when the scardlist reads function in the user application is called, the user application sends an instruction to the communication module to obtain the device list. And after receiving the instruction for acquiring the equipment list, the communication module converts the instruction format of the equipment list into a character string format, and calls a sendUsb function to send the instruction for acquiring the equipment list to the card reader equipment manager.
When the card reader device manager is a USB card reader device manager, after receiving an instruction for acquiring the device list, the USB card reader device manager calls a Utibmanager.getDeviceList function to convert the instruction for acquiring the device list sent by the communication module into a binary format, after the conversion is successful, the UsbManager.getDeviceList function is called to send the instruction for acquiring the device list to the USB card reader device, after the USB card reader device returns the device list, the card reader device manager calls a Utib.by2HexStr function to convert data returned by the USB card reader device into a character string format and sends the character string format to the communication module, and after the communication module converts the received device list into a binary format, the communication module calls a recvUsb function to return the device list to the communication module.
Wherein, both the sendUsb function and the recUsb function are self-defined functions of developers.
Specifically, the device list includes a large amount of information, including a Vendor ID (VID), a manufacturer ID (PID), and a name of the USB card reader device.
When the card reader device manager is a Bluetooth card reader device manager, the Bluetooth card reader device manager receives the instruction and calls Bluetooth adapter LeScanCallback () to search surrounding Bluetooth devices and calls a recUsb function to return a device list to the communication module.
Preferably, the communication module supports the CCID protocol.
Step 104: after the communication module receives the device list returned by the card reader device manager, the communication module acquires the device list and judges whether a preset device identifier can be acquired in the device list, if so, the step 105 is executed, otherwise, the step 101 is returned;
in this embodiment, when the card reader device is a USB card reader device, and the communication module receives a device list returned by the USB card reader device manager, the communication module traverses the device list, and screens out a USB card reader device that meets the condition through a preset device identifier.
Wherein the preset device identifier comprises: vendor ID (VID for short), manufacturer ID (PID for short), and USB card reader device name.
For example, the communication module sends "8006000100004000" to the card reader device manager for obtaining vendor ID and manufacturer ID information; the communication module sends '8006 XX030904XX 00', '8006 XX030904XX 00' to the card reader device manager to acquire 'iMan factor' and 'iProduct', wherein the two names of 'iMan factor' and 'iProduct' are connected to form a USB card reader device name.
In this embodiment, if the communication module finds a USB card reader device that meets the condition, it calls a musbmanager. After the USB card reader equipment receives the application, the application program can display a dialog box to inquire whether the USB card reader equipment agrees to control or not, and after the user agrees, the communication module calls an mlintf.getEndpoint (i.getAddress function) to obtain a communication endpoint of the USB card reader equipment to prepare for communication between the communication module and the USB card reader equipment later. And calling a function mUsbManger.
In this embodiment, if the communication module does not find a USB card reader device that meets the condition, the communication module directly returns corresponding status information to the user application. And after the user application receives the state information sent by the communication module, calling a SCRardListReaders function to return the state information to the application program.
Further, when the communication module does not find the USB card reader device meeting the condition, the state information at this time is a state code indicating that the USB card reader device does not meet the condition, and the application program can determine the reason for the USB card reader device not meeting the condition according to the state code, where the reason for the USB card reader device not meeting the condition may include: the USB card reader device is not inserted, the USB card reader device is not inserted well, and the USB card reader device has problems. After receiving the state information, the user performs a series of operations according to the specific state.
When the card reader equipment is Bluetooth card reader equipment, the communication module receives an equipment list returned by the Bluetooth card reader equipment manager, and traverses the equipment list, and selects the Bluetooth card reader equipment meeting the conditions through a preset equipment identifier.
Wherein the preset device identifier comprises: a bluetooth card reader device name and a bluetooth card reader device address.
More specifically, the communication module may screen the devices that meet the conditions according to actual conditions. Getname if only the bluetooth card reader device with the specified name is selected; getaddress if only selecting the bluetooth card reader device with the designated bluetooth address; if both the name and the bluetooth address are specified, the functions device.
In this embodiment, if the communication module finds a bluetooth card reader device meeting the condition, it calls a musbmanager. After the Bluetooth card reader equipment receives the application, the application program can display a dialog box to inquire whether the Bluetooth card reader equipment is agreed to be controlled or not, and after the agreed instruction transmitted by the application program, the communication module calls a device.
In this embodiment, if the communication module does not find a bluetooth card reader device that meets the condition, the communication module directly returns corresponding status information to the user application. And after the user application receives the state information sent by the communication module, calling a SCRardListReaders function to return the state information to the application program.
Further, when the communication module does not find the eligible bluetooth card reader device, the state information at this time is the state code indicating that the eligible bluetooth card reader device is not available, and the application program can judge the reason of the ineligible bluetooth card reader device according to the state code. For example, reasons for a non-qualified bluetooth card reader device may include: the bluetooth card reader equipment does not insert, and bluetooth card reader equipment self has the problem. After receiving the state information, the user performs a series of operations according to the specific state.
Step 105: the communication module sends an instruction for acquiring descriptor information of the card reader device to a card reader device manager, the card reader device manager performs format conversion on the instruction for acquiring the descriptor information of the card reader device, the instruction after format conversion is sent to the card reader device, the data format is converted and sent to the communication module after the card reader device manager receives the descriptor information returned by the card reader device, the communication module acquires and analyzes the descriptor information of the card reader device, the analysis result is converted into the format and then returned to the user application, and the step 101 is returned;
in this embodiment, the communication module calls the sendUsb function to send an instruction for obtaining the descriptor of the card reader device to the card reader device manager, the card reader device manager receives the instruction and then calls the utility. Control transfer function is called to send the instruction of obtaining the descriptor information of the card reader device after the format conversion to the card reader device, after the card reader device receives the instruction, control transfer function returns descriptor information to the card reader device manager, and after the card reader device manager receives the descriptor information returned by the card reader device, the utility. byte2hexstr function is called to convert the format of the descriptor information returned by the card reader equipment, after the descriptor information is converted into a character string, and the card reader equipment manager calls a recvUsb function to return the card reader equipment descriptor information after format conversion to the communication module.
For example, in this embodiment, the communication module calls the sendUsb function to send "usb _ ctl: 8006000100004000' instruction is used for acquiring a device descriptor, an interface descriptor and a ccid descriptor, wherein the ccid descriptor can analyze the ccid protocol type, the transmission speed, the number of card slots and the like supported by the current card reader device; calling the sendUsb function sends "usb _ ctl: a103000000000004 "is used to obtain the data transmission rate.
In this embodiment, after the communication module acquires the descriptor information of the card reader device, the acquired information and the status code representing that the card reader device is present are returned to the user application, and the user application calls the scardlists reader function to return the status information to the application program.
Step 106: the communication module sends a power-on instruction to the card reader device manager;
in this embodiment, when the SCardConnect function is called by the user application, the user application sends a power-on instruction to the communication module, when the card reader device is a USB card reader device, the communication module calls a sendUsb function to send the power-on instruction to the card reader device manager, after receiving the power-on instruction, the card reader device manager calls a property. And if the instruction fails to be sent, the card reader equipment manager returns a message of failure in instruction sending to the communication module.
Specifically, when the card reader device is a USB card reader device, the USB card reader device returns information of some cards after receiving a power-on instruction, the USB card reader device manager calls an mconnection. bulk transfer function to receive data returned by the USB card reader device, then calls a utility. byte2hexstr function to convert the data returned by the USB card reader device into a character string, and after the conversion is successful, calls a recvUsb function to return the formatted data to the communication module.
More specifically, the information of the card refers to the presence or absence of the card and other related information.
For example, in the present embodiment, the communication module transmits "usb _ find: 6100000000XX 00000000' instructs to power on the card of the USB card reader device, wherein XX is the card slot serial number.
In this embodiment, when the SCardConnect function is called by the user application, the user application sends a power-on instruction to the communication module, when the card reader device is a bluetooth card reader device, the communication module calls the sendUsb function to send the power-on instruction to the bluetooth card reader device manager, after receiving the power-on instruction, the bluetooth card reader device manager calls the performance. And if the instruction fails to be sent, the Bluetooth card reader equipment manager returns a message of failure in instruction sending to the communication module.
Specifically, after receiving a power-on command, the bluetooth card reader device returns some card information, the bluetooth card reader device manager calls an mconnection. bulktransfer function to receive data returned by the bluetooth card reader device, then calls a utility. byte2hexstr function to convert the data returned by the bluetooth card reader device into a character string, and after the conversion is successful, calls a recvUsb function to return the data converted into the character string to the communication module.
Step 107: the communication module receives and analyzes information returned by the card reader device manager, whether a card is inserted is judged, if yes, step 108 is executed, and if not, step 101 is executed;
in this embodiment, the communication module determines whether a card is present on the card reader device by analyzing card information returned by the card reader device.
For example, if the information returned by the card reader device is "80000000000000 XXYY 00", then there is no card on the card reader device, where XXYY is the error code; if the returned information is '80 xxxxxxxx0000000000+ ATR', the card reader device has a card, wherein xxxxxxxx is the data length of ATR, and the card belongs to the activated state.
For example, the data returned when a card is present on the card reader device is:
“80 09 00 00 00 00 25 00 00 00 3b 91 13 81 31 80 9f 10 0d”
it should be noted that ATR (abbreviation of Answer-to-Reset) includes two parts, an interface character and a history character. In the present embodiment, the interface character is mainly referred to. The interface characters comprise information of clocks of the card and the USB card reader device, baud rate, the mode of the current card, state characters specific to T0 and T1 protocols and the like.
It should be noted that the communication module distinguishes the card types according to the state symbols specific to the T0 and T1 protocols.
Step 108: the communication module judges whether the card reader equipment can accelerate, if so, step 109 is executed, otherwise, step 110 is executed;
specifically, the card reader device returns an ATR that contains a detailed description of the card, including information regarding whether the card supports acceleration.
It should be noted that the ccid descriptor of the card reader device is obtained to include information about whether the card reader device supports speed increase and a range of speed values, and the ATR includes information about whether speed increase has been performed, suggested speed values, and the like.
Step 109: the communication module sends an instruction of accelerating the card reader equipment to the card reader equipment manager, the card reader equipment manager converts the format and then sends the acceleration instruction after the format conversion to the card reader equipment, and the card reader equipment manager receives response data returned by the card reader equipment and then sends the response data converted format to the communication module;
in this embodiment, when the card reader device is a USB card reader device, the communication module calls the sendUsb function to send an instruction for speeding up the USB card reader device to the card reader device manager, the card reader device manager receives the instruction and then calls the utility. A USB card reader device is called to send a format-converted speed-up instruction to a USB card reader device, the USB card reader device needs to judge whether the USB card reader device can accelerate or not after receiving the speed-up instruction, if not, an error message is returned to the card reader device manager, if possible, acceleration is performed, meanwhile, returning a response of successful acceleration, after the card reader device manager receives the response returned by the USB card reader device, and calling a Utility.byte2HexStr function to convert the format of the descriptor information returned by the USB card reader equipment, converting the descriptor information into a character string, and calling a recUsb function to return to the communication module.
In this embodiment, after receiving the speed-up command sent by the communication module, the card reader device manager converts the command format. Specifically, the instruction is in a string format, and the card reader device manager converts the format of the instruction into a binary format.
In this embodiment, when the card reader device is a bluetooth card reader device, the communication module calls a sendUsb function to send an instruction for accelerating the speed of the bluetooth card reader device to a bluetooth card reader device manager, the bluetooth card reader device manager receives the instruction and then converts the format of the instruction, calls writecharateristic and readcharateristic functions to send the speed-up instruction after converting the format to the bluetooth card reader device, the bluetooth card reader device needs to judge whether the bluetooth card reader device can accelerate itself after receiving the speed-up instruction, if not, returns error information to the bluetooth card reader device manager, if yes, accelerates and simultaneously returns a response that the acceleration is successful, and the bluetooth card reader device manager receives the response returned by the bluetooth card reader device and then converts the response format, and calls a recvUsb function to return the response after converting the format to the communication module.
Further, the communication module transmits data "6 fxxxxxxx 0000000000+ pps" for acceleration, where xx is the length of pps and pps is the data combined according to the ATR. Wherein pps (protocol and parameters selection) means: protocol and parameter selection.
Furthermore, if the card reader device and the card support the speed increase, corresponding data of the speed increase of the card reader device is sent, the card reader device transmits the data to the card, and through the process, the card reader device and the card are both increased to the corresponding speed.
Step 110: after the communication module analyzes the card type, the card state information is converted into a format and then is sent to the user application;
in the present embodiment, the communication module resolves whether the card type is T0 card or T1 card according to the state characters specific to the T0 and T1 protocols in the ATR.
In this step, the communication module returns the status information of the card on the card reader device to the user application. After receiving the state code, the user application calls the SCRArdConnect function to send the state code to the user application, after receiving the state information sent by the communication module, the user application needs to judge whether a card exists on the USB card reader equipment according to the state information, if the card exists, the step 101 is returned, and if the card does not exist, an error is reported to the application program.
Step 111: the communication module analyzes the exchange protocol type supported by the card reader equipment according to the descriptor information of the card reader equipment;
in this embodiment, the exchange protocol type is specifically defined in the descriptor information of the card reader device, and there are generally three types of exchange protocol types supported by the card reader device: TPDU, Short APDU and Short and ExtendedAPDU.
Step 112: the communication module carries out protocol encapsulation on the operation instruction according to the card type and an exchange protocol supported by the card reader equipment, and sends the encapsulated operation instruction to the card reader equipment manager;
in this embodiment, when the card reader device is a USB card reader device, when the SCardTransmit function is called by an application program, the application program sends an operation instruction to the communication module, the communication module performs protocol encapsulation after receiving an instruction sent by a user application, then calls a sendUsb function to send a protocol encapsulated instruction to the card reader device manager, the card reader device manager receives the encapsulated instruction and then calls a usbdviceconnection.
In this embodiment, when the card reader device is a bluetooth card reader device, when the SCardTransmit function is called by an application program, the application program sends an operation instruction to the communication module, the communication module performs protocol encapsulation after receiving an instruction sent by a user application, and then calls a sendUsb function to send the instruction of the protocol encapsulation to the bluetooth card reader device manager, the bluetooth card reader device manager receives the instruction and then calls writehardharacteristic and readcharacterictic functions to send the instruction after encapsulation to the bluetooth card reader device, the bluetooth card reader device returns data to the bluetooth card reader device manager after executing the instruction, and the bluetooth card reader device manager converts a data format and then calls a recvUsb function to return information after the bluetooth card reader device converts the data format to the communication module.
In this embodiment, the application calls the API to send an operation instruction to the communication module. The protocols used are the 7816 protocol and the CCID protocol.
For example, the application program sends an instruction to the USB card reader device to obtain a string of random numbers by calling the interface API: "0084000008".
For a smart card supporting the T1 protocol, atr is "800 a 00000000000000003 b e 100008131 fe 4510 ca", and the transmission data is "0084000008".
If the card reader device supports the exchange protocol type of "Short APDU", the sending data is "6 f 0500000000250000000084000008";
if the card reader device supports an exchange protocol type of "TPDU", the transmission data is "6 f 090000000052000000000005008400000889".
Step 113: the card reader device manager carries out format conversion after receiving the instruction, sends the converted format to the card reader device, and after receiving the data returned by the card reader device manager, the communication module carries out protocol unpacking on the received data, converts the format of the card response data and returns the card response data to the user for application;
this step is followed by: the user application calls the SCardTransmit function to send the card response data to the application. If the application program continues to send the relevant operation instruction, the step 112 is returned, otherwise, the step 114 is executed.
Step 114: the communication module sends a power-off instruction of the card reader equipment to the card reader equipment manager;
in this embodiment, when the card reader device is a USB card reader device, when the SCardConnect function is called by a user application, the user application sends a power-down instruction to the communication module, the communication module calls a sendUsb function to send the power-down instruction to the card reader device manager, after receiving the power-down instruction, the card reader device manager calls a performance. And if the instruction fails to be sent, the card reader equipment manager returns a message of failure in instruction sending to the communication module.
In this embodiment, when the card reader device is a bluetooth card reader device, the user invokes a scardsconnect function applied by the user to send a power-down request to the bluetooth card reader device to the USB card reader device, the communication module invokes a USB _ send instruction of a sendUsb function to send a power-down request to the bluetooth card reader device to the card reader device manager, and after receiving the power-down request, the card reader device manager invokes writecharateristic and readcharateristic functions to power down the bluetooth card reader device, and returns a message indicating whether the power-down of the bluetooth card reader device is successful or not to the communication module through the recvUsb function.
Step 115: the communication module obtains the card reader equipment state information returned by the card reader equipment manager, then carries out format conversion and returns the card reader equipment state information to the user application;
in this step, the status information of the card reader device at this time refers to the status of whether power-down was successful or not.
Step 116: the communication module uses destroy to stop the card reader device service and returns corresponding status information to the user application.
In this embodiment, the user invokes the scardrreleasecontext function in the user application to send a termination instruction to the communication module, and after receiving the instruction sent by the user application, the communication module stops the card reader device service by using destroy, and returns the status code to the user application. The user application returns the corresponding status code to the user by calling the scardrestablecontext function.
EXAMPLE III
This embodiment provides a device that realizes card reader equipment communication in tall and erect system of ann, its characterized in that, the device includes: a communication module and a card reader device manager.
The communication module specifically comprises:
the first receiving module 301 is configured to receive an instruction sent by a user application and data returned by a card reader device manager;
an obtaining module 302, configured to obtain a device list when the first receiving module 301 receives an instruction for searching for a card reader device sent by a user application;
a first determining module 303, configured to determine whether a preset device identifier may be obtained in the device list obtained by the obtaining module 302;
a first sending module 304, configured to send, to the card reader device manager, an instruction to obtain information of the card reader device corresponding to the preset device identifier when the first determining module 303 determines that the preset device identifier may be obtained in the device list; the first format conversion module 306 is used for sending the analysis result after the format conversion to the user application; the power-on instruction is used for sending a power-on instruction after the format is converted by the first format conversion module 306 to the card reader device manager; the card type conversion module is used for returning the result of the card type converted by the first conversion format module 306 to the user application; the operation instruction packaged by the packaging module 308 is sent to the card reader device manager; the data processing module is used for returning the unpacked data converted by the first format conversion module 306 to the user application;
the first analyzing module 305 is configured to analyze the card reader device information after format conversion when the data returned by the card reader device manager and received by the first receiving module 301 is the card reader information after format conversion;
a first format conversion module 306, configured to convert the format of the analysis result obtained by the first analysis module 305; the first receiving module 301 is configured to convert a power-on instruction format when receiving a power-on instruction sent by a user application to the card reader device; the first receiving module 301 is used for converting the format of the operation instruction when receiving the operation instruction sent by the user application; a result for converting the card type analyzed by the second analysis module 307 into a format; the data conversion module is also used for converting the format of the unpacked data of the unpacking module 309;
the second parsing module 307, configured to, when the first receiving module 301 receives the response data after format conversion, parse the card type according to the response data after format conversion to obtain a result of the card type;
an encapsulating module 308, configured to perform protocol encapsulation on the operation instruction after the format conversion by the first format conversion module 306;
an unpacking module 309, configured to perform protocol unpacking when the first receiving module 301 receives the operation response data after format conversion;
card reader equipment manager specifically includes:
the second receiving module 401 is configured to receive an instruction sent by the communication module and a response returned by the card reader device;
a second format conversion module 402, configured to perform format conversion on the instruction, which is sent by the first sending module 304 and is used to acquire information of the card reader device corresponding to the preset device identifier; the second receiving module 401 is configured to convert the format of the card reader device information returned by the card reader device; for converting the format of the power-on instruction received by the second receiving module 401; the second receiving module 401 is configured to convert the format of the response data received by the second receiving module 401 and returned by the card reader device; the second receiving module 401 is further configured to convert the format of the operation instruction after receiving the packaged operation instruction; the second receiving module 401 is configured to convert the format after receiving operation response data returned by the card reader device;
a second sending module 403, configured to send the instruction for obtaining the information of the card reader device after the format conversion by the second format conversion module 402 to the card reader device; the card reader equipment information after the format conversion by the second format conversion module 402 is sent to the communication module; the power-on instruction is used for sending the power-on instruction after the format conversion by the second format conversion module 402 to the card reader device; the response data is used for sending the response data after the format conversion by the second format conversion module 402 to the communication module; the operation instruction is used for sending the operation instruction after the format conversion by the second format conversion module 402 to the card reader device; for sending the operation response data converted by the second format conversion module 402 to the communication module.
Specifically, the first conversion format module 306 includes: a first conversion format unit and a second conversion format unit;
the first conversion format unit is used for converting the format of the power-on instruction into a character string; the device is also used for converting the format of the operation instruction into a character string;
the second format conversion unit is used for converting the format of the analysis result into a binary system; the format of the result for analyzing the card type is converted into binary; the data processing device is also used for converting the format of the unpacked data into a binary system;
the second conversion format module 402 includes: a third conversion format unit and a fourth conversion format unit;
the third format conversion unit is used for converting the format of the card reader equipment information into a character string; for converting the format of the response data into a character string; the operation response data processing device is also used for converting the format of the operation response data returned by the card reader device into a character string;
the fourth format conversion unit is used for converting the format of the instruction for acquiring the information of the card reader equipment into a binary system; the power-on instruction processing device is used for converting the format of the power-on instruction into a binary system; and is also used for converting the format of the operation instruction into binary.
In this embodiment, the obtaining module 302 includes: a first transmitting unit and a first receiving unit;
the first sending unit is used for sending an instruction for acquiring the equipment list to the card reader equipment manager;
and the first receiving unit is used for receiving the equipment list returned by the card reader equipment manager.
Preferably, the apparatus further comprises a calling module;
a calling module, configured to, after the second receiving module 401 receives the instruction to obtain the device list, call a usbmanager.
Or,
LeScanCallback system function is called to send an instruction to the card reader device to obtain a device list.
Specifically, the first determining module 303 further includes: a traversing unit;
a traversal unit, configured to traverse the device list after the obtaining module 302 obtains the device list.
In this embodiment, the second sending module 403 includes a first calling unit;
a first calling unit, configured to call a usbdviceconnection.
Specifically, the second sending module 403 further includes a second calling unit;
a second calling unit, configured to call a usbdviceconnection. bulk transfer system function to send a power-on instruction to the card reader device; the function of the UsbDeviceConnection. bulk transfer system is also used for calling the UsbDeviceConnection. bulk transfer system function to send the response data after format conversion to the communication module; or, the function is used for calling the writecard feature system function to send a power-on instruction to the card reader device; and the function is also used for calling a readcharateristic system function to send the response data after format conversion to the communication module.
Preferably, the device further comprises a second judgment module;
the second judging module is used for judging whether a card exists according to response data returned by the card reader equipment manager of the first receiving module 301;
the second analyzing module 307 is specifically configured to analyze the card type according to the response data when the second determining module determines that the card exists.
Furthermore, the device also comprises a third judgment module;
the third judgment module is used for judging whether the card reader equipment can accelerate;
the first sending module 304 is further configured to send an instruction of speeding up the card reader device to the card reader device manager when the third determining module determines that the card reader device can speed up;
the second analyzing module 307 is further configured to analyze the card information directly according to the response when the third determining module determines that the card reader device cannot speed up.
Specifically, the first sending module 304 further includes a third invoking unit;
and the third calling unit is used for calling the UsbDeviceConnection. bulk transfer system function to send a speed-up instruction to the card reader device manager.
More specifically, the third determining module is specifically configured to determine whether the card reader device can accelerate according to information about whether the card reader device supports acceleration included in the descriptor in the card reader device information;
the first sending module 304 is configured to send an instruction of speeding up the card reader device to the card reader device manager when the third determining module determines that the descriptor includes information that the card reader device supports speeding up.
Further, the second parsing module 307 is specifically configured to parse the type of the card according to the information of the card type in the response data.
Further, the second parsing module 307 is specifically configured to parse the type of the card in response to the status information specific to the T0 protocol and the status information specific to the T1 protocol in the data.
Preferably, the apparatus further comprises a third parsing module;
and the third analysis module is used for analyzing the exchange protocol type supported by the card reader equipment according to the information of the card reader equipment.
In this embodiment, the encapsulating module 308 is specifically configured to perform protocol encapsulation on the operation instruction after the format conversion by the first format conversion module 306 according to the card type and the exchange protocol supported by the card reader device.
Preferably, the method further comprises the following steps:
the first format conversion module 306 is further configured to convert a format of an instruction for starting the card reader device service when the first receiving module 301 receives the instruction for starting the card reader device service, which is sent by the user application; the first receiving module 301 is further configured to convert a power-off instruction format when receiving a power-off instruction sent by a user application and sent to the card reader device; when the first receiving module 301 receives the response data after the format conversion, the format of the response data after the format conversion is converted; the first receiving module 301 is further configured to convert a format of an instruction for stopping the card reader device service when the first receiving module receives the instruction for stopping the card reader device service, which is sent by the user application;
the starting module is used for starting the card reader equipment service after the first format conversion module 306 converts the instruction format for starting the card reader equipment service;
the first sending module 304 is further configured to return corresponding state information to the user application after the starting module starts the card reader device service; the power-off instruction is also used for sending the power-off instruction after the format conversion to the card reader device manager; the first format conversion module 306 is further configured to return the response data after the format conversion to the user application; the card reader is also used for returning corresponding state information to the user application after the stopping module stops the service of the card reader equipment;
the second format conversion module 402 is further configured to convert the format-converted power-down instruction into a format; the second receiving module 401 is further configured to convert the format after receiving response data returned by the card reader device;
the second sending module 403 is further configured to send the power-off instruction after the format conversion by the second format conversion module 402 to the card reader device; the second conversion module 402 is further configured to send the response data after the format conversion to the communication module;
a stopping module, configured to stop the card reader device service after the first format conversion module 306 converts the instruction format for stopping the card reader device service.
Further, the corresponding state information in the first sending module 304 is specifically: information of success or failure of service opening of the card reader device; the card reader device services stop success or failure information.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all such changes or substitutions should be covered by the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (34)

1. A method for realizing communication of a card reader device in an android system is characterized by comprising the following steps:
step S1: when the communication module receives an instruction for searching for the card reader device sent by the user application, executing step S2; when the communication module receives a power-on instruction sent by the user application to the card reader device, the power-on instruction format is converted, and then step S3 is executed; when the communication module receives the operation instruction sent by the user application, the operation instruction format is converted, and then step S4 is executed;
step S2: the communication module acquires an equipment list and judges whether a preset equipment identifier can be acquired in the equipment list, if so, an instruction for acquiring information of the card reader equipment corresponding to the preset equipment identifier is sent to a card reader equipment manager, the card reader equipment manager performs format conversion on the instruction for acquiring the information of the card reader equipment, the instruction after format conversion is sent to the card reader equipment, after the card reader equipment manager receives the card reader equipment information returned by the card reader equipment, the format of the card reader equipment information is converted and the card reader information after format conversion is sent to the communication module, the communication module analyzes the card reader equipment information after format conversion and returns the analysis result to the user application after format conversion, and if not, an error is reported;
step S3: the communication module sends a format-converted power-on instruction to the card reader device manager, the card reader device manager converts the format-converted power-on instruction into a format and sends the format-converted power-on instruction to the card reader device, the card reader device manager converts the format after receiving response data returned by the card reader device and sends the format-converted response data to the communication module, the communication module analyzes the card type according to the format-converted response data and converts the format of a result of analyzing the card type, and the format-converted result of analyzing the card type is returned to the user application;
step S4: the communication module carries out protocol encapsulation on the operation instruction after format conversion and then sends the operation instruction to the card reader equipment manager, the card reader equipment manager converts the format of the operation instruction and sends the operation instruction after the format conversion to the card reader equipment, the card reader equipment manager receives operation response data returned by the card reader equipment and then converts the format and sends the operation response data after the format conversion to the communication module, and the communication module carries out protocol unpacking and then converts the unpacked data into the format and returns the format to the user application.
2. The method according to claim 1, wherein the converting the format of the power-on instruction specifically comprises: the communication module converts the format of the power-on instruction into a character string;
the converting the format of the operation instruction specifically comprises: the communication module converts the format of the operation instruction into a character string;
the card reader device manager performs format conversion on the instruction for acquiring the card reader device information, and specifically includes: the card reader equipment manager converts the format of the instruction for acquiring the card reader equipment information into a binary system;
the information format of the conversion card reader device is specifically as follows: the card reader equipment manager converts the format of the card reader equipment information into a character string;
the format conversion of the analysis result specifically comprises: the communication module converts the format of the analysis result into a binary system;
the card reader equipment manager converts the power-on instruction into a format, specifically: the card reader equipment manager converts the format of the power-on instruction into a binary system;
the card reader device manager converts the format after receiving the response data returned by the card reader device, and specifically comprises the following steps: after receiving response data returned by the card reader equipment, the card reader equipment manager converts the format of the response data into a character string;
the format conversion of the result of analyzing the card type specifically comprises: the communication module converts the format of the result of analyzing the card type into a binary system;
the card reader equipment manager converts the format of the operation instruction, and specifically comprises the following steps: the card reader equipment converts the format of the operation instruction into a binary system;
the card reader equipment manager converts the format after receiving the operation response data returned by the card reader equipment, and specifically comprises the following steps: after receiving the operation response data returned by the card reader equipment, the card reader equipment manager converts the format of the operation response data returned by the card reader equipment into a character string;
the format conversion of the unpacked data is specifically as follows: and the communication module converts the format of the unpacked data into a binary system.
3. The method according to claim 1, wherein the communication module obtains the device list specifically as follows: and the communication module sends an instruction for acquiring an equipment list to the card reader equipment manager and receives the equipment list returned by the card reader equipment manager.
4. The method of claim 1, further comprising: after receiving the instruction for acquiring the device list, the card reader device manager calls a UsbManager getDeviceList system function to send the instruction for acquiring the device list to the card reader device;
or,
LeScanCallback system function is called to send an instruction to the card reader device to obtain a device list.
5. The method according to claim 1, wherein the communication module acquires an equipment list and determines whether a preset equipment identifier can be acquired in the equipment list, specifically:
and traversing the equipment list after the communication module acquires the equipment list, judging whether a preset equipment identifier can be acquired in the equipment list, if so, sending an instruction for acquiring information of the card reader equipment corresponding to the preset equipment identifier to a card reader equipment manager, and otherwise, reporting an error.
6. The method according to claim 1, wherein in step S2, the sending the instruction after format conversion to the card reader device specifically includes: the card reader device manager calls a UsbDeviceConnection.controlTransfer system function to send a format conversion instruction to the card reader device; and after receiving the instruction, the card reader equipment calls a UsbDeviceConnection.controlTransfer system function to return card reader equipment information to the card reader equipment manager.
7. The method according to claim 1, wherein in step S3, the card reader device manager converts the format of the power-on command and sends the converted power-on command to the card reader device, specifically:
the card reader equipment manager calls a UsbDeviceConnection. bulk transfer system function to send a power-on instruction to the card reader equipment; the sending of the response data after format conversion to the communication module specifically includes: the card reader equipment manager calls a UsbDeviceConnection. bulk transfer system function to send response data after format conversion to the communication module;
or,
the card reader equipment manager calls a writecard feature system function to send a power-on instruction to the card reader equipment; the sending of the response data after format conversion to the communication module specifically includes: and the card reader equipment manager calls a readcharateristic system function to send the response data after format conversion to the communication module.
8. The method according to claim 1, wherein before the step S3, the step S further comprises, before the step S3, the step S of analyzing the card type according to the response data: the communication module judges whether a card exists according to response data returned by the card reader device manager, if so, the communication module analyzes the card type according to the response data, and if not, an error is reported.
9. The method according to claim 1, wherein before the communication module analyzes the card type according to the response in step S3, the method further comprises the steps of determining whether the card reader device can be accelerated by the communication module, if so, sending an instruction for accelerating the card reader device to the card reader device manager, and if not, analyzing the card information directly according to the response by the communication module.
10. The method according to claim 9, wherein the sending the instruction for speeding up the card reader device to the card reader device manager specifically comprises: and the communication module calls a UsbDeviceConnection.bulk transfer system function to send a speed-up instruction to the card reader equipment manager.
11. The method according to claim 9, wherein the determining, by the communication module, whether the card reader device can speed up specifically includes: the communication module judges whether the card reader equipment can accelerate according to the information whether the card reader equipment supports acceleration contained in the descriptor in the card reader equipment information, and if the descriptor contains the information that the card reader equipment supports acceleration, the card reader equipment can accelerate; if the descriptor contains information that the card reader device does not support speed increasing, the card reader device cannot speed up.
12. The method according to claim 1, wherein the parsing of the card type in step S3 specifically includes: and the communication module analyzes the type of the card according to the information of the card type in the response data.
13. The method according to claim 12, wherein the communication module analyzes the type of the card according to the information of the card type in the response data, specifically: the communication module analyzes the type of the card according to the state information specific to the T0 protocol and the state information specific to the T1 protocol in the response data.
14. The method according to claim 1, wherein the step S4 is preceded by: and the communication module analyzes the exchange protocol type supported by the card reader equipment according to the information of the card reader equipment.
15. The method according to claim 14, wherein in step S4, the communication module performs protocol encapsulation on the operation instruction, specifically: and the communication module carries out protocol encapsulation on the operation instruction according to the card type and the exchange protocol supported by the card reader equipment.
16. The method according to claim 1, wherein the step S1 further comprises: when the communication module receives an instruction for starting the card reader equipment service sent by the user application, the communication module converts the format of the instruction for starting the card reader equipment service and then executes the step S0; when the communication module receives a power-off instruction sent by the user application to the card reader device, the power-off instruction format is converted, and then step S5 is executed; when the communication module receives an instruction for stopping the service of the card reader device sent by the user application, the communication module converts the format of the instruction for stopping the service of the card reader device and then executes the step S6;
step S0: the communication module starts the card reader equipment service and returns corresponding state information to the user application;
step S5: the communication module sends a power-off instruction after format conversion to the card reader equipment manager, the card reader equipment manager converts the format of the power-off instruction after format conversion and sends the converted format to the card reader equipment, the card reader equipment manager converts the format after receiving response data returned by the card reader equipment and sends the format-converted response data to the communication module, and the communication module converts the format-converted response data and returns the format-converted response data to the user application;
step S6: and the communication module stops the service of the card reader equipment and returns corresponding state information to the user application.
17. The method according to claim 16, wherein the corresponding status information in step S0 is specifically: the card reader equipment service opening success or failure information;
the corresponding status information in step S6 is specifically: the card reader device services stop success or failure information.
18. An apparatus for enabling communication of a card reader device in an android system, comprising: a communication module and a card reader device manager;
the communication module specifically comprises:
the first receiving module is used for receiving an instruction sent by a user application and data returned by the card reader equipment manager;
the acquisition module is used for acquiring an equipment list when the first receiving module receives an instruction for searching for card reader equipment sent by the user application;
a first determining module, configured to determine whether a preset device identifier may be obtained in the device list obtained by the obtaining module;
the first sending module is configured to send, to the card reader device manager, an instruction to obtain information of the card reader device corresponding to the preset device identifier when the first determining module determines that the preset device identifier can be obtained in the device list; the analysis result after the format conversion of the first format conversion module is sent to the user application; the power-on instruction is used for sending the format converted by the first format conversion module to the card reader equipment manager; the card type conversion module is used for converting the format of the card type into a first format conversion module; the card reader equipment manager is used for sending the operation instruction packaged by the packaging module to the card reader equipment manager; the data processing module is used for returning the unpacked data after the format conversion of the first format conversion module to the user application;
the first analysis module is used for analyzing the card reader equipment information after format conversion when the data returned by the card reader equipment manager received by the first receiving module is the card reader information after format conversion;
the first format conversion module is used for converting the format of the analysis result obtained by the first analysis module; the first receiving module is used for converting the power-on instruction format when receiving a power-on instruction sent by the user application to the card reader equipment; the first receiving module is used for converting the format of the operation instruction when the first receiving module receives the operation instruction sent by the user application; the card type conversion module is used for converting the result of the card type obtained by the analysis of the second analysis module into a format; the data conversion module is also used for converting the format of the unpacked data;
the second analysis module is used for analyzing the card type according to the response data after the format conversion to obtain a result of the card type when the first receiving module receives the response data after the format conversion;
the packaging module is used for carrying out protocol packaging on the operation instruction after the format conversion of the first format conversion module;
the unpacking module is used for unpacking the protocol when the first receiving module receives the operation response data after the format conversion;
the card reader device manager specifically includes:
the second receiving module is used for receiving the instruction sent by the communication module and the response returned by the card reader equipment;
the second format conversion module is used for carrying out format conversion on the instruction which is sent by the first sending module and used for acquiring the information of the card reader equipment corresponding to the preset equipment identifier; the format conversion module is used for converting the format of the card reader equipment information received by the second receiving module and returned by the card reader equipment; the power-on instruction conversion module is used for converting the format of the power-on instruction received by the second receiving module; the format conversion module is used for converting the response data received by the second receiving module and returned by the card reader equipment and then converting the format; the second receiving module is further used for converting the format of the operation instruction after receiving the packaged operation instruction; the second receiving module is used for converting the format after receiving operation response data returned by the card reader equipment;
the second sending module is used for sending the instruction for acquiring the information of the card reader equipment after the format is converted by the second format conversion module to the card reader equipment; the card reader equipment information after the format conversion of the second format conversion module is sent to the communication module; the power-on instruction after the format conversion of the second format conversion module is sent to the card reader equipment; the response data after the format conversion of the second format conversion module is sent to the communication module; the operation instruction after the format conversion of the second format conversion module is sent to the card reader equipment; and the operation response data after the format conversion of the second format conversion module is sent to the communication module.
19. The apparatus of claim 18, wherein the first transform format module comprises: a first conversion format unit and a second conversion format unit;
the first conversion format unit is used for converting the format of the power-on instruction into a character string; the operation instruction is also used for converting the format of the operation instruction into a character string;
the second format conversion unit is used for converting the format of the analysis result into a binary system; the format of the result of analyzing the card type is converted into binary; the data processing device is also used for converting the format of the unpacked data into a binary system;
the second conversion format module includes: a third conversion format unit and a fourth conversion format unit;
the third format conversion unit is used for converting the format of the card reader equipment information into a character string; the format of the response data is converted into a character string; the card reader device is also used for converting the format of the operation response data returned by the card reader device into a character string;
the fourth format conversion unit is configured to convert the format of the instruction for acquiring the information of the card reader device into a binary system; the power-on instruction is used for converting the format of the power-on instruction into a binary system; and the processor is also used for converting the format of the operation instruction into binary.
20. The apparatus of claim 18, wherein the obtaining module comprises: a first transmitting unit and a first receiving unit;
the first sending unit is used for sending an instruction for acquiring an equipment list to the card reader equipment manager;
the first receiving unit is configured to receive the device list returned by the card reader device manager.
21. The apparatus of claim 18, further comprising a calling module;
the calling module is used for calling a UsbManagergetDeviceList system function to send an instruction for acquiring the device list to the card reader device after the second receiving module receives the instruction for acquiring the device list;
or,
LeScanCallback system function is called to send an instruction to the card reader device to obtain a device list.
22. The apparatus of claim 18, wherein the first determining module further comprises: a traversing unit;
the traversing unit is configured to traverse the device list after the obtaining module obtains the device list.
23. The apparatus of claim 18, wherein the second sending module comprises a first calling unit;
the first calling unit is used for calling a UsbDeviceConnection.
24. The apparatus of claim 18, wherein the second sending module further comprises a second invoking unit;
the second calling unit is used for calling a UsbDeviceConnection. bulk transfer system function to send a power-on instruction to the card reader equipment; the system function is also used for calling UsbDeviceConnection.bulk transfer system function to send the response data after format conversion to the communication module; or, the function is used for calling the writecard feature system function to send a power-on instruction to the card reader device; and the module is also used for calling a readcharateristic system function to send the response data after format conversion to the communication module.
25. The apparatus of claim 18, further comprising a second determining module;
the second judging module is used for judging whether a card exists according to response data returned by the card reader device manager of the first receiving module;
the second analysis module is specifically configured to analyze the card type according to the response data when the second determination module determines that a card is present.
26. The apparatus of claim 18, further comprising a third determining module;
the third judging module is used for judging whether the card reader equipment can accelerate;
the first sending module is further configured to send an instruction of speeding up the card reader device to the card reader device manager when the third determining module determines that the card reader device can speed up;
the second analysis module is further configured to analyze card information directly according to a response when the third determination module determines that the card reader device cannot accelerate.
27. The apparatus of claim 26, wherein the first sending module further comprises a third invoking unit;
the third calling unit is used for calling a UsbDeviceConnection. bulk transfer system function to send a speed-up instruction to the card reader device manager.
28. The apparatus according to claim 26, wherein the third determining module is specifically configured to determine whether the card reader device can speed up according to information about whether the card reader device supports speed up, which is included in a descriptor in the card reader device information;
the first sending module is configured to send an instruction of speeding up the card reader device to the card reader device manager if the third determining module determines that the descriptor includes information that the card reader device supports speeding up, and the card reader device can speed up.
29. The apparatus according to claim 18, wherein the second parsing module is specifically configured to parse a card type according to information about the card type in the response data.
30. The apparatus of claim 29, wherein the second parsing module is specifically configured to parse the type of the card according to the status information specific to the T0 protocol and the status information specific to the T1 protocol in the response data.
31. The apparatus of claim 18, further comprising a third parsing module;
and the third analysis module is used for analyzing the exchange protocol type supported by the card reader equipment according to the card reader equipment information.
32. The apparatus according to claim 31, wherein the encapsulation module is specifically configured to perform protocol encapsulation on the operation instruction converted from the format by the first format conversion module according to the card type and the exchange protocol supported by the card reader device.
33. The apparatus of claim 18, further comprising:
the first format conversion module is further configured to convert a format of an instruction for starting the card reader device service when the first receiving module receives the instruction for starting the card reader device service, which is sent by the user application; the first receiving module is further used for converting the power-off instruction format when receiving a power-off instruction sent by the user application and sent to the card reader equipment; when the first receiving module receives the response data after the format conversion, the format of the response data after the format conversion is converted; the first receiving module is further used for converting the format of the instruction for stopping the service of the card reader equipment when the first receiving module receives the instruction for stopping the service of the card reader equipment, which is sent by the user application;
the starting module is used for starting the card reader equipment service after the first format conversion module converts the instruction format for starting the card reader equipment service;
the first sending module is further configured to return corresponding state information to the user application after the starting module starts the card reader device service; the power-off instruction after format conversion is sent to the card reader equipment manager; the first format conversion module is also used for converting the format of the response data into the format converted by the first format conversion module; the card reader is also used for returning corresponding state information to the user application after the stop module stops the service of the card reader equipment;
the second format conversion module is further configured to convert the format-converted power-down instruction into a format; the second receiving module is also used for converting the format after receiving response data returned by the card reader equipment;
the second sending module is further configured to send the power-off instruction after the format conversion by the second format conversion module is performed to the card reader device; the second format conversion module is also used for sending the response data after the format conversion of the second format conversion module to the communication module;
and the stopping module is used for stopping the service of the card reader equipment after the first format conversion module converts the instruction format for stopping the service of the card reader equipment.
34. The apparatus of claim 33, wherein the corresponding status information in the first sending module is specifically: the card reader equipment service opening success or failure information; the card reader device services stop success or failure information.
CN201710944163.9A 2017-09-30 2017-09-30 Method and device for realizing communication of card reader equipment in android system Active CN107784243B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710944163.9A CN107784243B (en) 2017-09-30 2017-09-30 Method and device for realizing communication of card reader equipment in android system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710944163.9A CN107784243B (en) 2017-09-30 2017-09-30 Method and device for realizing communication of card reader equipment in android system

Publications (2)

Publication Number Publication Date
CN107784243A CN107784243A (en) 2018-03-09
CN107784243B true CN107784243B (en) 2020-11-03

Family

ID=61433697

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710944163.9A Active CN107784243B (en) 2017-09-30 2017-09-30 Method and device for realizing communication of card reader equipment in android system

Country Status (1)

Country Link
CN (1) CN107784243B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110336592B (en) 2019-06-28 2021-03-16 飞天诚信科技股份有限公司 Data transmission method suitable for Bluetooth card reader, electronic equipment and storage medium
CN112835836B (en) * 2021-01-29 2022-04-08 郑州信大捷安信息技术股份有限公司 Method and device for information interaction between host and smart card
CN114417900A (en) * 2021-12-21 2022-04-29 东信和平科技股份有限公司 System and method for realizing unified read-write card and peripheral access

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5581257A (en) * 1991-09-24 1996-12-03 Gordian Holding Corporation Radio frequency automatic identification system
CN1932854A (en) * 2006-09-30 2007-03-21 北京飞天诚信科技有限公司 Card reader capable of customizing flag information
CN101576945A (en) * 2008-12-31 2009-11-11 北京飞天诚信科技有限公司 Multifunctional card reader and realization method thereof
CN102123142A (en) * 2011-01-12 2011-07-13 金锰 Information processing method

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS59202857A (en) * 1983-05-02 1984-11-16 Toppan Printing Co Ltd Apparatus for converting picture pattern area ratio data
JP3483993B2 (en) * 1995-08-31 2004-01-06 ホーチキ株式会社 Access control device
CN102118709B (en) * 2011-02-22 2014-08-13 中兴通讯股份有限公司 Method and system for increasing format conversion efficiency in group multimedia message sending service
CN104426572A (en) * 2013-09-11 2015-03-18 中兴通讯股份有限公司 Method and system for multiplexing radio-frequency front end
CN103955392A (en) * 2014-05-21 2014-07-30 东信和平科技股份有限公司 Generation method and system for intelligent card writing-in file
CN105225101B (en) * 2015-09-16 2018-01-05 腾讯科技(深圳)有限公司 Circle deposit method, device and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5581257A (en) * 1991-09-24 1996-12-03 Gordian Holding Corporation Radio frequency automatic identification system
CN1932854A (en) * 2006-09-30 2007-03-21 北京飞天诚信科技有限公司 Card reader capable of customizing flag information
CN101576945A (en) * 2008-12-31 2009-11-11 北京飞天诚信科技有限公司 Multifunctional card reader and realization method thereof
CN102123142A (en) * 2011-01-12 2011-07-13 金锰 Information processing method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于单片机的非接触式IC 卡读卡器设计;吕中兴 等;《数字技术与应用》;20141215;第165-166,168页 *

Also Published As

Publication number Publication date
CN107784243A (en) 2018-03-09

Similar Documents

Publication Publication Date Title
CN107784243B (en) Method and device for realizing communication of card reader equipment in android system
EP2487838B1 (en) Data card and method for internet access of data card
CN107318098B (en) Terminal control method, SIM card, communication module and terminal
CN105094905B (en) Method and device for dynamically loading language resources
CN109587252A (en) Loading method, device, electronic equipment and the storage medium of operator parameter
CN107844821B (en) Smart card, control method thereof, and computer-readable storage medium
WO2023134153A1 (en) Linkage control configuration method, linkage control method and linkage control system
US20220327010A1 (en) Extensible communication framework and communication method supporting multiple communication protocols
CN112269746A (en) Automatic testing method and related equipment
CN112835839A (en) PCIe interface device enumeration method, PCIe interface device enumeration apparatus, PCIe interface device and PCIe interface storage medium
CN112015537A (en) Method, system, terminal device and storage medium for executing data processing task
WO2010118612A1 (en) Method for installing contactless payment application, smart card and mobile terminal
CN111580986A (en) Data acquisition method, system and medium based on acquisition service middleware
CN106294119B (en) Test scheduling system and method and terminal equipment
CN112181147B (en) Small program-based wearable device interaction method and device and electronic device
CN112954717A (en) Household appliance network distribution method and device based on H5 page
CN112351094A (en) Webpage pushing method and device, electronic equipment and storage medium
CN115484343B (en) Method for preventing data transmission loss of android mobile phone and Bluetooth equipment based on WeChat applet
CN101917780B (en) Function implementation method and device of wireless communication terminal network equipment
CN111381978B (en) Method for accessing application program, storage medium and intelligent television
CN112835836B (en) Method and device for information interaction between host and smart card
EP3573306A1 (en) Data processing method and device utilized in client terminal
CN103079190B (en) It is a kind of to realize method, system and main frame that wireless terminal browses webpage function
CN108307286B (en) Method and system for realizing communication between android devices based on NFC
CN113114522B (en) Flow monitoring device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant