CN101719212B - Identification method and device of serial-port card reader - Google Patents

Identification method and device of serial-port card reader Download PDF

Info

Publication number
CN101719212B
CN101719212B CN2009102424498A CN200910242449A CN101719212B CN 101719212 B CN101719212 B CN 101719212B CN 2009102424498 A CN2009102424498 A CN 2009102424498A CN 200910242449 A CN200910242449 A CN 200910242449A CN 101719212 B CN101719212 B CN 101719212B
Authority
CN
China
Prior art keywords
serial
card reader
drives
card
deck
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
CN2009102424498A
Other languages
Chinese (zh)
Other versions
CN101719212A (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
Beijing 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 CN2009102424498A priority Critical patent/CN101719212B/en
Publication of CN101719212A publication Critical patent/CN101719212A/en
Application granted granted Critical
Publication of CN101719212B publication Critical patent/CN101719212B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Transfer Systems (AREA)

Abstract

The invention discloses identification method and device of a serial-port card reader, belonging to the field of IC card readers. An operating system loads a serial-port bus driver; the serial-port bus driver sends a querying command to a serial port, receives a response message returned by the serial port and establishes corresponding physical equipment objects for a card holder of the card reader connected with the serial port according to the response message; the operating system installs a corresponding type function driver for each physical equipment object and adds new equipment records in smart card service; and the serial-port bus driver sends a card holder state querying command to the card reader connected with the serial port, receives a returned card holder state message and sends the returned card holder state message to the function driver.

Description

The recognition methods of serial-port card reader and device
Technical field
IC-card card reader of the present invention field, particularly a kind of recognition methods of serial-port card reader and device.
Background technology
IC (Integrated Circuit, integrated circuit) card is another the novel information instrument that occurs after magnetic card.It is a microelectronic chip to be embedded meet in the card base of ISO 7816 standards, makes card form.At present, IC-card has been widely applied to a lot of fields such as finance, traffic, social security, and for example, the bus card that we often use is exactly a kind of of IC-card.
IC-card read write line (abbreviation card reader) is the bridge between IC-card and application system, is referred to as IFD (Interface Device, interfacing equipment) in the ISO international standard.General common IC-card adopts radio-frequency technique and IFD to carry out communication, and promptly the CPU in the IFD links to each other with IC-card by an interface circuit and communicates.Wherein, the IC-card interface circuit is a vital part in the IC-card read write line, according to the difference of real application systems, can select parallel communications, half duplex series communication and different IC-card read-write chip such as I2C communicates by letter.
In realizing process of the present invention, the inventor finds that there is following shortcoming at least in prior art:
The IC-card read write line can connect with the computer application system by serial communication interface (claiming serial ports again), but in the process that connects, owing to the characteristic of serial ports itself, can't realize the plug-and-play feature of serial-port card reader.
Summary of the invention
In order to realize the plug-and-play feature of serial-port card reader, the invention provides a kind of method and apparatus of discerning serial-port card reader.Described technical scheme is as follows:
A kind of recognition methods of serial-port card reader, described method comprises:
Operating system loads serial bus and drives, and described operating system drives with serial ports by described serial bus and communicates;
Described serial bus drives to described serial ports and sends the inquiry instruction, and receive the response message that described serial ports returns, described inquiry instruction is used for inquiring the device type of the card reader deck that is connected with described serial ports, carries the device type and the number of deck in the card reader that is connected with described serial ports in the described response message;
Described serial bus drives according to described response message, the deck of the card reader that connects for described serial ports is created the corresponding physical device object, and the function that described operating system is installed respective type for each physical device object drives and the new equipment records of interpolation in the smart card service;
Described serial bus drives to the card reader that is connected with described serial ports and sends inquiry deck status command, and receives the deck status information of returning;
Described serial bus drives described deck status information is sent to described function driving;
Described operating system loads serial bus and drives, and drives and serial communication by described serial bus, specifically comprises:
Operating system loads serial bus and drives;
Described serial bus drives the plug and play readjustment notice of registration serial ports kind equipment;
Serial port drive is found serial ports, and creates serial port drive example apparatus object, by the plug and play manager described serial port drive example apparatus object is returned to described serial bus and drives;
Described serial bus drives judges whether described serial port drive example apparatus object is correct;
If correct, then described serial bus drives creates the serial ports object, communicates with described serial ports;
If incorrect, then do not operate.
Whether preserve marking equipment state information during described serial bus drives, being used for sign has equipment to be connected with serial ports.
After the response message that the described serial ports of described reception returns, described method also comprises:
Described serial bus drives and judges whether to receive at the appointed time the response message that described serial ports returns;
If, then continue to carry out described serial bus and drive according to described response message, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, judge whether to take place the equipment pull action;
When the pull action of the equipment of generation, revising described marking equipment state information is no equipment connection status;
When the equipment pull action does not take place when, end operation.
After the response message that the described serial ports of described reception returns, described method also comprises:
Described serial bus drives judges whether the card reader that is connected with described serial ports is new equipment;
If, then revise described marking equipment state information for the equipment connection status is arranged, to carry out described serial bus and drive according to described response message, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, then carry out the described step that sends inquiry deck status command to the card reader that is connected with described serial ports.
Preserve the deck status identifier during described serial bus drives, described deck status identifier is used to identify the deck state of the card reader that is connected with described serial ports object, and described deck state comprises: have card to power on, have card not power on and do not have card.
Described serial bus drives and receives after the described deck status information, and described method also comprises:
Judge whether described deck status information changes;
If change, then revise the deck status identifier of preserving in the described serial port drive bus after, carry out that described deck status information is sent to the step that described function drives;
If do not change, end operation then.
Described serial bus drives described deck status information is sent to after described function drives, and described method also comprises: when described deck status information for card arranged having powered on or when having card not power on, described function driving generation card operational order;
Whether described function drives the communication channel of judging between described serial bus driving and the described card reader occupied;
If then described serial bus drives hangs up described card operational order, waits for that communication channel is not occupied;
If not, then described serial bus drives described card operational order is sent to described card reader, and receives the operational order execution result that described card reader is returned, and returns to described function and drives.
Described function drives and generates the card operational order, specifically comprises:
Described function drives the card operation requests that the upper layer application of described operating system is imported into and encapsulates, and is packaged into the card operational order that meets CCID protocol massages form.
Whether described function drives the communication channel of judging between described serial bus driving and the described card reader occupied, specifically comprises:
Described function drives and monopolizes the mutex of communication channel to described operating system application;
If apply for successfully, then described communication channel is unoccupied;
If the application failure, then described communication channel is occupied.
Described serial bus drives described card operational order is sent to described card reader, and receives the operational order execution result that described card reader is returned, and returns to described function and drives, and specifically comprises:
Described serial bus drives and receives described card operational order, and according to the regulation of serial ports transmission protocol message form described card operational order is encapsulated, and sends to described card reader by corresponding serial ports then;
Described card reader is operated card accordingly according to described operational order after the operational order that receives is resolved;
Described card reader encapsulates the execution result of described operational order, sends to described serial bus and drives;
Described serial bus drives and drives sending to described function after the described execution result parsing.
A kind of recognition device of serial-port card reader, described device comprises:
Load-on module is used to load serial bus and drives, and operating system drives with serial ports by described serial bus and communicates;
First transceiver module, be used for sending the inquiry instruction to described serial ports, and receive the response message that described serial ports returns, described inquiry instruction is used for inquiring the device type of the card reader deck that is connected with described serial ports, carries the device type and the number of deck in the card reader that is connected with described serial ports in the described response message;
Creation module, be used for the response message that receives according to described first transceiver module, the deck of the card reader that connects for described serial ports is created the corresponding physical device object, and the function that described operating system is installed respective type for each physical device object drives and the new equipment records of interpolation in the smart card service;
Second transceiver module is used for sending inquiry deck status command to the card reader that is connected with described serial ports, and receives the deck status information of returning;
The 3rd transceiver module is used for that described deck status information is sent to described function and drives;
Described load-on module specifically comprises:
Loading unit is used to load serial bus and drives;
Registering unit, the plug and play readjustment that is used for the serial ports kind equipment is notified;
Creating unit is used to find serial ports, and creates serial port drive example apparatus object, by the plug and play manager described serial port drive example apparatus object is returned to described serial bus and drives;
Judging unit is used to judge whether described serial port drive example apparatus object is correct;
If correct, then described serial bus drives creates the serial ports object, communicates with described serial ports;
If incorrect, then do not operate.
Described device also comprises: first preserves module, is used to preserve marking equipment state information, and whether be used for sign has equipment to be connected with serial ports.
Described device also comprises:
The response message judge module is used to judge whether to receive at the appointed time the response message that described serial ports returns;
If then described creation module is carried out the response message that receives according to described first transceiver module, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, judge whether to take place the equipment pull action;
When the pull action of the equipment of generation, it is no equipment connection status that the described first preservation module is revised described marking equipment state information;
When the equipment pull action does not take place when, end operation.
Described device also comprises:
The new equipment judge module is used to judge whether the card reader that is connected with described serial ports is new equipment;
If, then described first preserves module revises described marking equipment state information for the equipment connection status is arranged, described creation module is carried out described serial bus and is driven according to described response message, and the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, then second transceiver module is carried out the described step that sends inquiry deck status command to the card reader that is connected with described serial ports.
Described device also comprises: second preserves module, be used to preserve the deck status identifier, described deck status identifier is used to identify the deck state of the card reader that is connected with described serial ports object, and described deck state comprises: have card to power on, have card not power on and do not have card.
Described device also comprises:
The deck condition judgment module is used to judge whether described deck status information changes;
If change, after the then described second preservation module was revised the deck status identifier of preserving in the described serial port drive bus, described the 3rd transceiver module sent to the step that described function drives with described deck status information;
If do not change, end operation then.
Described device also comprises:
Generate instruction module, be used for when described deck status information for card arranged having powered on or when having card not power on, described function driving generation card operational order;
The communication port judge module is used to judge whether the communication channel between described serial bus driving and the described card reader is occupied;
Execution module if the judged result that is used for described communication port judge module is then hung up described card operational order for being, waits for that communication channel is not occupied; If the judged result of described communication port judge module then sends to described card operational order described card reader, and receives the operational order execution result that described card reader is returned for not, return to described function and drive.
Described generation instruction module specifically is used for:
The card operation requests that the upper layer application of described operating system is imported into encapsulates, and is packaged into the card operational order that meets CCID protocol massages form.
Described communication port judge module specifically is used for: monopolize the mutex of communication channel to described operating system application;
If apply for successfully, then described communication channel is unoccupied;
If the application failure, then described communication channel is occupied.
The beneficial effect that the technical scheme that the embodiment of the invention provides is brought is:
By a kind of method and apparatus of discerning serial-port card reader is provided, can make serial-port card reader on the serial ports of main frame, realize plug and play, not only inherit the advantage of serial ports but also possessed the convenient characteristics of plug and play, do not need in the implementation procedure existing serial-port card reader is carried out any modification, can also support the serial ports multiple card-base card reader.
Description of drawings
Fig. 1 is the preliminary work process flow diagram in the recognition methods of a kind of serial-port card reader of providing in the embodiment of the invention 1;
Fig. 2 is the illustrative view of functional configuration that a kind of serial bus that provides in the embodiment of the invention 1 drives;
Fig. 3 is the recognition methods process flow diagram of a kind of serial-port card reader of providing in the embodiment of the invention 1;
Fig. 4 is a means of communication process flow diagram in the recognition methods of a kind of serial-port card reader of providing in the embodiment of the invention 1;
Fig. 5 is the structural representation of the recognition device of a kind of serial-port card reader of providing in the embodiment of the invention 2.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, embodiment of the present invention is described further in detail below in conjunction with accompanying drawing.
Embodiment 1
The embodiment of the invention 1 provides a kind of method of discerning serial-port card reader, in the method, is executive agent with the computing machine, and sets the serial bus driving that reader device has been installed in this computing machine in advance, and referring to Fig. 1, this method comprises:
Step 101: operating system loads serial bus and drives;
Need to prove that the serial bus that loads in the step 101 drives can be as shown in Figure 2, wherein, the main application that serial bus drives is: 1, the reading card device carries out poll, establishment equipment and drives the reporting equipment state variation to function; 2, the card operational order that driving generates to function encapsulates according to the regulation of serial ports transmission protocol message form; 3, the mutual exclusion transmitting-receiving between the instruction of operational order and poll; 4, support many draw-in grooves card reader.
Step 102: serial bus drives the plug and play readjustment notice to plug and play manager registration serial ports kind equipment;
Particularly, receive the plug and play readjustment notice of this serial ports type equipment when the plug and play manager after, whether the operating system inspection exists serial ports.
Step 103: operating system is found to load serial port drive behind the serial ports;
Step 104: serial port drive is that the serial ports of each discovery is created serial port drive example apparatus object, and returns to the serial bus driving by the serial port drive example apparatus object that the plug and play manager is created serial port drive;
Wherein, if the serial port drive of operating system has been found a plurality of serial ports, then create a plurality of corresponding serial ports and drive the example apparatus object, and a plurality of serial port drive instance objects are returned to the serial bus driving one by one by the plug and play manager;
When having a plurality of serial ports in the main frame, can use COM1, COM2 etc. to distinguish respectively.Wherein, COM is COMmunication, the abbreviation of communication.
Step 105: serial bus drives the parameter that receives readjustment;
Wherein, the parameter of readjustment is specially the serial port drive example apparatus object that serial port drive is created.
Step 106: whether serial bus drives the parameter of judging readjustment correct;
If correct, then execution in step 107;
If incorrect, then do not operate.
Wherein, judge whether the parameter of readjustment correctly is specifically as follows: whether the serial port drive example apparatus object that serial bus driving judgement receives and the serial ports of operating system appointment mate, if coupling, then Hui Tiao parameter is correct; If do not match, then Hui Tiao parameter is incorrect;
Serial bus drives according to the number of times of readjustment and judges COM1 or COM2 (being COM1 for the first time, then is COM2 for the second time), and comprehensive then registry information judges whether to use current serial ports; That specify use in the judgement registration table is COM1 or COM2.
Step 107: serial bus drives creates the serial ports object.
Wherein, it is corresponding with the serial port drive example apparatus object of serial port drive establishment that serial bus drives the serial ports object of creating.
After the completing steps 107, promptly finished the preliminary work of the method for identification serial-port card reader.After preliminary work was finished, serial bus drove the mode with poll, sent the inquiry instruction every fixing a period of time to the serial ports object, and this inquiry instruction is used to check the insertion whether serial-port card reader equipment is arranged or extract.Because the corresponding relation between serial ports object and the serial port drive example apparatus object, serial port drive can be handed down to corresponding serial ports with this inquiry instruction.Referring to Fig. 3, the poll that serial bus drives is specially:
Step 301: serial bus drives to serial ports and sends the inquiry instruction;
Wherein, concrete inquiry instruction can for: 0x1b 01 00 77 78 00;
Need to prove, serial bus drives the regulation that the inquiry instruction that sends to serial ports need be followed serial communication protocol, first byte 0x1b of instruction is the downlink command head of serial communication protocol regulation, represents that this instruction is downlink command, promptly drives the instruction that is handed down to serial ports by serial bus; The 2nd byte in the instruction and the 3rd byte representation should instruction in the length of data of encapsulation, the low byte of the 2nd byte representation data length wherein, the high byte of the 3rd byte representation data length; The data that encapsulate in the instruction are to the 3rd byte reciprocal since the 4th byte; The instruction the 1st byte of inverse and the second-to-last byte be the instruction verification and, obtain by the 2nd byte data of instruction to the 3rd byte data addition reciprocal, wherein, last byte be presentation directives's verification and high byte, the instruction verification of second-to-last byte representation and low byte.
Wherein, the 4th byte 0x77 of this inquiry instruction represents to inquire deck device type in the card reader.
Step 302: serial bus drives and judges whether to receive at the appointed time the information that serial ports returns;
If then execution in step 303;
If not, execution in step 311 then.
Wherein, if connecting reader device on the current serial ports, then after card reader receives the inquiry instruction of serial bus driving transmission, whether verification should instruct correct, and to serial bus driving back-checking result, the data in the check results can represent that result that this inquiry instruction is carried out is success or failure.For example:
0,xb1 01 00 00 01 00 represents successfully
0,xb1 01 00 01 02 00 expression checksum errors
0,xb1 01 00 02 03 00 expression data lengths surpass 271
0,xb1 01 00 03 04 00 expression command header are incorrect
Wherein, if card reader verification inquiry instruction is correct, when the back-checking result was correct, card reader also will drive the execution result (being response message) of link order to serial bus.Concrete, response message can for: 0,xb1 01 00 43 44 00.In this response message, comprised the type identification of deck, wherein, 0xb1 is the up-on command head of serial communication protocol regulation, 0x43 represents that this card reader deck type is the C type.
If this card reader is a multiple card-base card reader, then response message can be 0,xb1 03 00 43 43 53 dc 00, represents that the deck type of three decks of this card reader is respectively C type, C type and S type.
Step 303: serial bus drives and judges whether to receive response message;
If then execution in step 304;
If not then execution in step 311.
Step 304: serial bus drives judges whether the equipment that is currently connected to serial ports is new equipment;
If, execution in step 305;
If not, execution in step 306.
Concrete, in serial bus drives, exist one to be used to represent the whether marking equipment state information of connection device of current serial ports, serial bus drives this marking equipment state information of renewal behind each poll.
Serial bus drives according to this marking equipment state information judges whether the equipment that is currently connected to serial ports is new equipment; If marking equipment state information is no equipment connection status, then can judge the equipment that is currently connected to serial ports is new equipment, and the modification marking equipment state is the existing device connection status behind end of polling(EOP).
Step 305: serial bus drives analyzes the response message that card reader is returned, and creates smart card device in main frame;
Wherein, serial bus drive to be analyzed the response message of the inquiry instruction that card reader returns, and according to deck type and the number in the response message, creates smart card device in main frame, detailed process can for:
(1) serial bus drives the deck establishment corresponding physical device object for card reader;
Here need to prove that serial bus drives deck type and the deck number according to card reader, for creating corresponding physical device object.
(2) operating system is installed the function driving of respective type for each physical device object;
Here need to prove that the operating system of main frame is installed for the physical device object of having created and value-added tax function drives, each function drives the smart card Driver Library of a standard of registration.Wherein, operating system is that the function of the smart card device of the pairing deck installation of each physical device object respective type drives (being called for short function drives), and each function drives the smart card Driver Library of registering a standard.Here, the smart card Driver Library is used to provide the framework of a standard that the service controller of function driving and smart card service is carried out alternately.
Need to prove that also the smart card service can comprise service controller, explorer and database.Wherein, service controller be used to manage the smart card service, receive the request that drives from function, management resource manager etc.; Explorer is used for adding new smart card device record or deleting existing smart card device record etc. at database.
(3) in the smart card service of main frame, add new equipment records.
Wherein, the smart card Driver Library that the smart card service drives and registers according to the function that loads is created new smart card device record in the explorer of smart card service.
Step 306: serial bus drives to card reader and sends inquiry deck status command;
Wherein, inquiry deck status command is specifically as follows: 0x b1 0a 00 65 00 00 00 00 00 77 00 00 00 e6 00;
Judge that by response message this card reader is a multiple card-base card reader if serial bus drives, then serial bus drives the instruction that generates with the same number of inquiry deck of deck state and sends to card reader.With card reader 3 decks being arranged is example, the instruction that serial bus drives three inquiry deck states that send to card reader respectively can for:
No. 1 deck state of 0x b10a 00 65 00 00 00 00 00 77 00 00 00 e6,00 expression inquiry
No. 2 deck states of 0x b10a 00 65 00 00 00 00 01 78 00 00 00 e8,00 expression inquiry
No. 3 deck states of 0x b10a 00 65 00 00 00 00 02 79 00 00 00 ea, 00 expression inquiry
Wherein, the 9th byte representation deck numbering of the instruction of inquiry deck state, on behalf of No. 1 deck, 01,00 represent deck No. 2, and by that analogy.
Need to prove, in serial bus drives, preserve a deck status identifier, be used for preserving the state of card reader deck, upgrade this deck status identifier behind each poll; If card reader is a multiple card-base card reader, can preserve a plurality of deck status identifiers during then serial bus drives, corresponding one by one with deck in the card reader.The deck status identifier can comprise three values, and is corresponding with three states of deck in the card reader respectively, is respectively: have card not power on, have card to power on, do not have card.
Step 307: serial bus drives and receives the deck status information that card reader is returned;
The deck status information of returning can be instruction: 0xb1 0a 00 81 00 00 00 00 00 a1 00 00 00 2c 01;
Wherein, the state of the 11st byte representation deck of instruction, wherein, 0x00 represents to have that card powers on, the 0x01 sign has that card does not power on, 0x02 represents not have card.Therefore, in above-mentioned concrete instruction, the deck state powers on for card is arranged.
Step 308: serial bus drives judges according to the deck status information whether corresponding deck state change has taken place;
If change execution in step 309;
If do not change execution in step 310;
Wherein, deck state that carries in the use deck status information and serial bus drive the deck status identifier of preserving and compare, if different, then change has taken place the deck state; If identical, then the deck state does not change.
Step 309: serial bus drives and upgrades corresponding deck status identifier, and drives the variation of the corresponding deck state of report to function;
Step 310: serial bus drives an end of polling(EOP) of reading card device;
Step 311: serial bus drives judges whether serial equipment disconnects connection;
If then execution in step 312;
If not, execution in step 310 then.
Wherein, serial bus drives and judges according to the marking equipment state information of its storage inside whether serial equipment disconnects connection; If marking equipment state information is the existing device connection status, then can judge serial equipment and disconnect connection, i.e. the equipment of serial ports connection is extracted.
Step 312: serial bus drives to operating system report serial equipment and disconnects connection, and execution in step 310 after the status indicator information of updating the equipment;
Wherein, serial bus drives and revises marking equipment state information is no equipment connection status, and has disconnected connection to operating system report serial equipment, corresponding apparatus record in the driving of operating system offloading functions, the deletion system.
After the serial bus driving finds that by poll serial-port card reader also connects with it, serial bus drives receiving function and drives the card operational order that sends, and send to card reader after the card operational order encapsulated, receive the instruction execution result that card reader returns and resolve after pass to function and drive; Perhaps, according to the setting of time counter, regularly send the inquiry instruction, carry out poll to card reader.
When the poll that drives by serial bus when main frame is found to have card reader to be connected with it by serial ports, behind end of polling(EOP), can carry out following operation, referring to Fig. 4:
Step 401: the upper layer application of main frame sends the card operation requests and drives to function;
Particularly, the upper layer application of main frame is called the smart card service according to PCSC (Personal Computer/Smart Card) consensus standard, and drives the transmit operation request to function.
Step 402: function drives and generates the card operational order;
Concrete, function drives the card operation requests that the main frame upper layer application is sent and encapsulates, be packaged into the card operational order that meets CCID (USBChip/Smart Card Interface Devices-USB, chip intelligent card equipment) protocol massages form.If card reader is a multiple card-base card reader, then correspondingly use the 6th this function of byte representation to drive the numbering of pairing card reader deck according to the message format of CCID agreement, 0x00 represents that No. 1 deck, 0x01 represent deck No. 2, and by that analogy.
For example, function drives and receives the random number request of the getting 0,x00 84 00 00 08 that upper layer application produces, function drive to use the instruction head (0x6f 05 00 00 00 00 10 00 00 00) of CCID protocol massages format specification that the random number request of getting that receives is encapsulated, and the card operational order that obtains getting random number is 0x6f 05 00 00 00 00 10 00 00 00 00 84 00 00 08.
Step 403: whether function drives the communication channel of judging between serial bus driving and the card reader occupied;
If then execution in step 404;
If not, execution in step 405 then.
In embodiments of the present invention, because driving, serial bus constantly serial ports is carried out poll, therefore, need to make poll instruction and card operational order mutual exclusion ground, transmitting-receiving in an orderly manner in main frame and card reader communication process, this process can be driven by serial bus and control.Be after function drives generation card instruction manipulation, can monopolize the mutex of communication channel to this function driving of operating system application sign, make function drive and drive hair card operational order under card reader by serial bus, carry out the transmitting-receiving etc. of mutual, the instruction of data with card reader, and finishing after the release mutex;
Perhaps, after serial bus drove and generates the inquiry instruction, communication channel was special-purpose mutex in operating system application sign polling procedure, discharges mutex behind the end of polling(EOP).
Thus, judge communication channel whether occupied method can for: whether arbitration functions drives can successfully obtain mutex;
If function drives and can successfully obtain mutex, illustrate that then communication channel does not have occupied or is in idle condition;
Obtain the mutex failure if function drives, illustrate that then communication channel is occupied.
Step 404: serial bus drives the instruction suspends that this function is driven, and after the wait mutex was released, this function drives obtained mutex;
If obtain success, then execution in step 405;
If obtain unsuccessfully, continue to wait for that then mutex is released.
For example, the deck state in the current card reader is that card powers on, and what function drove that one of encapsulation meets CCID protocol massages form gets random number instruction 0x6f 05 00 00 00 00 10 00 00 00 00 84 00 00 08; But at current time, serial bus drives and just carries out poll at the reading card device, because mutex is occupied, function drives obtains the mutex failure, then this is got the random number instruction suspends, wait for after serial bus drives end of polling(EOP) discharging mutex, obtain mutex more again, after obtaining successfully, execution in step 405.
Step 405: serial bus drives receiving function and drives the card operational order that generates, and preserves mutex;
After function drives and to obtain the mutex success, drive to serial bus and to send the card operational order that generates, and, mutex is saved in serial bus drives, discharge mutex after driving the execution result that receives this instruction when serial bus.
Step 406: serial bus drives and sends to card reader after the card operational order that the function driving that receives is generated encapsulates;
Wherein, serial bus drives and the function that receives to be driven the card operational order that meets CCID protocol massages form that generates encapsulates according to the regulation of serial ports transmission protocol message form, sends to card reader by serial ports then.
For example, serial bus drives and encapsulates getting the random number instruction, the data that promptly before this instruction, add 3 bytes, be the downlink command head 0x1b of serial ports transmission protocol message format specification, the low byte of instruction length and the high byte of instruction length successively, and after this instruction, add the data of 2 bytes, be respectively verification and low byte and verification and high byte, after the encapsulation get random number instruction can for: 0x6f 05 00 00 00 00 10 00 00 00 00 84 00 00 08
Step 407: card reader is resolved the operational order that receives;
In embodiments of the present invention, card reader is resolved the instruction that receives, remove the part of serial ports transmission protocol message format specification in this instruction, obtain the instruction of CCID protocol massages form, if this instruction is not upper and lower electricity instruction, then further the instruction head of preceding 10 bytes of CCID protocol massages format specification is removed, obtain function APDU (Application Protocol Data Unit Application Protocol Data Unit).
For example, card reader is separated the random number instruction 0x6f 05 00 00 00 00 10 00 00 00 00 84 00 00 08 that extracts, obtain the instruction of CCID protocol massages form: 0x6f 05 00 00 00 00 10 00 00 00 00 84 00 00 08, because this instruction is not power on instruction or electricity instruction down, then card reader is further resolved and is obtained function APDU:0x00 84 00 00 08.
Step 408: card reader is operated card accordingly according to the instruction that parses, and the instruction after maybe will resolving is handed down to card;
Wherein, after the card reader parsing obtained the instruction of CCID protocol massages form, if this instruction is power on instruction or electricity instruction down, then card reader powered on to corresponding card and operates or electricity operation down; Perhaps function APDU is sent to the corresponding card in the card reader.
For example, if the operational order that main frame parses is 0,x62 08 00 00 00 00 00 00 00 00, according to the format specification of CCID protocol massages as can be known this instruction be the card instruction that powers on, so, card reader according to this instruction to the operation that powers on of the card of appointment.
Step 409: card reader encapsulates the execution result of instruction, sends to serial bus and drives;
For example, the card in the card reader is complete get the random number instruction after, the instruction execution result that returns to card reader is: 0x2111 ca 2b 2e bb 20 05 90 00; The instruction execution result that card reader is returned card according to the regulation of CCID protocol massages form is carried out the encapsulation first time, obtains: 0,x21 11 ca 2b 2e bb 20 05 90 00; Then, card reader according to the regulation of serial ports transmission protocol message form add up-on command head 0xb1 and instruction length, verification and, the instruction execution result after obtaining encapsulating is: 0,xb1 14 00 80 0a 00 00 00 00 10 00 00 00 21,11c,a2b,2eb,b20,059,000 73 03.
Step 410: serial bus drives issues the function driving after the instruction execution result that card reader is returned is resolved.
Serial bus drives the instruction execution result that card reader is returned and resolves according to the serial ports host-host protocol, and the result that parsing is obtained passes to the function driving.
The embodiment of the invention provides a kind of method of discerning serial-port card reader, can make serial-port card reader on the serial ports of main frame, realize plug and play, not only inherit the advantage of serial ports but also possessed the convenient characteristics of plug and play, do not need in the implementation procedure existing serial-port card reader is carried out any modification, can also support the serial ports multiple card-base card reader in addition.
Embodiment 2
The embodiment of the invention 2 provides a kind of device of discerning serial-port card reader, and referring to Fig. 5, this device comprises:
Load-on module 501 is used to load serial bus and drives, and operating system drives with serial ports by serial bus and communicates;
First transceiver module 502, be used for sending the inquiry instruction to serial ports, and receive the response message that serial ports returns, the inquiry instruction is used for inquiring the device type of the card reader deck that is connected with serial ports, carry in the response message with card reader that serial ports is connected in the device type and the number of deck;
Creation module 503, be used for the response message that receives according to first transceiver module, the deck of the card reader that connects for serial ports is created the corresponding physical device object, and the function that operating system is installed respective type for each physical device object drives and the new equipment records of interpolation in the smart card service;
Second transceiver module 504 is used for sending inquiry deck status command to the card reader that is connected with serial ports, and receives the deck status information of returning;
The 3rd transceiver module 505 is used for that the deck status information is sent to function and drives.
Wherein, load-on module 501 specifically comprises:
Loading unit is used to load serial bus and drives;
Registering unit, the plug and play readjustment that is used for the serial ports kind equipment is notified;
Creating unit is used to find serial ports, and creates serial port drive example apparatus object, by the plug and play manager serial port drive example apparatus object is returned to serial bus and drives;
Judging unit is used to judge whether serial port drive example apparatus object is correct;
If correct, then serial bus drives and creates the serial ports object, communicates with serial ports;
If incorrect, then do not operate.
Further, this device also comprises:
First preserves module, is used to preserve marking equipment state information, and whether be used for sign has equipment to be connected with serial ports.
Further, this device also comprises:
The response message judge module is used to judge whether receive the response message that serial ports returns at the appointed time;
If then first transceiver module 502 is carried out the step that receives the response message that serial ports return;
If not, judge whether to take place the equipment pull action;
When the pull action of the equipment of generation, it is no equipment connection status that the first preservation module is revised marking equipment state information;
When the equipment pull action does not take place when, end operation.
Further, this device also comprises:
The new equipment judge module is used to judge whether the card reader that is connected with serial ports is new equipment;
If, then first preserve module modification marking equipment state information for the equipment connection status is arranged, creation module 503 executive operating system serial bus drive according to response message, and the deck of the card reader that connects for serial ports is created the step of corresponding physical device object;
If not, then second transceiver module 504 is carried out the step that sends inquiry deck status command to the card reader that is connected with serial ports.
Further, this device also comprises:
Second preserves module, is used to preserve the deck status identifier, and the deck status identifier is used to identify the deck state of the card reader that is connected with the serial ports object, and the deck state comprises: have card to power on, have card not power on and do not have card.
Further, this device also comprises:
The deck condition judgment module is used to judge whether the deck status information changes;
If change, after then the second preservation module was revised the deck status identifier of preserving in the serial port drive bus, the 3rd transceiver module sent to the step that function drives with the deck status information;
If do not change, end operation then.
Further, this device also comprises:
Generate instruction module, be used for when the deck status information for card arranged having powered on or when having card not power on, function driving generation card operational order;
The communication port judge module is used to judge whether the communication channel between serial bus driving and the card reader is occupied;
Execution module if the judged result that is used for the communication port judge module is then hung up the card operational order for being, waits for that communication channel is not occupied; If the judged result of communication port judge module then sends to the card operational order card reader for not, and receive the operational order execution result that card reader is returned, return to function and drive.
Wherein, generating instruction module specifically is used for:
The card operation requests that the upper layer application of operating system is imported into encapsulates, and is packaged into the card operational order that meets CCID protocol massages form.
Wherein, the communication port judge module specifically is used for: mutex from communication channel to the operating system application that monopolize;
If apply for that successfully, then communication channel is unoccupied;
If the application failure, then communication channel is occupied.
The embodiment of the invention provides a kind of device of discerning serial-port card reader, can make serial-port card reader on the serial ports of main frame, realize plug and play, not only inherit the advantage of serial ports but also possessed the convenient characteristics of plug and play, do not need in the implementation procedure existing serial-port card reader is carried out any modification, can also support the serial ports multiple card-base card reader in addition.
Below only be preferred embodiment of the present invention, or not within the spirit and principles in the present invention not all in order to restriction the present invention, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (19)

1. the recognition methods of a serial-port card reader is characterized in that, described method comprises:
Operating system loads serial bus and drives, and described operating system drives with serial ports by described serial bus and communicates;
Described serial bus drives to described serial ports and sends the inquiry instruction, and receive the response message that described serial ports returns, described inquiry instruction is used for inquiring the device type of the card reader deck that is connected with described serial ports, carries the device type and the number of deck in the card reader that is connected with described serial ports in the described response message;
Described serial bus drives according to described response message, the deck of the card reader that connects for described serial ports is created the corresponding physical device object, and the function that described operating system is installed respective type for each physical device object drives and the new equipment records of interpolation in the smart card service;
Described serial bus drives to the card reader that is connected with described serial ports and sends inquiry deck status command, and receives the deck status information of returning;
Described serial bus drives described deck status information is sent to described function driving;
Described operating system loads serial bus and drives, and drives and serial communication by described serial bus, specifically comprises:
Operating system loads serial bus and drives;
Described serial bus drives the plug and play readjustment notice of registration serial ports kind equipment;
Serial port drive is found serial ports, and creates serial port drive example apparatus object, by the plug and play manager described serial port drive example apparatus object is returned to described serial bus and drives;
Described serial bus drives judges whether described serial port drive example apparatus object is correct;
If correct, then described serial bus drives creates the serial ports object, communicates with described serial ports;
If incorrect, then do not operate.
2. the recognition methods of serial-port card reader as claimed in claim 1 is characterized in that, preserves marking equipment state information during described serial bus drives, and whether be used for sign has equipment to be connected with serial ports.
3. the recognition methods of serial-port card reader as claimed in claim 2 is characterized in that, in the time of response message that the described serial ports of described reception returns, described method also comprises:
Described serial bus drives and judges whether to receive at the appointed time the response message that described serial ports returns;
If, then continue to carry out described serial bus and drive according to described response message, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, judge whether to take place the equipment pull action;
When the pull action of the equipment of generation, revising described marking equipment state information is no equipment connection status;
When the equipment pull action does not take place when, end operation.
4. the recognition methods of serial-port card reader as claimed in claim 2 is characterized in that, after the response message that the described serial ports of described reception returns, described method also comprises:
Described serial bus drives judges whether the card reader that is connected with described serial ports is new equipment;
If, then revise described marking equipment state information for the equipment connection status is arranged, to carry out described serial bus and drive according to described response message, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, then carry out the described step that sends inquiry deck status command to the card reader that is connected with described serial ports.
5. the recognition methods of serial-port card reader as claimed in claim 1, it is characterized in that, during driving, preserves described serial bus the deck status identifier, described deck status identifier is used to identify the deck state of the card reader that is connected with described serial ports object, and described deck state comprises: have card to power on, have card not power on and do not have card.
6. the recognition methods of serial-port card reader as claimed in claim 5 is characterized in that, described serial bus drives and receives after the described deck status information, and described method also comprises:
Judge whether described deck status information changes;
If change, then revise the deck status identifier of preserving in the described serial port drive bus after, carry out that described deck status information is sent to the step that described function drives;
If do not change, end operation then.
7. the recognition methods of serial-port card reader as claimed in claim 1, it is characterized in that, described serial bus driving sends to described deck status information after the described function driving, described method also comprises: when described deck status information for card arranged having powered on or when having card not power on, described function driving and generates the card operational order;
Whether described function drives the communication channel of judging between described serial bus driving and the described card reader occupied;
If then described serial bus drives hangs up described card operational order, waits for that communication channel is not occupied;
If not, then described serial bus drives described card operational order is sent to described card reader, and receives the operational order execution result that described card reader is returned, and returns to described function and drives.
8. the recognition methods of serial-port card reader as claimed in claim 7 is characterized in that, described function drives and generates the card operational order, specifically comprises:
Described function drives the card operation requests that the upper layer application of described operating system is imported into and encapsulates, and is packaged into the card operational order that meets CCID protocol massages form.
9. the recognition methods of serial-port card reader as claimed in claim 7 is characterized in that, whether described function drives the communication channel of judging between described serial bus driving and the described card reader occupied, specifically comprises:
Described function drives and monopolizes the mutex of communication channel to described operating system application;
If apply for successfully, then described communication channel is unoccupied;
If the application failure, then described communication channel is occupied.
10. the recognition methods of serial-port card reader as claimed in claim 7, it is characterized in that described serial bus drives described card operational order is sent to described card reader, and receives the operational order execution result that described card reader is returned, return to described function and drive, specifically comprise:
Described serial bus drives and receives described card operational order, and according to the regulation of serial ports transmission protocol message form described card operational order is encapsulated, and sends to described card reader by corresponding serial ports then;
Described card reader is operated card accordingly according to described operational order after the operational order that receives is resolved;
Described card reader encapsulates the execution result of described operational order, sends to described serial bus and drives;
Described serial bus drives and drives sending to described function after the described execution result parsing.
11. the recognition device of a serial-port card reader is characterized in that, described device comprises:
Load-on module is used to load serial bus and drives, and operating system drives with serial ports by described serial bus and communicates;
First transceiver module, be used for sending the inquiry instruction to described serial ports, and receive the response message that described serial ports returns, described inquiry instruction is used for inquiring the device type of the card reader deck that is connected with described serial ports, carries the device type and the number of deck in the card reader that is connected with described serial ports in the described response message;
Creation module, be used for the response message that receives according to described first transceiver module, the deck of the card reader that connects for described serial ports is created the corresponding physical device object, and the function that described operating system is installed respective type for each physical device object drives and the new equipment records of interpolation in the smart card service;
Second transceiver module is used for sending inquiry deck status command to the card reader that is connected with described serial ports, and receives the deck status information of returning;
The 3rd transceiver module is used for that described deck status information is sent to described function and drives;
Described load-on module specifically comprises:
Loading unit is used to load serial bus and drives;
Registering unit, the plug and play readjustment that is used for the serial ports kind equipment is notified;
Creating unit is used to find serial ports, and creates serial port drive example apparatus object, by the plug and play manager described serial port drive example apparatus object is returned to described serial bus and drives;
Judging unit is used to judge whether described serial port drive example apparatus object is correct;
If correct, then described serial bus drives creates the serial ports object, communicates with described serial ports;
If incorrect, then do not operate.
12. the recognition device of serial-port card reader as claimed in claim 11 is characterized in that, described device also comprises: first preserves module, is used to preserve marking equipment state information, and whether be used for sign has equipment to be connected with serial ports.
13. the recognition device of serial-port card reader as claimed in claim 12 is characterized in that, described device also comprises:
The response message judge module is used to judge whether to receive at the appointed time the response message that described serial ports returns;
If then described creation module is carried out the response message that receives according to described first transceiver module, the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, judge whether to take place the equipment pull action;
When the pull action of the equipment of generation, it is no equipment connection status that the described first preservation module is revised described marking equipment state information;
When the equipment pull action does not take place when, end operation.
14. the recognition device of serial-port card reader as claimed in claim 12 is characterized in that, described device also comprises:
The new equipment judge module is used to judge whether the card reader that is connected with described serial ports is new equipment;
If, then the first preservation module is revised described marking equipment state information for the equipment connection status is arranged, described creation module is carried out described serial bus and is driven according to described response message, and the deck of the card reader that connects for described serial ports is created the step of corresponding physical device object;
If not, then second transceiver module is carried out the described step that sends inquiry deck status command to the card reader that is connected with described serial ports.
15. the recognition device of serial-port card reader as claimed in claim 11, it is characterized in that, described device also comprises: second preserves module, be used to preserve the deck status identifier, described deck status identifier is used to identify the deck state of the card reader that is connected with described serial ports object, and described deck state comprises: have card to power on, have card not power on and do not have card.
16. the recognition device of serial-port card reader as claimed in claim 15 is characterized in that, described device also comprises:
The deck condition judgment module is used to judge whether described deck status information changes;
If change, after the then described second preservation module was revised the deck status identifier of preserving in the described serial port drive bus, described the 3rd transceiver module sent to the step that described function drives with described deck status information;
If do not change, end operation then.
17. the recognition device of serial-port card reader as claimed in claim 11 is characterized in that, described device also comprises:
Generate instruction module, be used for when described deck status information for card arranged having powered on or when having card not power on, described function driving generation card operational order;
The communication port judge module is used to judge whether the communication channel between described serial bus driving and the described card reader is occupied;
Execution module if the judged result that is used for described communication port judge module is then hung up described card operational order for being, waits for that communication channel is not occupied; If the judged result of described communication port judge module then sends to described card operational order described card reader, and receives the operational order execution result that described card reader is returned for not, return to described function and drive.
18. the recognition device of serial-port card reader as claimed in claim 17 is characterized in that, described generation instruction module specifically is used for:
The card operation requests that the upper layer application of described operating system is imported into encapsulates, and is packaged into the card operational order that meets CCID protocol massages form.
19. the recognition device of serial-port card reader as claimed in claim 17 is characterized in that, described communication port judge module specifically is used for: monopolize the mutex of communication channel to described operating system application;
If apply for successfully, then described communication channel is unoccupied;
If the application failure, then described communication channel is occupied.
CN2009102424498A 2009-12-11 2009-12-11 Identification method and device of serial-port card reader Active CN101719212B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2009102424498A CN101719212B (en) 2009-12-11 2009-12-11 Identification method and device of serial-port card reader

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2009102424498A CN101719212B (en) 2009-12-11 2009-12-11 Identification method and device of serial-port card reader

Publications (2)

Publication Number Publication Date
CN101719212A CN101719212A (en) 2010-06-02
CN101719212B true CN101719212B (en) 2011-10-05

Family

ID=42433785

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2009102424498A Active CN101719212B (en) 2009-12-11 2009-12-11 Identification method and device of serial-port card reader

Country Status (1)

Country Link
CN (1) CN101719212B (en)

Families Citing this family (6)

* 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
CN104484292B (en) * 2014-12-30 2017-08-11 飞天诚信科技股份有限公司 A kind of drive device and its method of work suitable for serial equipment
CN104811359B (en) * 2015-04-10 2018-12-07 深圳市元征科技股份有限公司 A kind of serial port communication method and terminal
CN108153696B (en) * 2017-12-29 2020-04-10 广州市中海达测绘仪器有限公司 Embedded system serial port module matching method, device, medium and computer equipment
CN113360443B (en) * 2021-05-31 2022-07-08 浪潮电子信息产业股份有限公司 Serial port card communication realization method, device, equipment and readable storage medium
CN113378150A (en) * 2021-06-22 2021-09-10 疯壳(深圳)科技有限公司 Autonomous identification and connection method and system for serial port terminal equipment

Also Published As

Publication number Publication date
CN101719212A (en) 2010-06-02

Similar Documents

Publication Publication Date Title
CN101719212B (en) Identification method and device of serial-port card reader
US9111466B2 (en) Efficient access to connectivity information using cable identification
US8346991B2 (en) Multi-function peripheral device, corresponding method and electronic system having a peripheral and a host communicating via a single interface
CN102388596B (en) Method of detecting a NFC device emulating several contactless cards which may use a plurality of protocols
CN100474857C (en) Method for information interaction between host computer and smart card
US9851703B2 (en) Method for managing the dialogue between an item of equipment and at least one multi-application object
US9491166B2 (en) Apparatus and method for authenticating smart card
CN101859395A (en) Information transmission realization method and system, main control equipment and intelligent card
CN107926075A (en) The system and method for supporting the data communication under isomerous environment
CN101699416B (en) Communication method and system between host computer and card reader with multiple card holders
CN104517146A (en) NFC tag, communication method and system
KR20130132780A (en) Method and system of communicating personal health data in a near field communication environment
CN100468440C (en) Method and device for information interaction between host and smart card
CN1960276B (en) Remote control system and method
US8775709B2 (en) Method for recognizing a card reader with multiple card holders and method for communicating between a host and the card reader and system thereof
US20110197203A1 (en) Communication device, communication method and program
CN105612531A (en) Network access method, RFID tag, electronic device, and control system
CN104426715A (en) Distributed testing tool control method
CN101771720A (en) Scanning discovery method for active management technical terminal
JP2015500537A (en) Security information interaction system, apparatus and method based on extended parameter collection
CN101086763A (en) A collaborative working RFID reader and its collaborative work method
US9252843B2 (en) Method and apparatus for data transmission
CN101876951B (en) Recognition method of multiple card-base card reader and communication method of host computer and multiple card-base card reader
CN109889280B (en) NFC equipment safety test method
CN105117761A (en) Label information processing method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant