CN109684888B - Method for communicating with smart card and card reader - Google Patents

Method for communicating with smart card and card reader Download PDF

Info

Publication number
CN109684888B
CN109684888B CN201811593916.7A CN201811593916A CN109684888B CN 109684888 B CN109684888 B CN 109684888B CN 201811593916 A CN201811593916 A CN 201811593916A CN 109684888 B CN109684888 B CN 109684888B
Authority
CN
China
Prior art keywords
card
data
response
parameter
instruction
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
CN201811593916.7A
Other languages
Chinese (zh)
Other versions
CN109684888A (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 CN201811593916.7A priority Critical patent/CN109684888B/en
Publication of CN109684888A publication Critical patent/CN109684888A/en
Application granted granted Critical
Publication of CN109684888B publication Critical patent/CN109684888B/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/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/10009Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation sensing by radiation using wavelengths larger than 0.1 mm, e.g. radio-waves or microwaves
    • G06K7/10366Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation sensing by radiation using wavelengths larger than 0.1 mm, e.g. radio-waves or microwaves the interrogation device being adapted for miscellaneous applications
    • 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/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/10009Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation sensing by radiation using wavelengths larger than 0.1 mm, e.g. radio-waves or microwaves
    • G06K7/10198Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation sensing by radiation using wavelengths larger than 0.1 mm, e.g. radio-waves or microwaves setting parameters for the interrogator, e.g. programming parameters and operating modes

Landscapes

  • Health & Medical Sciences (AREA)
  • Toxicology (AREA)
  • Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Electromagnetism (AREA)
  • General Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Communication Control (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The invention discloses a method for communicating with a smart card and a card reader, wherein the method comprises the following steps: the card reader sends a card searching instruction; receiving a card searching response from the smart card; judging the type of the smart card according to the card protocol information in the card searching response, organizing a card selection command if the smart card is a non-standard smart card, and sending the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip power-on response to the upper computer, acquiring instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, calculating instruction verification data according to the instruction effective data, sequentially splicing the instruction effective data and the instruction verification data to obtain a first card communication instruction, and sending the first card communication instruction to the smart card; receiving a first card communication response from the smart card, acquiring first response effective data from the first card communication response, organizing the communication response comprising the first response effective data, and returning the communication response to the upper computer.

Description

Method for communicating with smart card and card reader
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method for communicating with a smart card and a card reader.
Background
A smart card is a microchip embedded card that has an integrated circuit including a central processing unit CPU, a programmable read only memory EEPROM, a random access memory RAM, and an in-card operating system that is embedded in the read only memory ROM. Because the smart card has the characteristics of high reliability, good safety, large storage capacity and the like, the application range of the smart card is not limited to the early communication field any more, but the smart card is widely applied to the fields of finance and finance, social insurance, traffic and tourism, medical health, government administration, commodity retail, entertainment, school management and the like.
In the prior art, with the expansion of the application range of the smart card, some non-standard smart cards appear, and the appearance of the smart card causes that the traditional card reader cannot communicate with the non-standard smart card.
Disclosure of Invention
The invention provides a method for communicating with a smart card and a card reader, which solve the technical problems.
The invention provides a method for communicating with a smart card, which comprises the following steps:
step t 1: the card reader sends a card searching instruction; receiving a card searching response from the smart card; judging the type of the smart card according to the card protocol information in the card searching response, and executing step t2 if the smart card is a non-standard smart card; if the smart card is a standard smart card, executing step t 5;
step t 2: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 3;
step t 3: the card reader waits for receiving a communication instruction from an upper computer, acquires instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, calculates instruction verification data according to the instruction effective data, sequentially splices the instruction effective data and the instruction verification data to obtain a first card communication instruction, and sends the first card communication instruction to the smart card;
step t 4: the card reader receives a first card communication response from the smart card, acquires first response effective data from the first card communication response, organizes the communication response comprising the first response effective data, and returns the communication response to the upper computer; returning to the step t 3;
step t 5: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 6;
step t 6: the card reader waits for receiving a communication instruction from the upper computer, acquires instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, organizes the instruction start end data, calculates instruction verification data according to the instruction start end data and the instruction effective data, sequentially splices the instruction start end data, the instruction effective data and the instruction verification data to obtain a second card communication instruction, and sends the second card communication instruction to the smart card;
step t 7: the card reader receives a second card communication response from the smart card, acquires second response effective data from the second card communication response, organizes the communication response comprising the second response effective data, and returns the communication response to the upper computer; returning to step t 6.
The invention also provides a card reader for communicating with a smart card, comprising: the system comprises a first sending module, a first receiving module, a first judging module, a first organizing module, a second sending module, a second receiving module, a first returning module, a third receiving module, a first obtaining module, a first calculating module, a first splicing module, a third sending module, a fourth receiving module, a second obtaining module, a second organizing module, a fourth sending module, a third organizing module, a second splicing module, a fifth sending module, a fifth receiving module, a third obtaining module and a fourth organizing module;
the first sending module is used for sending a card searching instruction;
the first receiving module is used for receiving a card searching response from the intelligent card;
the first judging module is used for judging the type of the intelligent card according to the card protocol information in the card searching response received by the first receiving module;
the first organizing module is used for organizing a card selection command;
a second sending module, configured to send a card selection command organized by the first organization module to the smart card;
the second receiving module is used for receiving a card selection response from the smart card;
the first return module is used for sending the on-chip electric response to the upper computer;
the third receiving module is used for receiving a communication instruction from the upper computer;
the first obtaining module is used for obtaining the instruction effective data from the communication instruction received by the third receiving module;
the first calculation module is used for calculating instruction verification data according to the instruction valid data acquired by the first acquisition module when the first judgment module judges that the type of the smart card is a non-standard smart card;
the first splicing module is used for sequentially splicing the instruction effective data acquired by the first acquisition module and the instruction verification data acquired by the first calculation module to acquire a first card communication instruction;
the third sending module is used for sending the first card communication instruction obtained by the first splicing module to the smart card;
the fourth receiving module is used for receiving a first card communication response from the smart card;
the second obtaining module is used for obtaining first response effective data from the first card communication response received by the fourth receiving module;
the second organization module is used for organizing the communication response comprising the first response effective data;
the fourth sending module is used for returning the communication response organized by the second organization module to the upper computer; and returning the communication response organized by the fourth organization module to the upper computer;
the third organizing module is used for organizing instruction starting end data when the first judging module judges that the smart card is a standard smart card;
the second splicing module is used for calculating instruction check data according to the instruction starting end data and the instruction effective data acquired by the first acquisition module; sequentially splicing the starting end data organized by the third organization module, the instruction effective data acquired by the first acquisition module and the instruction check data organized by the third organization module to obtain a second card communication instruction;
the fifth sending module is configured to send the second card communication instruction obtained by the second splicing module to the smart card;
the fifth receiving module is used for receiving a second card communication response from the smart card;
the third obtaining module is configured to obtain second response valid data from the second card communication response received by the fifth receiving module;
and the fourth organizing module is used for organizing the communication response comprising the second response effective data.
The invention has the beneficial effects that: the invention provides a method for communicating with a smart card and a card reader, which can communicate with a standard smart card and a non-standard smart card.
Drawings
Fig. 1 is a flowchart of a method for communicating with a smart card according to embodiment 2 of the present invention.
Fig. 2 is a block diagram of a card reader in communication with a smart card according to embodiment 3 of the present invention.
Detailed description of the invention
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 1
The embodiment provides a method for communicating with a smart card, which comprises the following steps:
step t 1: the card reader sends a card searching instruction; receiving a card searching response from the smart card; judging the type of the smart card according to the card protocol information in the card searching response, and executing the step t2 if the smart card is a non-standard smart card; if the smart card is a standard smart card, executing step t 5;
step t 2: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 3;
step t 3: the card reader waits for receiving a communication instruction from the upper computer, obtains instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, calculates instruction verification data according to the instruction effective data, sequentially splices the instruction effective data and the instruction verification data to obtain a first card communication instruction, and sends the first card communication instruction to the smart card;
step t 4: the card reader receives a first card communication response from the smart card, acquires first response effective data from the first card communication response, organizes the communication response comprising the first response effective data, and returns the communication response to the upper computer; returning to the step t 3;
step t 5: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 6;
step t 6: the card reader waits for receiving a communication instruction from the upper computer, acquires instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, organizes the instruction start end data, calculates instruction verification data according to the instruction start end data and the instruction effective data, sequentially splices the instruction start end data, the instruction effective data and the instruction verification data to obtain a second card communication instruction, and sends the second card communication instruction to the smart card;
step t 7: the card reader receives a second card communication response from the smart card, acquires second response effective data from the second card communication response, organizes the communication response comprising the second response effective data, and returns the communication response to the upper computer; returning to step t 6.
Further, the first response valid data is obtained from the first card communication response, and specifically:
the card reader takes the rest data except the last two bytes of data in the first card communication response as the first response valid data.
Further, the second response valid data is obtained from the second card communication response, and specifically: the card reader acquires data on a first byte in the second card communication response, acquires response starting end data according to the data on the first byte in the second card communication response, takes last two bytes in the second card communication response as second response verification data, and takes all data between the response starting end data and the second response verification data as second response effective data.
Further, the card reader acquires data on a first byte in the second card communication response, and acquires response start end data according to the data on the first byte in the second card communication response, specifically: the card reader acquires data on a third bit and data on a fourth bit of a first byte in the second card communication response, and if the data on the third bit and the data on the fourth bit are both a second preset value, the card reader takes the first three bytes in the second card communication response as response starting end data; if the data on the third bit or the data on the fourth bit are both the first preset value, the card reader takes the first byte in the second card communication response as the response starting end data; otherwise, the card reader takes the first two bytes in the card communication response as the response starting end data.
In this embodiment, the organization card selection command may specifically be:
the card reader acquires card identification information from the card searching response; respectively setting a first parameter, a second parameter, a fourth parameter and a third parameter with the lowest bit as a second preset value, sequentially splicing a first preset byte, card identification information, the first parameter, the second parameter, the third parameter and the fourth parameter to obtain first splicing data, calculating first selection verification data according to the first splicing data, and splicing the first selection verification data after the first splicing data to obtain a card selection command.
In this embodiment, organizing the card selection command may further specifically be:
the card reader acquires card identification information from the card searching response; according to a third parameter, a fourth parameter and a high-level command which are respectively set as a first parameter, a second parameter and have the lowest bit as a second preset value, sequentially splicing the first preset byte, the card identification information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command to obtain second splicing data, calculating second selective verification data according to the second splicing data, and splicing the second selective verification data behind the second splicing data to obtain a card selection command.
In this embodiment, the determining the type of the smart card according to the card protocol information in the card searching response may specifically be:
the card reader acquires card protocol information from the card searching response, judges whether low-nibble data of data on a second byte in the card protocol information is a first preset value or not, and judges that the intelligent card is a non-standard intelligent card if the low-nibble data of the data on the second byte in the card protocol information is the first preset value; otherwise, the intelligent card is judged to be a standard intelligent card.
In this embodiment, the obtaining of the instruction valid data from the communication instruction may specifically be: the card reader analyzes the communication instruction according to the communication protocol of the card reader and the upper computer to obtain effective instruction data;
in this embodiment, the communication protocol may include: CCID protocol or HID protocol or SCSI protocol or other communication protocol;
correspondingly, step t1 is preceded by: and electrifying the card reader, reporting the communication protocol of the card reader to the upper computer, and establishing connection between the card reader and the upper computer.
In this embodiment, the obtaining of the instruction valid data from the communication instruction may further specifically be:
the card reader acquires data at a first preset position in the communication command and takes the data as the length of the command effective data, the data with the length being the length of the command effective data is acquired from a second preset position of the communication command, and the acquired data is taken as the command effective data.
In this embodiment, the instruction start end data includes a fifth parameter, a sixth parameter, and a seventh parameter;
if the sixth parameter and the seventh parameter are both null, organizing the instruction start end data, specifically: setting data on a fourth bit and data on a third bit in a fifth parameter as a first preset value, and taking the fifth parameter as instruction starting end data;
if neither the sixth parameter nor the seventh parameter is empty, organizing the instruction start end data, specifically: setting data on a fourth bit and data on a third bit in a fifth parameter as a second preset value, and sequentially splicing the fifth parameter, the sixth parameter and the seventh parameter to obtain instruction starting end data;
if the sixth parameter is not null and the seventh parameter is null, organizing the instruction start data, specifically: setting data on a fourth bit in the fifth parameter as a first preset value; setting data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter and the sixth parameter to obtain instruction starting end data;
if the sixth parameter is null and the seventh parameter is not null, organizing the instruction start data, specifically: setting data on a fourth bit in the fifth parameter as a second preset value; and setting data on a third bit in the fifth parameter as a first preset value, and sequentially splicing the fifth parameter and the seventh parameter to obtain instruction starting end data.
The present embodiments provide a method of communicating with a smart card that can communicate with both standard smart cards and non-standard smart cards.
Example 2
The present embodiment provides a method for communicating with a smart card, as shown in fig. 1, including:
step 101: powering on the card reader, establishing connection with an upper computer, and sending a card searching instruction;
specifically, the card reader is powered on, the communication protocol type of the card reader is reported to the upper computer, the connection is established with the upper computer, and anti-collision prefix bytes, application family identifiers and card searching parameters are organized; calculating card searching verification data according to the anti-collision prefix byte, the application family identifier and the card searching parameter, sequentially splicing the anti-collision prefix byte, the application family identifier, the card searching parameter and the card searching verification data to obtain a card searching instruction, and sending the card searching instruction.
In this embodiment, the length of the anti-collision prefix byte, the length of the application family identifier, and the length of the card-searching parameter are all one byte, and the length of the card-searching verification data is 2 bytes.
For example: the method comprises the following steps that a Card reader is electrified, the type of a communication protocol of the Card reader is reported to an upper computer to be a CCID (USB Chip/Smart Card Interface Devices-USB) type, the Card reader is connected with the upper computer, and an anti-collision prefix byte 50, an application family identifier 00 and a Card searching parameter 00 are organized; calculating card searching check data CRC _ B according to the anti-collision prefix byte, the application family identifier and the card searching parameter, sequentially splicing the anti-collision prefix byte 50, the application family identifier 00, the card searching parameter 00 and the card searching check data CRC _ B to obtain a card searching instruction 500000 CRC _ B, and sending the card searching instruction.
In this embodiment, the communication protocol between the card reader and the host Computer may be, but is not limited to, a CCID protocol, an HID (human Interface Device) protocol, a SCSI (Small Computer System Interface) protocol, or other communication protocols.
Step 102: the card reader receives a card searching response from the smart card;
for example: the card reader receives a card-seeking response 5000000000D 10300810070C 0CRC _ B from the smart card.
Step 103: the card reader analyzes the card searching response, first card information and card protocol information are obtained from the card searching response, the type of the smart card is judged according to the card protocol information, and if the type of the smart card is a standard smart card, step 109 is executed; if the smart card type is a non-standard smart card, executing step 104;
specifically, the card reader takes the data of the second byte to the fifth byte in the card searching response as first information of the card, takes the data of the tenth byte to the twelfth byte in the card searching response as protocol information of the card, judges whether the low-half-byte data of the second byte in the protocol information of the card is a first preset value, and if so, judges that the smart card is a non-standard smart card; step 104 is executed; otherwise, the smart card is determined to be a standard smart card, and step 109 is executed.
In this embodiment, the first preset value is 0.
For example: the card reader takes data 00000000 from the second byte to the fifth byte in the card searching response 5000000000D 10300810070C 0CRC _ B as first information of a card, takes data 0070C 0 from the tenth byte to the twelfth byte in the card searching response as protocol information of the card, judges that the low nibble data 0 of the data 70 on the second byte in the protocol information of the card is a first preset value, and judges that the smart card is a non-standard smart card; step 104 is performed.
Step 104: the card reader organizes a card selection command and sends the card selection command to the smart card;
specifically, the card reader sets a first parameter, a second parameter, a third parameter with the lowest bit set to 1, a fourth parameter and a high-level command respectively, calculates selection check data according to a first preset byte, first card information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command, sequentially splices the first preset byte, the first card information, the first parameter, the second parameter, the third parameter, the fourth parameter, the high-level command and the selection check data to obtain a card selection command, and sends the card selection command to the smart card.
In this embodiment, the first preset byte is 1D, the data lengths of the first parameter, the second parameter, the third parameter, and the fourth parameter are all the first byte, the data length of the high-level command is 0 byte or 1 byte or more (2 or more), and the data length of the selected check data is 2 bytes.
In this embodiment, the fourth parameter may specifically be a card identifier. Preferably, in step 104, the fourth parameter is 00.
For example, the card reader sets a first parameter 00, a second parameter 08, a third parameter 01 with the lowest bit set to 1, a fourth parameter 00 and a high level command of a null value respectively, calculates the selection check data CRC _ B according to a first preset byte 1D, card first information 000000000000, the first parameter 00, the second parameter 08, the third parameter 01 and the fourth parameter 00, sequentially splices the first preset byte 1D, the card first information 000000000000, the first parameter 00, the second parameter 08, the third parameter 01, the fourth parameter 00 and the selection check data CRC _ B to obtain a card selection command 1D 0000000000080100 CRC _ B, and sends the card selection command to the smart card.
Step 105: the card reader receives the card selection response from the smart card, judges whether the card selection response is a successful selection response or not, and if so, sends the on-card electric response to the upper computer to execute step 106; otherwise, reporting an error;
specifically, the card reader receives a card selection response from the smart card, acquires data on the last two bytes in the card selection response and uses the data as a card selection response check value, calculates a first check value according to data except the last two bytes in the card selection response, judges whether the first check value is matched with the selection response check value, if so, judges that the card selection response is a successful selection response, sends a card power-on response to the upper computer, and executes step 106; otherwise, reporting an error;
for example: the card reader receives a card selection response 00CRC _ B from the smart card, acquires data CRC _ B on the last two bytes in the card selection response and uses the data CRC _ B as a card selection response check value, calculates a first check value according to the number 00 except the last two bytes in the card selection response, judges whether the first check value is matched with the selection response check value, if so, judges that the card selection response is a selection success response, sends a card power-on response to the upper computer, and executes step 106; otherwise, an error is reported.
Step 106: the card reader waits for receiving a communication instruction from the upper computer, and executes the step 107 after receiving the communication instruction from the upper computer;
for example: the card reader waits for receiving a communication command from the upper computer, and executes step 106 after receiving the communication command 6F 070000040000000000A 40000026002 from the upper computer;
step 107: the card reader acquires instruction effective data from the communication instruction, calculates instruction verification data according to the instruction effective data, sequentially splices the instruction effective data and the instruction verification data to obtain a first card communication instruction, and sends the first card communication instruction to the smart card;
specifically, the card reader analyzes a communication command according to the communication protocol type of the card reader and the upper computer, obtains command effective data from the communication command, calculates command verification data according to the command effective data, sequentially splices the command effective data and the command verification data to obtain a first card communication command, and sends the first card communication command to the smart card;
in this embodiment, the data length of the instruction check data is 2 bytes.
In this embodiment, the obtaining of the instruction effective data from the communication instruction specifically includes:
the card reader acquires data on a first preset position in the communication command and takes the data as the length of the command effective data, the data with the length being the length of the command effective data is acquired from a second preset position of the communication command, and the acquired data is taken as the command effective data.
In this embodiment, if the current protocol channel is an HID protocol channel corresponding to an HID protocol, the first preset position may be, but is not limited to, a seventh byte in the communication command, and the second preset position may be, but is not limited to, an eighth byte in the communication command; if the current protocol channel is a CCID protocol channel corresponding to the CCID protocol, the first preset location may be, but is not limited to, a second byte in the communication instruction, and the second preset location may be, but is not limited to, an eleventh byte in the communication instruction; if the current protocol channel is a SCSI protocol channel corresponding to a SCSI protocol, the first predetermined location may be, but is not limited to, a ninth byte in the communication command, and the second predetermined location may be, but is not limited to, a thirty-second byte in the communication command.
For example: the card reader analyzes a communication command 6F 07000000000000000000A 40000026002 according to the communication protocol type CCID protocol type of the card reader and the upper computer, acquires data 07 on a second byte in the communication command and takes the data as the effective data length of the command, acquires data 00A 40000026002 with the length of 7 bytes of the effective data length of the command from the eleventh byte of the communication command, takes the acquired data 00A 40000026002 as the effective data of the command, calculates command check data CRC _ B according to the effective data of the command, sequentially splices the effective data 00A 40000026002 of the command and the command check data CRC _ B to obtain a card communication command 00A 00040026002 CRC _ B, and sends the card communication command to the smart card;
step 108: the card reader receives the first card communication response from the smart card, acquires the first response effective data and the first response verification data from the first card communication response, organizes the communication response including the first response effective data, returns the communication response to the upper computer, and returns to step 106.
Specifically, the card reader receives a first card communication response from the smart card, takes data on the last two bytes in the first card communication response as first response verification data, takes data in the first card communication response before the first response verification data as first response effective data, organizes the communication response including the first response effective data according to the communication protocol type of the card reader and the upper computer, returns the communication response to the upper computer, and returns to step 106.
For example: the card reader receives a first card communication response 9000 CRC _ B from the smart card, takes the data CRC _ B on the last two bytes in the first card communication response as first response verification data, takes the data 9000 in the first card communication response before the first card response verification data as first response effective data, organizes the communication response 800200000001060000009000 with the CCID protocol type including the first response effective data according to the communication protocol type of the card reader and the upper computer, returns the communication response to the upper computer, and returns to the step 106.
Step 109: the card reader organizes a card selection command and sends the card selection command to the smart card;
specifically, the card reader sets a first parameter, a second parameter, a third parameter with the lowest bit set to 1, a fourth parameter and a high-level command respectively, calculates selection check data according to a first preset byte, first card information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command, sequentially splices the first preset byte, the first card information, the first parameter, the second parameter, the third parameter, the fourth parameter, the high-level command and the selection check data to obtain a card selection command, and sends the card selection command to the smart card.
In this embodiment, the first preset byte is 1D, the data lengths of the first parameter, the second parameter, the third parameter, and the fourth parameter are all the first byte, the data length of the high-level command is 0 byte or 1 byte or more (2 or more), and the data length of the selected check data is 2 bytes.
In this embodiment, the fourth parameter may specifically be a card identifier.
For example, the card reader sets a first parameter 00, a second parameter 08, a third parameter 01 with the lowest bit set to 1, a fourth parameter 00 and a high level command of a null value respectively, calculates the selection check data CRC _ B according to a first preset byte 1D, card first information 000000000000, the first parameter 00, the second parameter 08, the third parameter 01 and the fourth parameter 00, sequentially splices the first preset byte 1D, the card first information 000000000000, the first parameter 00, the second parameter 08, the third parameter 01, the fourth parameter 00 and the selection check data CRC _ B to obtain a card selection command 1D 0000000000080100 CRC _ B, and sends the card selection command to the smart card.
Step 110: the card reader receives the card selection response from the smart card, judges whether the card selection response is a successful selection response or not, and if so, sends the on-card electric response to the upper computer to execute step 111; otherwise, reporting an error;
specifically, the card reader receives a card selection response from the smart card, acquires data on the last two bytes in the card selection response and uses the data as a card selection response check value, calculates a first check value according to data except the last two bytes in the card selection response, judges whether the first check value is matched with the selection response check value, if so, judges that the card selection response is a successful selection response, sends a card power-on response to the upper computer, and executes step 111; otherwise, reporting an error;
for example: the card reader receives a card selection response 00CRC _ B from the smart card, acquires data CRC _ B on the last two bytes in the card selection response and uses the data CRC _ B as a card selection response check value, calculates a first check value according to the number 00 except the last two bytes in the card selection response, judges whether the first check value is matched with the selection response check value, if so, judges that the card selection response is a selection success response, sends a card power-on response to the upper computer, and executes step 111; otherwise, an error is reported.
Step 111: the card reader waits for receiving a communication instruction from the upper computer, and executes the step 112 after receiving the communication instruction from the upper computer;
step 112: the card reader acquires the effective instruction data from the communication instruction, organizes the instruction start end data, calculates the instruction check data according to the instruction start end data and the effective instruction data, sequentially splices the instruction start end data, the effective instruction data and the instruction check data to obtain a second card communication instruction, and sends the second card communication instruction to the intelligent card;
specifically, the card reader analyzes a communication command according to the communication protocol type of the card reader and the upper computer, obtains command effective data from the communication command, organizes the command start end data, calculates command verification data according to the command start end data and the command effective data, sequentially splices the command start end data, the command effective data and the command verification data to obtain a second card communication command, and sends the second card communication command to the smart card;
in this embodiment, the data length of the instruction check data is 2 bytes.
In this embodiment, the specific operation of obtaining the instruction valid data from the communication instruction is described in detail in step 107, and is not described in detail in step 112.
In this embodiment, the instruction start end data includes a fifth parameter, a sixth parameter, and a seventh parameter;
if the sixth parameter and the seventh parameter are both null, organizing the instruction start end data, specifically: setting data on a fourth bit and data on a third bit in a fifth parameter as a first preset value, and taking the fifth parameter as instruction starting end data;
if neither the sixth parameter nor the seventh parameter is empty, organizing the instruction start end data, specifically: setting data on a fourth bit and data on a third bit in a fifth parameter as a second preset value, and sequentially splicing the fifth parameter, the sixth parameter and the seventh parameter to obtain instruction starting end data;
if the sixth parameter is not null and the seventh parameter is null, organizing the instruction start data, specifically: setting data on a fourth bit in the fifth parameter as a first preset value; setting data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter and the sixth parameter to obtain instruction starting end data;
if the sixth parameter is null and the seventh parameter is not null, organizing the instruction start data, specifically: setting data on a fourth bit in the fifth parameter as a second preset value; and setting data on a third bit in the fifth parameter as a first preset value, and sequentially splicing the fifth parameter and the seventh parameter to obtain instruction starting end data.
In this embodiment, the fifth parameter may be a protocol control byte, the sixth parameter may be a card identifier, and the seventh parameter may be a node address.
In this embodiment, the second preset value may be 1.
For example: the card reader analyzes a communication command 6F 07000000000000000000A 40000026002 according to the communication protocol type CCID protocol type of the card reader and the upper computer, obtains command valid data 00A 40000026002 from the communication command, sets data on a fourth bit and data on a third bit in a fifth parameter as a second preset value 1, and sequentially splices the fifth parameter 0F, the sixth parameter 00 and the seventh parameter 01 to obtain command starting end data 0F 0001; calculating command check data CRC _ B according to the command start end data 0F 0001 and the command valid data 00A 40000026002, sequentially splicing the command start end data 0F 0001, the command valid data 00A 40000026002 and the command check data CRC _ B to obtain a second card communication command 0F 000100A 40000026002 CRC _ B, and sending the second card communication command to the smart card;
step 113: the card reader receives a second card communication response from the smart card, acquires second response effective data from the second card communication response, organizes the communication response comprising the second response effective data, and returns the communication response to the upper computer; returning to step 111.
In this embodiment, the second response valid data is acquired from the second card communication response in sequence, which specifically includes: the card reader acquires data on a first byte in the second card communication response, acquires response starting end data according to the data on the first byte in the second card communication response, takes last two bytes in the card communication response as second response verification data, and takes all data between the response starting end data and the second response verification data as second response effective data.
Further, the card reader acquires data on a first byte in the second card communication response, and acquires response start end data according to the data on the first byte in the second card communication response, specifically: the card reader acquires data on a third bit and data on a fourth bit of a first byte in the second card communication response, and if the data on the third bit and the data on the fourth bit are both a second preset value, the card reader takes the first three bytes in the second card communication response as response starting end data; if the data on the third bit or the data on the fourth bit are both the first preset value, the card reader takes the first byte in the second card communication response as the response starting end data; otherwise, the card reader takes the first two bytes in the second card communication response as response starting end data.
In this embodiment, the organization includes a communication response of the second response valid data, specifically: and organizing the communication response comprising the second response effective data according to the communication protocol type of the host computer.
For example: the card reader obtains data on a third bit and data on a fourth bit of a first byte 0F in a second card communication response 0F 00019000 CRC _ B, the data on the third bit and the data on the fourth bit are both a second preset value 1, and then the card reader takes the first three bytes 0F 0001 in the second card communication response as response starting end data; and taking the last two byte data CRC _ B in the card communication response as second response verification data, taking all data 9000 between the response starting end data and the second response verification data as second response effective data, organizing the communication response 800200000001060000009000 of which the CCID protocol type comprises the second response effective data according to the communication protocol type of the card communication response and the upper computer, returning the communication response to the upper computer, and returning to the step 111.
Example 3
The present embodiment provides a card reader for communicating with a smart card, as shown in fig. 2, including: the system comprises a first sending module 01, a first receiving module 02, a first judging module 03, a first organizing module 04, a second sending module 05, a second receiving module 06, a first returning module 07, a third receiving module 08, a first obtaining module 09, a first calculating module 10, a first splicing module 11, a third sending module 12, a fourth receiving module 13, a second obtaining module 14, a second organizing module 15, a fourth sending module 16, a third organizing module 17, a second splicing module 18, a fifth sending module 19, a fifth receiving module 20, a third obtaining module 21 and a fourth organizing module 22;
the first sending module 01 is used for sending a card searching instruction;
the first receiving module 02 is used for receiving a card searching response from the smart card;
the first judging module 03 is configured to judge the type of the smart card according to the card protocol information in the card searching response received by the first receiving module 02;
a first organizing module 04 for organizing the card selection command;
a second sending module 05, configured to send a card selection command organized by the first organization module 04 to the smart card;
a second receiving module 06, configured to receive a card selection response from the smart card;
the first returning module 07 is used for sending the card charging response to the upper computer after the second receiving module 06 receives the card selection response;
the third receiving module 08 is used for receiving a communication instruction from the upper computer;
the first obtaining module 09 is configured to obtain the instruction valid data from the communication instruction received by the third receiving module 08;
the first calculating module 10 is configured to calculate instruction verification data according to the instruction valid data acquired by the first acquiring module 09 when the first judging module 03 judges that the type of the smart card is the non-standard smart card;
the first splicing module 11 is configured to splice the instruction valid data obtained by the first obtaining module 09 and the instruction verification data obtained by the first calculating module 10 in sequence to obtain a first card communication instruction;
the third sending module 12 is configured to send the first card communication instruction obtained by the first splicing module 11 to the smart card;
the fourth receiving module 13 is configured to receive the first card communication response from the smart card;
the second obtaining module 14 is configured to obtain first response valid data from the first card communication response received by the fourth receiving module 13;
a second organizing module 15 for organizing the communication response including the first response valid data;
the fourth sending module 16 is used for returning the communication response organized by the second organization module 15 to the upper computer; and returning the communication response organized by the fourth organization module 22 to the upper computer;
the third organizing module 17 is configured to organize the instruction start end data when the first determining module 03 determines that the smart card is the standard smart card;
the second splicing module 18 is configured to calculate instruction check data according to the instruction start end data and the instruction valid data acquired by the first acquiring module 09; sequentially splicing the starting end data organized by the third organization module 17, the instruction effective data acquired by the first acquisition module 09 and the instruction check data organized by the third organization module 17 to obtain a second card communication instruction;
a fifth sending module 19, configured to send the second card communication instruction obtained by the second splicing module 18 to the smart card;
a fifth receiving module 20, configured to receive a second card communication response from the smart card;
the third obtaining module 21 is configured to obtain second response valid data from the second card communication response received by the fifth receiving module 20;
a fourth organizing module 22 for organizing the communication reply comprising the second reply payload data.
In this embodiment, the second obtaining module 14 is specifically configured to use the remaining data in the first card communication response, except the last two bytes of data, as the first response valid data.
In this embodiment, the third obtaining module 21 specifically includes: first and second acquisition units
The first acquisition unit is used for acquiring data on a first byte in the second card communication response and acquiring response starting end data according to the data on the first byte in the second card communication response;
and the second acquisition unit is used for taking the last two bytes of data in the second card communication response as second response verification data and taking all data between the response starting end data and the second response verification data as second response valid data.
Further, the first obtaining unit is specifically configured to obtain data on a third bit and data on a fourth bit of a first byte in the second card communication response, and if the data on the third bit and the data on the fourth bit are both a second preset value, the card reader uses the first three bytes in the second card communication response as response start end data; if the data on the third bit or the data on the fourth bit are both the first preset value, the card reader takes the first byte in the second card communication response as the response starting end data; otherwise, the card reader takes the first two bytes in the card communication response as the response starting end data.
In this embodiment, the first organization module 04 may be specifically configured to obtain card identification information from the card searching response; respectively setting a first parameter, a second parameter, a fourth parameter and a third parameter with the lowest bit as a second preset value, sequentially splicing a first preset byte, card identification information, the first parameter, the second parameter, the third parameter and the fourth parameter to obtain first splicing data, calculating first selection verification data according to the first splicing data, and splicing the first selection verification data after the first splicing data to obtain a card selection command.
In this embodiment, the first organization module 04 may be further specifically configured to obtain card identification information from the card searching response; according to a third parameter, a fourth parameter and a high-level command which are respectively set as a first parameter, a second parameter and have the lowest bit as a second preset value, sequentially splicing the first preset byte, the card identification information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command to obtain second splicing data, calculating second selective verification data according to the second splicing data, and splicing the second selective verification data behind the second splicing data to obtain a card selection command.
In this embodiment, the first determining module 03 is specifically configured to obtain card protocol information from the card searching response, determine whether low-nibble data of data on a second byte in the card protocol information is a first preset value, and if so, determine that the smart card is a non-standard smart card; otherwise, the intelligent card is judged to be a standard intelligent card.
In this embodiment, the card reader may further include: declaring a connection module;
the declaration connection module is used for reporting a communication protocol of the card reader to the upper computer after the card reader is powered on, and the card reader is connected with the upper computer;
the first obtaining module 09 is specifically configured to analyze the communication instruction according to a communication protocol between the first obtaining module and the upper computer, and obtain instruction effective data.
The communication protocol comprises the following steps: CCID protocol or HID protocol or SCSI protocol or other communication protocol.
In this embodiment, the first obtaining module 09 is specifically configured to obtain data at a first preset position in the communication instruction, and use the data as an instruction effective data length, obtain data with a length equal to the instruction effective data length from a second preset position of the communication instruction, and use the obtained data as the instruction effective data.
In this embodiment, the instruction start end data includes a fifth parameter, a sixth parameter, and a seventh parameter;
the third organizing module 17 is specifically configured to set, when the sixth parameter and the seventh parameter are both empty, data on a fourth bit and data on a third bit in the fifth parameter as a first preset value, and use the fifth parameter as instruction start end data;
when the sixth parameter and the seventh parameter are not empty, setting data on a fourth bit and data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter, the sixth parameter and the seventh parameter to obtain instruction starting end data;
when the sixth parameter is null and the seventh parameter is not null, setting data on a fourth bit in the fifth parameter to be a second preset value; and setting data on a third bit in the fifth parameter as a first preset value, and sequentially splicing the fifth parameter and the seventh parameter to obtain instruction starting end data.
The present embodiments provide a card reader in communication with a smart card, which may communicate with standard smart cards and with non-standard smart cards.
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 changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention should be protected by the claims.

Claims (22)

1. A method of communicating with a smart card, comprising:
step t 1: the card reader sends a card searching instruction; receiving a card searching response from the smart card; judging the type of the smart card according to the card protocol information in the card searching response, and executing step t2 if the smart card is a non-standard smart card; if the smart card is a standard smart card, executing step t 5;
step t 2: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 3;
step t 3: the card reader waits for receiving a communication instruction from an upper computer, acquires instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, calculates instruction verification data according to the instruction effective data, sequentially splices the instruction effective data and the instruction verification data to obtain a first card communication instruction, and sends the first card communication instruction to the smart card;
step t 4: the card reader receives a first card communication response from the smart card, acquires first response effective data from the first card communication response, organizes the communication response comprising the first response effective data, and returns the communication response to the upper computer; returning to the step t 3;
step t 5: the card reader organizes a card selection command and sends the card selection command to the smart card; receiving a card selection response from the smart card, sending a card on-chip electricity response to the upper computer, and executing step t 6;
step t 6: the card reader waits for receiving a communication instruction from the upper computer, acquires instruction effective data from the communication instruction after receiving the communication instruction from the upper computer, organizes the instruction start end data, calculates instruction verification data according to the instruction start end data and the instruction effective data, sequentially splices the instruction start end data, the instruction effective data and the instruction verification data to obtain a second card communication instruction, and sends the second card communication instruction to the smart card;
step t 7: the card reader receives a second card communication response from the smart card, acquires second response effective data from the second card communication response, organizes the communication response comprising the second response effective data, and returns the communication response to the upper computer; returning to step t 6.
2. The method according to claim 1, wherein the obtaining of the first response valid data from the first card communication response comprises:
and the card reader takes the rest data except the last two bytes of data in the first card communication response as the first response effective data.
3. The method according to claim 1, wherein the obtaining of the second response valid data from the second card communication response comprises: the card reader acquires data on a first byte in the second card communication response, acquires response starting end data according to the data on the first byte in the second card communication response, takes last two bytes of data in the second card communication response as second response verification data, and takes all data between the response starting end data and the second response verification data as second response effective data.
4. The method according to claim 3, wherein the card reader obtains data on a first byte in the second card communication response, and obtains response start data according to the data on the first byte in the second card communication response, specifically: the card reader acquires data on a third bit and data on a fourth bit of a first byte in a second card communication response, and if the data on the third bit and the data on the fourth bit are both a second preset value, the card reader takes the first three bytes in the second card communication response as response starting end data; if the data on the third bit or the data on the fourth bit are both the first preset value, the card reader takes the first byte in the second card communication response as the response starting end data; otherwise, the card reader takes the first two bytes in the card communication response as response starting end data.
5. The method according to claim 1, characterized in that the organization card selection command is in particular:
the card reader acquires card identification information from the card searching response; respectively setting a first parameter, a second parameter, a fourth parameter and a third parameter with the lowest bit as a second preset value, sequentially splicing a first preset byte, the card identification information, the first parameter, the second parameter, the third parameter and the fourth parameter to obtain first spliced data, calculating first selective verification data according to the first spliced data, and splicing the first selective verification data behind the first spliced data to obtain a card selection command.
6. The method of claim 1,
the organization card selection command specifically comprises:
the card reader acquires card identification information from the card searching response; according to a third parameter, a fourth parameter and a high-level command which are respectively set as a first parameter, a second parameter and have the lowest bit as a second preset value, sequentially splicing a first preset byte, the card identification information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command to obtain second splicing data, calculating second selection verification data according to the second splicing data, and splicing the second selection verification data behind the second splicing data to obtain a card selection command.
7. The method according to claim 1, wherein the determining the type of the smart card according to the card protocol information in the card-seeking response specifically comprises:
the card reader acquires card protocol information from the card searching response, judges whether low-nibble data of data on a second byte in the card protocol information is a first preset value or not, and judges that the intelligent card is a non-standard intelligent card if the low-nibble data of the data on the second byte in the card protocol information is the first preset value; otherwise, judging that the smart card is a standard smart card.
8. The method according to claim 1, wherein the obtaining of the command validity data from the communication command comprises: the card reader analyzes the communication instruction according to a communication protocol of the card reader and the upper computer to obtain effective instruction data;
the step t1 is preceded by: the card reader is electrified, a communication protocol of the card reader is reported to the upper computer, and the card reader is connected with the upper computer.
9. The method according to claim 1, wherein the obtaining of the command validity data from the communication command comprises:
and the card reader acquires data at a first preset position in the communication instruction and takes the data as an instruction effective data length, the data with the length being the instruction effective data length is acquired from a second preset position of the communication instruction, and the acquired data is taken as the instruction effective data.
10. The method of claim 8, wherein the communication protocol comprises: CCID protocol or HID protocol or SCSI protocol or other communication protocol.
11. The method of claim 1, wherein the instruction start data comprises a fifth parameter, a sixth parameter, and a seventh parameter;
if the sixth parameter and the seventh parameter are both null, organizing instruction start end data, specifically: setting data on a fourth bit and data on a third bit in the fifth parameter as a first preset value, and taking the fifth parameter as instruction starting end data;
if neither the sixth parameter nor the seventh parameter is null, organizing instruction start end data, specifically: setting data on a fourth bit and data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter, the sixth parameter and the seventh parameter to obtain instruction starting end data;
if the sixth parameter is not null and the seventh parameter is null, organizing instruction start end data, specifically: setting data on a fourth bit in the fifth parameter to be a first preset value; setting data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter and the sixth parameter to obtain instruction starting end data;
if the sixth parameter is null and the seventh parameter is not null, organizing instruction start end data, specifically: setting data on a fourth bit in the fifth parameter to be a second preset value; and setting data on a third bit in the fifth parameter as a first preset value, and sequentially splicing the fifth parameter and the seventh parameter to obtain instruction starting end data.
12. A card reader in communication with a smart card, comprising: the system comprises a first sending module, a first receiving module, a first judging module, a first organizing module, a second sending module, a second receiving module, a first returning module, a third receiving module, a first obtaining module, a first calculating module, a first splicing module, a third sending module, a fourth receiving module, a second obtaining module, a second organizing module, a fourth sending module, a third organizing module, a second splicing module, a fifth sending module, a fifth receiving module, a third obtaining module and a fourth organizing module;
the first sending module is used for sending a card searching instruction;
the first receiving module is used for receiving a card searching response from the intelligent card;
the first judging module is used for judging the type of the intelligent card according to the card protocol information in the card searching response received by the first receiving module;
the first organizing module is used for organizing a card selection command;
the second sending module is used for sending the card selection command organized by the first organization module to the smart card;
the second receiving module is used for receiving a card selection response from the smart card;
the first return module is used for sending the on-chip electric response to the upper computer;
the third receiving module is used for receiving a communication instruction from the upper computer;
the first obtaining module is used for obtaining the instruction effective data from the communication instruction received by the third receiving module;
the first calculation module is used for calculating instruction verification data according to the instruction valid data acquired by the first acquisition module when the first judgment module judges that the type of the smart card is a non-standard smart card;
the first splicing module is used for sequentially splicing the instruction effective data acquired by the first acquisition module and the instruction verification data acquired by the first calculation module to acquire a first card communication instruction;
the third sending module is used for sending the first card communication instruction obtained by the first splicing module to the smart card;
the fourth receiving module is used for receiving a first card communication response from the smart card;
the second obtaining module is used for obtaining first response effective data from the first card communication response received by the fourth receiving module;
the second organization module is used for organizing the communication response comprising the first response effective data;
the fourth sending module is used for returning the communication response organized by the second organization module to the upper computer; and returning the communication response organized by the fourth organization module to the upper computer;
the third organizing module is used for organizing instruction starting end data when the first judging module judges that the smart card is a standard smart card;
the second splicing module is used for calculating instruction check data according to the instruction starting end data and the instruction effective data acquired by the first acquisition module; sequentially splicing the starting end data organized by the third organization module, the instruction effective data acquired by the first acquisition module and the instruction check data organized by the third organization module to obtain a second card communication instruction;
the fifth sending module is configured to send the second card communication instruction obtained by the second splicing module to the smart card;
the fifth receiving module is used for receiving a second card communication response from the smart card;
the third obtaining module is configured to obtain second response valid data from the second card communication response received by the fifth receiving module;
and the fourth organizing module is used for organizing the communication response comprising the second response effective data.
13. The card reader according to claim 12, wherein the second obtaining module is specifically configured to use the remaining data in the first card communication response, except for the last two bytes of data, as the first response valid data.
14. The card reader according to claim 12, wherein the third obtaining module specifically includes: first and second acquisition units
The first obtaining unit is configured to obtain data in a first byte in the second card communication response, and obtain response start end data according to the data in the first byte in the second card communication response;
the second obtaining unit is configured to use last two bytes of data in the second card communication response as second response verification data, and use all data between the response start end data and the second response verification data as second response valid data.
15. The card reader according to claim 14, wherein the first obtaining unit is specifically configured to obtain data at a third bit and data at a fourth bit of a first byte in a second card communication response, and if both the data at the third bit and the data at the fourth bit are a second preset value, the card reader takes the first three bytes in the second card communication response as response start data; if the data on the third bit or the data on the fourth bit are both the first preset value, the card reader takes the first byte in the second card communication response as the response starting end data; otherwise, the card reader takes the first two bytes in the card communication response as response starting end data.
16. The card reader according to claim 12, wherein the first organization module is specifically configured to obtain card identification information from the card-seeking response; respectively setting a first parameter, a second parameter, a fourth parameter and a third parameter with the lowest bit as a second preset value, sequentially splicing a first preset byte, the card identification information, the first parameter, the second parameter, the third parameter and the fourth parameter to obtain first spliced data, calculating first selective verification data according to the first spliced data, and splicing the first selective verification data behind the first spliced data to obtain a card selection command.
17. The card reader according to claim 12, wherein the first organization module is specifically configured to obtain card identification information from the card-seeking response; according to a third parameter, a fourth parameter and a high-level command which are respectively set as a first parameter, a second parameter and have the lowest bit as a second preset value, sequentially splicing a first preset byte, the card identification information, the first parameter, the second parameter, the third parameter, the fourth parameter and the high-level command to obtain second splicing data, calculating second selection verification data according to the second splicing data, and splicing the second selection verification data behind the second splicing data to obtain a card selection command.
18. The card reader according to claim 12, wherein the first determining module is specifically configured to obtain card protocol information from the card-searching response, determine whether low-nibble data of data on a second byte in the card protocol information is a first preset value, and if so, determine that the smart card is a non-standard smart card; otherwise, judging that the smart card is a standard smart card.
19. The card reader of claim 12, further comprising: declaring a connection module;
the declaration connection module is used for reporting a communication protocol of the card reader to an upper computer after the card reader is powered on, and the card reader is connected with the upper computer;
the first acquisition module is specifically used for analyzing the communication instruction according to the communication protocol of the first acquisition module and the upper computer to acquire instruction effective data.
20. The card reader according to claim 12, wherein the first obtaining module is specifically configured to obtain data at a first preset position in the communication command, and use the data as a command effective data length, obtain data with a length equal to the command effective data length from a second preset position of the communication command, and use the obtained data as the command effective data.
21. The card reader of claim 19, wherein the communication protocol comprises: CCID protocol or HID protocol or SCSI protocol or other communication protocol.
22. The card reader of claim 12, wherein the command start data comprises a fifth parameter, a sixth parameter, and a seventh parameter;
the third organizing module is specifically configured to set, when the sixth parameter and the seventh parameter are both empty, data on a fourth bit and data on a third bit in the fifth parameter as a first preset value, and use the fifth parameter as instruction starting end data;
when the sixth parameter and the seventh parameter are not empty, setting data on a fourth bit and data on a third bit in the fifth parameter as a second preset value, and sequentially splicing the fifth parameter, the sixth parameter and the seventh parameter to obtain instruction starting end data;
when the sixth parameter is null and the seventh parameter is not null, setting data on a fourth bit in the fifth parameter to a second preset value; and setting data on a third bit in the fifth parameter as a first preset value, and sequentially splicing the fifth parameter and the seventh parameter to obtain instruction starting end data.
CN201811593916.7A 2018-12-25 2018-12-25 Method for communicating with smart card and card reader Active CN109684888B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811593916.7A CN109684888B (en) 2018-12-25 2018-12-25 Method for communicating with smart card and card reader

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811593916.7A CN109684888B (en) 2018-12-25 2018-12-25 Method for communicating with smart card and card reader

Publications (2)

Publication Number Publication Date
CN109684888A CN109684888A (en) 2019-04-26
CN109684888B true CN109684888B (en) 2021-09-07

Family

ID=66189499

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811593916.7A Active CN109684888B (en) 2018-12-25 2018-12-25 Method for communicating with smart card and card reader

Country Status (1)

Country Link
CN (1) CN109684888B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101587533A (en) * 2009-03-31 2009-11-25 北京飞天诚信科技有限公司 Card reader and card reading method thereof
CN106326797A (en) * 2016-08-19 2017-01-11 飞天诚信科技股份有限公司 Non-contact type card and working method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103310175B (en) * 2013-06-24 2016-01-20 飞天诚信科技股份有限公司 A kind of method of work of the many draw-in grooves card reader based on standard CC ID agreement

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101587533A (en) * 2009-03-31 2009-11-25 北京飞天诚信科技有限公司 Card reader and card reading method thereof
CN106326797A (en) * 2016-08-19 2017-01-11 飞天诚信科技股份有限公司 Non-contact type card and working method

Also Published As

Publication number Publication date
CN109684888A (en) 2019-04-26

Similar Documents

Publication Publication Date Title
US9411990B2 (en) Working method of a multi-slot card reader based on the standard CCID protocol
US20090235037A1 (en) Method and device for customizing a portable electronic entity
US9491166B2 (en) Apparatus and method for authenticating smart card
JP6516133B2 (en) Communication device and communication system
CN108288008B (en) Card activation method and device
JP3863011B2 (en) Combination type IC card, control method therefor, and system program therefor
CN113361293A (en) Card swiping method, card controller, electronic device and storage medium
US10931331B2 (en) Communication device and method
CN109684888B (en) Method for communicating with smart card and card reader
US9010649B2 (en) IC card, portable electronic device, and reader/writer
US9542632B2 (en) IC card, portable electronic device, and reader/writer
CN1794848B (en) Data synchronization control method between a user equipment and a user authentication card and a corresponding user authentication card
EP3365833B1 (en) A method performed by an electronic device capable of communicating with a reader with improved self-testing
US7930458B2 (en) USB memory card reader having memory card identification
JP2005011147A (en) Ic card and ic card program
US9070065B2 (en) IC card, portable electronic apparatus, and controlling method of IC card
KR101455539B1 (en) Ic card and ic card control method
CN110334550B (en) Smart card and method for protecting privacy data thereof
JP7293669B2 (en) Electronic information storage medium, IC card, communication method and communication program
CN102930306B (en) Identify the method for IC-card logic appointment, terminal and system
CN114186574A (en) Intelligent student card communication method based on near field communication
CN1756154B (en) Digital signature method
Östling Intelligent Name Cardwith RFID technology
JPH09231112A (en) Ic card

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