CN104268605A - Card reader operating intelligent SD cards and ordinary SD cards and working method thereof - Google Patents

Card reader operating intelligent SD cards and ordinary SD cards and working method thereof Download PDF

Info

Publication number
CN104268605A
CN104268605A CN201410413476.8A CN201410413476A CN104268605A CN 104268605 A CN104268605 A CN 104268605A CN 201410413476 A CN201410413476 A CN 201410413476A CN 104268605 A CN104268605 A CN 104268605A
Authority
CN
China
Prior art keywords
card
card reader
instruction
data
response data
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.)
Granted
Application number
CN201410413476.8A
Other languages
Chinese (zh)
Other versions
CN104268605B (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 CN201410413476.8A priority Critical patent/CN104268605B/en
Publication of CN104268605A publication Critical patent/CN104268605A/en
Application granted granted Critical
Publication of CN104268605B publication Critical patent/CN104268605B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Credit Cards Or The Like (AREA)

Abstract

The invention discloses a card reader operating intelligent SD cards and ordinary SD cards and a working method of the card reader, and belongs to the field of communications. The method includes the steps that the card reader sends a binding instruction to a card, data in an assigned address are read, and if the read data are the same with the binding instruction, a card mark is set to be an ordinary SD card mark; a set interrupt mark is detected, the card reader obtains data in a USB storage when the set interrupt mark is a USB receive data mark, the instruction type of the obtained data is judged, if the data are an intelligent SD card communication instruction, the card reader communicates with the card, and if the data are a storage channel instruction, corresponding operations are carried out according to the card mark and the storage channel instruction. By the adoption of the method, the card reader can carry out data read-write operation on ordinary SD cards and can also issue an instruction to operate intelligent SD cards.

Description

The card reader of a kind of operative intelligence SD card and common SD card and method of work thereof
Technical field
The present invention relates to the communications field, particularly the card reader of a kind of operative intelligence SD card and common SD card and method of work thereof.
Background technology
At present, along with the development of science and technology, being used widely of smart mobile phone and digital product, SD card is as a kind of storage card of based semiconductor flash technology, because it has Large Copacity, high-performance, safety, read or write speed up to features such as 2M/ seconds, now become most widely used a kind of storage card in smart mobile phone and digital product.SD card is divided into intelligent SD card and two kinds, common SD card, wherein, has intelligent chip in intelligent SD card, has gathered and to have carried out data with equipment and store data two parts function; Common SD card only possesses the function storing data;
The present inventor finds, in prior art, intelligent SD card can only be applied to smart mobile phone or digital product, cannot be operated by card reader.
Summary of the invention
In order to solve the defect existed in prior art, the present invention proposes the method for work of the card reader of a kind of operative intelligence SD card and common SD card, comprising:
Step S1: described card reader carries out initialization, is set to intelligent SD card mark by card mark, reads the data in assigned address, and using the data that read as Backup Data;
Step S2: described card reader sends binding instruction to card, the data that described card returns are read from described assigned address, judge that whether the data that described card returns are identical with described binding instruction, that described card mark is set to common SD card mark, described Backup Data is write in described assigned address, the configuration information of definition scsi interface, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of described scsi interface is sent to described host computer, and performs step S3; Otherwise the configuration information of definition CCID interface and the configuration information of scsi interface, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of described CCID interface and the configuration information of described scsi interface are sent to described host computer, and performs step S3;
Step S3: described card reader judges whether the interrupt identification that there is set, the interrupt identification of if there is no set, then return step S3; If there is the interrupt identification of set, then judge the type of the interrupt identification of described set, if the interrupt identification of described set is USB receive Data Labels, then obtain the data in USB storage, and the data got are judged, if intelligent SD card communication instruction, then perform step S4; If memory channel instruction, then perform step S5;
Step S4: described card reader communicates with described card according to described intelligent SD card communication instruction, reads communication response from described card, and described communication response is sent to described host computer, returns step S3;
Step S5: described card reader, according to described card mark and described memory channel instruction, judges whether to perform described memory channel instruction, is, perform described memory channel instruction, return step S3; Otherwise return step S3.
In described step S2, after the configuration information of described card reader definition scsi interface, also comprise: the enable USB of described card reader connects;
In described step S2, described card reader also comprises after defining the configuration information of CCID interface and the configuration information of scsi interface: the enable USB of described card reader connects;
Before described step S3, also comprise:
Step S3-1: described card reader is carried out USB and enumerated, judges whether USB interface is connection status, is, performs described step S3; Otherwise return step S3-1.
Described card reader carries out initialization, comprising: draw-in groove state is set to without card by described card reader;
Described step S3, also comprises:
If the interrupt identification of described set snaps into bit flag, described card reader performs following steps:
Step a1: described card reader is draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then performs step a2; If without card, then perform step a3;
Step a2: described card reader sends to host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and returns step S3;
Step a3: described card reader sends without card response to host computer, and described draw-in groove state is saved as without card, returns step S3.
Described intelligent SD card communication instruction is the instruction that powers on;
Described step S4, is specially:
Step c1: described card reader sends binding instruction to described card;
Step c2: described card reader reads binding response data from described card, sends open command to described card;
Step c3: described card reader reads and disconnects response data from described card, sends link order to described card;
Step c4: described card reader reads connection response data from described card, sends to described card and obtains ATR instruction;
Step c5: described card reader reads ATR response data from described card, sends described ATR response data to described host computer, returns step S3.
Described card reader carries out initialization, also comprises: the first reading times reset;
Described step c2, comprising:
Step c2-1: described card reader time delay Preset Time, reads binding response data, upgrades described first reading times from described card;
Step c2-2: described card reader judges whether described first reading times is less than preset value, is perform step c2-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c2-3: described card reader judges whether successfully to read described binding response data, is perform step c2-4; Otherwise return step c2-1;
Step c2-4: described first reading times resets by described card reader, sends open command to described card, performs step c3.
Described card reader carries out initialization, comprising: the second reading times reset;
Described step c3 comprises:
Step c3-1: described card reader time delay Preset Time, reads and disconnects response data, upgrade described second reading times from described card;
Step c3-2: described card reader judges whether described second reading times is less than preset value, is perform step c3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c3-3: described card reader judges whether successfully to read described disconnection response data, is perform step c3-4; Otherwise return step c3-1;
Step c3-4: described second reading times resets by described card reader, sends link order to described card, performs step c4.
Described card reader is carried out initialization and is comprised: third reading is got number of times and reset;
Described step c4, specifically comprises:
Step c4-1: described card reader time delay Preset Time, reads connection response data, upgrades described third reading and get number of times from described card;
Step c4-2: described card reader judges that described third reading is got number of times and whether is less than preset value, is perform step c4-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c4-3: described card reader judges whether successfully to read described connection response data, is perform step c4-4; Otherwise return step c4-1;
Step c4-4: described third reading is got number of times and reset by described card reader, sends to described card and obtains ATR instruction, perform step c5.
Described card reader carries out initialization, comprising: the 4th reading times reset;
Described step c5 comprises:
Step c5-1: described card reader time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times;
Step c5-2: described card reader judges whether described 4th reading times is less than preset value, is perform step c5-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c5-3: described card reader judges whether successfully to read described ATR response data, is perform step c5-4; Otherwise return step c5-1;
Step c5-4: described 4th reading times resets by described card reader, sends described ATR response data, return step S3 to described host computer.
Described intelligent SD card communication instruction is lower electric instruction;
Described step S4, is specially:
Steps d 1: described card reader sends open command to described card;
Steps d 2: described card reader reads and disconnects response data from described card, sends to described card and unlocks binding instruction;
Steps d 3: described card reader reads and unlocks binding response data from described card, sends lower electric successful information to described host computer, returns step S3.
Described card reader is carried out initialization and is comprised: the 5th reading times reset;
Described steps d 3 comprises:
Steps d 3-1: described card reader time delay Preset Time, reads described unblock binding response data, upgrades described 5th reading times from described card;
Steps d 3-2: described card reader judges whether described 5th reading times is less than preset value, is perform steps d 3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Steps d 3-3: described card reader judges whether successfully to read described unblock binding response data, is perform steps d 3-4; Otherwise return steps d 3-1;
Steps d 3-4: described 5th reading times resets by described card reader, sends lower electric successful information to described host computer, returns step S3.
Described card reader is carried out initialization and is comprised: the 6th reading times reset;
Described intelligent SD card communication instruction is exchanges data instruction;
Described step S4, is specially:
Step b1: described card reader sends to described card and obtains APDU instruction;
Step b2: described card reader time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times;
Step b3: described card reader judges whether described 6th reading times is less than preset value, is perform step b4; Otherwise send to described host computer and read failure information, return step S3;
Step b4: described card reader judges whether successfully to read described APDU response data, is perform step b5; Otherwise return step b2;
Step b5: described 6th reading times resets by described card reader, described APDU response data is sent to described host computer, returns step S3.
Described card reader, according to described card mark and described memory channel instruction, judges whether to perform described memory channel instruction, is specially:
Described card reader obtains the data in the first default byte of described memory channel instruction, it can be used as destination address, if described destination address is described assigned address, and described card mark is intelligent SD card mark, then perform described memory channel instruction, return step S3; Otherwise return step S3.
Described card reader performs described memory channel instruction and specifically comprises:
Step e1: described card reader judges the type of described memory channel instruction according to second of described memory channel instruction the data preset in byte, if read operation instruction, then performs step e2; If write operation instruction, then perform step e3;
Step e2: described card reader reads the data in described destination address, and send it to described host computer, return step S3;
Step e3: described card reader obtains the data in the 3rd default byte of described memory channel instruction, it can be used as data length to be written, data to be written are obtained according to next byte of described data length to be written 3rd default byte from described memory channel instruction, and write in described destination address, send write operation to described host computer and complete information, return step S3.
A method of work for the card reader of operative intelligence SD card and common SD card, comprising:
Step W1: card reader carries out initialization, the configuration information of definition CCID interface and the configuration information of scsi interface, when described card reader receives the configuration information instruction of the acquisition interface that host computer issues, the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer;
Step W2: described card reader judges whether the interrupt identification that there is set, the interrupt identification of if there is no set, then return step W2; If there is the interrupt identification of set, then judge the type of the interrupt identification of described set, if the interrupt identification of described set is USB receive Data Labels, then perform step W3; If the interrupt identification of described set is other marks, then performs corresponding operating, return step W2;
Step W3: described card reader obtains the data in USB storage, judges the interface of the data received in described USB storage, if first interface, then performs step W4; If the second interface, then perform step W5;
Step W4: described card reader performs corresponding operating according to the configuration information of scsi interface to the data in described USB storage, and generating run code, send described operational code to described host computer, return step W2;
Step W5: described card reader communicates with card according to the data in described USB storage, reads communication response from described card, and described communication response is sent to described host computer, returns step W2.
Between described W1 and step W2, comprising: the enable USB of described card reader connects;
In described step W2, described card reader judges whether the interrupt identification that there is set, and before judging the type of the interrupt identification of set, also comprises:
Step W2-1: described card reader is carried out USB and enumerated, judges whether USB interface is connection status, is, described card reader judges whether the interrupt identification that there is set, and judges the type of the interrupt identification of set; Otherwise return step W2-1.
Described card reader carries out initialization, comprising: draw-in groove state be set to without card;
When the type of the interrupt identification of described set is when snapping into bit flag, described card reader performs following steps:
Step k1: described card reader is draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then performs step k2; If without card, then perform step k3;
Step k2: described card reader sends to described host computer has card to respond, and described draw-in groove state has been saved as card do not power on, return step W2;
Step k3: described card reader sends without card response to described host computer, and described draw-in groove state is saved as without card, returns step W2.
Data in described USB storage are the instruction that powers on;
Described step W5, is specially:
Step m1: described card reader sends binding instruction to card;
Step m2: described card reader reads binding response data from described card, sends open command to described card;
Step m3: described card reader reads and disconnects response data from described card, sends link order to described card;
Step m4: described card reader reads connection response data from described card, sends to described card and obtains ATR instruction;
Step m5: described card reader reads ATR response data from described card, sends described ATR response data to described host computer, returns step W2.
Described card reader carries out initialization, comprising: the first reading times reset;
Described step m2 comprises:
Step m2-1: described card reader time delay Preset Time, reads binding response data, upgrades described first reading times from described card;
Step m2-2: described card reader judges whether described first reading times is less than preset value, is perform step m2-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m2-3: described card reader judges whether successfully to read described binding response data, is perform step m2-4; Otherwise return step m2-1;
Step m2-4: described first reading times resets by described card reader, sends open command to described card, performs step m3.
Described card reader carries out initialization, comprising: the second reading times reset;
Described step m3 comprises:
Step m3-1: described card reader time delay Preset Time, reads and disconnects response data, upgrade described second reading times from described card;
Step m3-2: described card reader judges whether described second reading times is less than preset value, is perform step m3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m3-3: described card reader judges whether successfully to read described disconnection response data, is perform step m3-4; Otherwise return step m3-1;
Step m3-4: described second reading times resets by described card reader, sends link order to described card, performs step m4.
Described card reader carries out initialization, comprising: third reading is got number of times and reset;
Described step m4 comprises:
Step m4-1: described card reader time delay Preset Time, reads connection response data, upgrades described third reading and get number of times from described card;
Step m4-2: described card reader judges that described third reading is got number of times and whether is less than preset value, is perform step m4-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m4-3: described card reader judges whether successfully to read described connection response data, is perform step m4-4; Otherwise return step m4-1;
Step m4-4: described third reading is got number of times and reset by described card reader, sends to described card and obtains ATR instruction, perform step m5.
Described card reader carries out initialization, comprising: the 4th reading times reset;
Described step m5 comprises:
Step m5-1: described card reader time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times;
Step m5-2: described card reader judges whether described 4th reading times is less than preset value, is perform step m5-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m5-3: described card reader judges whether successfully to read described ATR response data, is perform step m5-4; Otherwise return step m5-1;
Step m5-4: described 4th reading times resets by described card reader, sends described ATR response data, return step W2 to described host computer.
Data in described USB storage are lower electric instruction;
Described step W5, is specially:
Step n1: described card reader sends open command to card;
Step n2: described card reader reads and disconnects response data from described card, sends to described card and unlocks binding instruction;
Step n3: described card reader reads and unlocks binding response data from described card, sends lower electric successful information to described host computer, returns step W2.
Described card reader is carried out initialization and is comprised: the 5th reading times reset;
Described step n3 comprises:
Step n3-1: described card reader time delay Preset Time, reads described unblock binding response data, upgrades described 5th reading times from described card;
Step n3-2: described card reader judges whether described 5th reading times is less than preset value, is perform step n3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step n3-3: described card reader judges whether described unblock binding response data reads successfully, is perform step n3-4; Otherwise return step n3-1;
Step n3-4: described 5th reading times resets by described card reader, sends lower electric successful information to described host computer, returns step W2.
Described card reader is carried out initialization and is comprised: the 6th reading times reset;
Data in described USB storage are exchanges data instruction;
Described step W5, is specially:
Step l1: described card reader sends to described card and obtains APDU instruction;
Step l2: described card reader time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times;
Step l3: described card reader judges whether described 6th reading times is less than preset value, is perform step l4; Otherwise send to described host computer and read failure information, return step W2;
Step l4: described card reader judges whether described APDU response data reads successfully, is perform step l5; Otherwise return step l2;
Step l5: described 6th reading times resets by described card reader, described APDU response data is sent to described host computer, returns step W2.
A card reader for operative intelligence SD card and common SD card, comprising:
Initialization module, for carrying out initialization, is set to intelligent SD card mark by card mark;
Read module, for reading the data in assigned address, and using the data that read as Backup Data, and triggers the first processing module;
First processing module, for sending binding instruction to card, reading the data that described card returns, and triggering the first judge module from described assigned address;
Whether the first judge module is identical with described binding instruction for judging the data that described card returns;
Second processing module, during for judging that the data that described card returns are identical with described binding instruction at described first judge module, described card mark is set to common SD card mark, described Backup Data is write in described assigned address, the configuration information of definition scsi interface, and trigger the first configuration information sending module;
First configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the configuration information of described scsi interface, and detection trigger module;
3rd processing module, during for judging that the data that described card returns are not identical with described binding instruction at described first judge module, the configuration information of definition CCID interface and the configuration information of scsi interface, and trigger the second configuration information sending module;
Second configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and detection trigger module;
Detection module, for judging whether the interrupt identification that there is set, and judges the type of the interrupt identification of set;
First acquisition module, for judging at described detection module the interrupt identification that there is set, and when the interrupt identification of described set is USB reception Data Labels, obtains the data in USB storage, and triggers the second judge module;
Second judge module, judges for the data got described first acquisition module;
4th processing module, when data for judging to get at described second judge module are intelligent SD card communication instruction, communicate with described card according to described intelligent SD card communication instruction, communication response is read from described card, and described communication response is sent to described host computer, and trigger described detection module;
3rd judge module, for judge at described second judge module the data got as memory channel instruction time, judge whether to perform described memory channel instruction according to described card mark and described memory channel instruction;
5th processing module, for when described 3rd judge module judges to perform described memory channel instruction, performs described memory channel instruction, and triggers described detection module.
Also comprise:
First enable module, for described card mark being set to common SD card mark in described second processing module, described Backup Data is write in described assigned address, when defining the configuration information of scsi interface, enable USB connects, and triggers the first configuration information sending module;
Second enable module, for when the configuration information of the configuration information of described 3rd processing module definition CCID interface and scsi interface, enable USB connects, and triggers the second configuration information sending module;
4th judge module, for when the configuration information of described scsi interface is sent to described host computer by described first configuration information sending module, carry out USB and enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module; When the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described second configuration information sending module, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module.
Described initialization module, also for draw-in groove state being set to without card;
Also comprise: the second acquisition module, for the interrupt identification that there is set being detected at described detection module, and when the interrupt identification of described set is for snapping into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sending to described host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and triggers described detection module; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, and trigger described detection module.
4th processing module, comprising:
First binding submodule, for the data that judge to get at described second judge module as power on instruction time, send binding instruction to card, read from described card and bind response data, and trigger the first disconnection submodule;
First disconnects submodule, for sending open command to described card, reading and disconnecting response data, and trigger the first connexon module from described card;
First connexon module, for sending link order to described card, reading connection response data, and triggering the first acquisition ATR submodule from described card;
First obtains ATR submodule, obtaining ATR instruction, reading ATR response data from described card, sending ATR response data, and trigger described detection module to described host computer for sending to described card.
Described initialization module, for resetting the first reading times;
Described first binding submodule, comprising:
First sends binding command unit, for the data that judge to get at described second judge module as power on instruction time, send to described card and bind instruction, time delay Preset Time, from described card, read binding response data, upgrade described first reading times, and trigger the first judging unit;
First judging unit, for judging whether described first reading times is less than preset value;
Second judging unit, for when described first judging unit judges that described first reading times is less than preset value, judges whether successfully to read described binding response data;
First zero unit, for when described second judging unit judges successfully to read described binding response data, resets described first reading times, and triggers the first disconnection submodule.
Described initialization module, also for the second reading times being reset;
Described first disconnects submodule, comprising:
First sends open command unit, for sending open command to described card, time delay Preset Time, reading and disconnecting response data, upgrade described second reading times, and trigger the 3rd judging unit from described card;
3rd judging unit, for judging whether described second reading times is less than preset value;
4th judging unit, for when described 3rd judging unit judges that described second reading times is less than preset value, judges whether successfully to read described disconnection response data;
Second zero unit, for when described 4th judging unit judges successfully to read described disconnection response data, resets described second reading times, and triggers the first connexon module.
Described initialization module, also resets for third reading being got number of times;
Described first connexon module, specifically comprises:
First sends link order unit, for sending link order time delay Preset Time to described card, reading connection response data, upgrading described third reading and get number of times, and trigger the 5th judging unit from described card;
5th judging unit, for judging that described third reading is got number of times and whether is less than preset value;
6th judging unit, at described 5th judging unit, judges that described third reading gets number of times when being less than preset value, judges whether successfully to read described connection response data;
3rd zero unit, for when described 6th judging unit judges successfully to read described connection response data, gets number of times and resets, and trigger the first acquisition ATR submodule by described third reading.
Described initialization module, also for the 4th reading times being reset;
Described first obtains ATR submodule, specifically comprises:
First sends acquisition ATR command unit, and obtain ATR instruction for sending to described card, time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times, and triggers the 7th judging unit;
7th judging unit, for judging whether described 4th reading times is less than preset value;
8th judging unit, for when described 7th judging unit judges that described 4th reading times is less than preset value, judges whether successfully to read described ATR response data;
4th zero unit, for when described 8th judging unit judges successfully to read described ATR response data, resets described 4th reading times, sends ATR response data, and trigger described detection module to described host computer.
Described 4th processing module, comprising:
Second disconnects submodule, when the data for judging to get at described second judge module are lower electric instruction, sends open command to card, reads and disconnect response data from described card, and triggers the first unblock binding submodule;
First unlocks binding submodule, unlocking binding instruction, reading and unlocking binding response data from described card for sending to described card, sends lower electric successful information, and trigger described detection module to described host computer.
Described initialization module, for resetting the 5th reading times;
Described first unlocks binding submodule, comprising:
First sends unblock binding command unit, unlocks binding instruction, time delay Preset Time for sending to described card, and from described card, reading unlocks binding response data, upgrades described 5th reading times, and triggers the 9th judging unit;
9th judging unit, for judging whether described 5th reading times is less than preset value;
Tenth judging unit, for when described 9th judging unit judges that described 5th reading times is less than preset value, judges whether successfully to read described unblock binding response data;
5th zero unit, during for judging at described tenth judging unit successfully to read described unblock binding response data, resetting described 5th reading times, sending lower electric successful information, and trigger described detection module to described host computer.
Described initialization module, also for the 6th reading times being reset;
Described card reader also comprises:
6th processing module, specifically for when intelligent SD card communication instruction is exchanges data instruction described in described 4th processing module, sends to described card and obtains APDU instruction, and trigger the 7th processing module;
7th processing module, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the 5th judge module;
5th judge module, for judging whether described 6th reading times is less than preset value;
6th judge module, for when described 5th judge module judges that described 6th reading times is less than preset value, judges whether APDU response data reads successfully;
8th processing module, for when described 6th judge module judges that APDU response data reads successfully, resets described 6th reading times, described APDU response data is sent to described host computer, and detection trigger module.
Described 3rd judge module, specifically for obtaining described memory channel instruction first presets the data in byte, it can be used as destination address, if described destination address is described assigned address, and described card mark is intelligent SD card mark, then determine to perform described memory channel instruction; Otherwise determine to perform described memory channel instruction.
Described 5th processing module, specifically comprises:
5th processing module judges submodule, for when described 3rd judge module judges to perform described memory channel instruction, judges the type of described memory channel instruction according to the second data preset in byte of described memory channel instruction;
5th processing module read operation module, for when described 5th processing module judges that submodule judges that memory channel instruction is read operation instruction, reads the data in described destination address, and sends it to described host computer, and trigger described detection module;
5th processing module write operation module, for when described 5th processing module judges that submodule judges that memory channel instruction is write operation instruction, obtain the data in the 3rd default byte of described memory channel instruction, it can be used as data length to be written, data to be written are obtained according to next byte of described data length to be written 3rd default byte from described memory channel instruction, and write in described destination address, send write operation to described host computer and complete information, and trigger described detection module.
A card reader for operative intelligence SD card and common SD card, comprising:
Initial mark module, for carrying out initialization, the configuration information of definition CCID interface and the configuration information of scsi interface;
Interface configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and triggering judges interrupt module;
Judging interrupt module, for judging whether the interrupt identification that there is set, and judging the type of the interrupt identification of set;
First interruption processing module, for judging at described judgement interrupt module the interrupt identification that there is set, and when the interrupt identification of set is USB reception Data Labels, obtains the data in USB storage, and triggers the first judgement interface module;
First judges interface module, for judging the interface of the data received in described USB storage;
First interface processing module, for when described first judges that interface module judges that the interface of the data received in USB storage is first interfaces, corresponding operating is performed according to the data in the described USB storage of the configuration information of described scsi interface, and generating run code, send described operational code to host computer, and trigger described judgement interrupt module;
Second interface processing module, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, communicate with card according to the data in described USB storage, communication response is read from described card, and described communication response is sent to host computer, and trigger described judgement interrupt module.
Also comprise:
Enable link block, for carrying out initialization in described initial mark module, during the configuration information of the configuration information of definition CCID interface and scsi interface, enable USB connects, and trigger interface configuration information sending module;
Enumerate judge module, for when the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described interface configuration information sending module, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, triggers and judge interrupt module.
Described initial mark module, also for draw-in groove state being set to without card;
Also comprise: operational module, for judging at described judgement interrupt module the interrupt identification that there is set, and when the interruption of set is designated and snaps into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sending to described host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and triggers described judgement interrupt module; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, trigger described judgement interrupt module.
Described second interface processing module, comprising:
First decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
First instruction process submodule, for judge at described first decision instruction type submodule data in described USB storage as power on instruction time, send binding instruction to card, from described card, read binding response data, and trigger the second instruction process submodule;
Second instruction process submodule, for sending open command to described card, reading and disconnecting response data, and triggering the 3rd instruction process submodule from described card;
3rd instruction process submodule, for sending link order to described card, reading connection response data, and triggering the 4th instruction process submodule from described card;
4th instruction process submodule, obtaining ATR instruction for sending to described card, reading ATR response data, sending described ATR response data to described host computer, and trigger described judgement interrupt module from described card.
Described initial mark module, also for the first reading times being reset;
Described first instruction process submodule, comprising:
First sends binding command unit, for the first decision instruction type submodule judge data in described USB storage as power on instruction time, binding instruction is sent to described card, time delay Preset Time, binding response data is read from described card, upgrade described first reading times, and trigger the first judging unit;
First judging unit, for judging whether described first reading times is less than preset value;
Second judging unit, for when described first judging unit judges that described first reading times is less than preset value, judges whether successfully to read described binding response data;
First zero unit, for when described second judging unit judges successfully to read described binding response data, resets described first reading times, and triggers the second instruction process submodule.
Described initial mark module, also for the second reading times being reset;
Described second instruction process submodule, specifically comprises:
First sends open command unit, for sending open command to described card, time delay Preset Time, reading and disconnecting response data, upgrade described second reading times, and trigger the 3rd judging unit from described card;
3rd judging unit, for judging whether described second reading times is less than preset value;
4th judging unit, for when described 3rd judging unit judges that described second reading times is less than preset value, judges whether successfully to read described disconnection response data;
Second zero unit, for when described 4th judging unit judges successfully to read described disconnection response data, resets described second reading times, and triggers the 3rd instruction process submodule.
Described initial mark module, also resets for third reading being got number of times;
Described 3rd instruction process submodule, specifically comprises:
First sends link order unit, for sending link order time delay Preset Time to described card, reading connection response data, upgrading described third reading and get number of times, and trigger the 5th judging unit from described card;
5th judging unit, for judging that described third reading is got number of times and whether is less than preset value;
6th judging unit, at described 5th judging unit, judges that described third reading gets number of times when being less than preset value, judges whether successfully to read described connection response data;
3rd zero unit, for when described 6th judging unit judges successfully to read described connection response data, gets number of times and resets, and trigger the 4th instruction process submodule by described third reading.
Described initial mark module, also for the 4th reading times being reset;
Described 4th instruction process submodule, specifically comprises:
First sends acquisition ATR command unit, and obtain ATR instruction for sending to described card, time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times, and triggers the 7th judging unit;
7th judging unit, for judging whether described 4th reading times is less than preset value;
8th judging unit, for when described 7th judging unit judges that described 4th reading times is less than preset value, judges whether successfully to read described ATR response data;
4th zero unit, for when described 8th judging unit judges successfully to read described ATR response data, resets described 4th reading times, sends ATR response data, and trigger described judgement interrupt module to described host computer.
Described second interface processing module, also comprises:
Second decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
5th instruction process submodule, when data for judging in described USB storage at described second decision instruction type submodule are lower electric instruction, send open command to card, read from described card and disconnect response data, and trigger the 6th instruction process submodule;
6th instruction process submodule, unlocking binding instruction for sending to described card, reading and unlocking binding response data from described card, sends lower electric successful information, and trigger described judgement interrupt module to described host computer.
Described initial mark module, for resetting the 5th reading times;
Described 6th instruction process submodule, comprising:
First sends unblock binding command unit, unlocks binding instruction, time delay Preset Time for sending to described card, and from described card, reading unlocks binding response data, upgrades described 5th reading times, and triggers the 9th judging unit;
9th judging unit, for judging whether described 5th reading times is less than preset value;
Tenth judging unit, for when described 9th judging unit judges that described 5th reading times is less than preset value, judges whether successfully to read described unblock binding response data;
5th zero unit, during for judging at described tenth judging unit successfully to read described unblock binding response data, resetting described 5th reading times, sending lower electric successful information, and trigger described judgement interrupt module to described host computer.
Described second interface processing module, comprising:
3rd decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
7th instruction process submodule, when the data for judging in described USB storage at described 3rd decision instruction type submodule being exchanges data instruction, sending to card and obtaining APDU instruction, and triggering the first reading submodule;
First reading submodule, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the first judgement submodule;
First judges submodule, for judging whether described 6th reading times is less than preset value;
Second judges submodule, for when described first judges that submodule judges that described 6th reading times is less than preset value, judges whether successfully to read described APDU response data;
First sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, described 6th reading times being reset, described APDU response data is sent to described host computer;
Second sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, sending read failure information to described host computer.
Beneficial effect of the present invention is, a kind of card reader is provided, the type of the SD card be connected with self can be identified, read-write operation can be carried out to common SD card, can when receiving the instruction that host computer issues, issue command adapted thereto to intelligent SD card, and obtain the response that intelligent SD card returns, make the application of intelligent SD card rely on smart mobile phone and digital product no longer merely.
Accompanying drawing explanation
The method of work process flow diagram of the card reader of a kind of operative intelligence SD card that Fig. 1 to Fig. 3 provides for embodiment 1 and common SD card;
The method of work process flow diagram of the card reader of a kind of operative intelligence SD card that Fig. 4 to Fig. 5 provides for embodiment 2 and common SD card;
The card reader structure figure of a kind of operative intelligence SD card that Fig. 6 provides for embodiment 3 and common SD card.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
For making the object, technical solutions and advantages of the present invention clearly, below in conjunction with accompanying drawing, embodiment of the present invention is described in further detail.
Embodiment 1
As shown in Figure 1 to Figure 3, the present embodiment 1 provides the method for work of the card reader of a kind of operative intelligence SD card and common SD card, specifically comprises:
Step 101: card reader carries out initialization;
In the present embodiment, comprise during initialization, interrupt identification resets by card reader, first reading times is reset, the second reading times resets, third reading gets number of times clearing clearing, the 4th reading times resets, the 5th reading times resets, the 6th reading times resets, draw-in groove state is initially set to without card, card mark is set to intelligent SD card mark;
Step 102: card reader reads the data in assigned address, and it can be used as Backup Data;
Step 103: card reader sends binding instruction to card, reads the data that card returns from assigned address, judging that whether the data read are identical with binding instruction, is perform step 104; Otherwise perform step 105;
Step 104: card mark is set to common SD card mark by card reader, Backup Data is write assigned address, the configuration information of definition scsi interface, enable USB connects, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of scsi interface is sent to host computer, performs step 106;
In the present embodiment, card reader can define the configuration information of any one interface in CCID, SCSI, hid, AutoRom, accordingly, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of the interface of definition is sent to host computer.
Step 105: the configuration information of card reader definition CCID interface and the configuration information of scsi interface, enable USB connects, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of CCID interface and the configuration information of scsi interface are sent to host computer, performs step 106;
In the present embodiment, card reader can define the configuration information of any two interfaces in CCID, SCSI, hid, AutoRom, accordingly, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of the interface of definition is sent to host computer.
Step 106: card reader is carried out USB and enumerated and judge whether USB interface is connection status, is perform step 107; Otherwise return step 106;
Step 107: card reader judges whether the interrupt identification that there is set, is, performs step 108; Otherwise return step 106;
Step 108: card reader judges the type of the interrupt identification of set, if snap into bit flag, then performs step 109; If USB receives Data Labels, then perform step 112; If other marks, then return step 106;
In the present embodiment, when card reader detects that snapping into a pin level changes, enter plug-in card and interrupt, bit flag set will be snapped into; When card reader receives data, enter USB and receive data interruption, USB is received Data Labels set, and the data received are stored in the USB storage of card reader.
Step 109: card reader is according to the electrical level judging draw-in groove state snapping into a pin, if draw-in groove state does not power on for there being card, then performs step 110; If draw-in groove state is without card, then perform step 111;
In the present embodiment, card reader judges the level state snapping into a pin, if high level, then draw-in groove state does not power on for there being card; If low level, then draw-in groove state is without card;
Step 110: card reader sends to host computer has card to respond, and draw-in groove state has been saved as card does not power on, and returns step 106;
In the present embodiment, when card reader detects that the level snapping into a pin is high level, card is had to respond by INT end points to host computer transmission.
Step 111: card reader sends without card response to host computer, and draw-in groove state is saved as without card, returns step 106;
In the present embodiment, when card reader detects that the level snapping into a pin is high level, card is had to respond by INT end points to host computer transmission.
Step 112: card reader obtains the data in USB storage, performs step 113;
In the present embodiment, card reader receives data in the mode of interrupting, and is kept in USB storage by the data received;
Step 113: card reader judges that whether the data got are legal, is perform step 115; Otherwise perform step 114;
In the present embodiment, whether the first byte of the data that card reader interpretation gets is 0x62 or 0x63 or 0x6f, is, represents that the data got are legal, otherwise represents that the data got are illegal;
Step 114: card reader sends error message to host computer, returns step 106;
Step 115: card reader judges the instruction type of the data got, if power on instruction, then performs step 116; If lower electric instruction, then perform step 134; If exchanges data instruction, then perform step 143; If memory channel instruction, then perform step 148;
In the present embodiment, card reader according to the first byte decision instruction type of the data got,
If the first byte is 0x62, then the data got are the instruction that powers on, and perform step 116;
If the first byte is 0X63, then the data got are lower electric instruction, perform step 134;
If the first byte is 0x6f, then the data got are exchanges data instruction, perform step 143;
If the first byte is the first preset value, then the data got are memory channel instruction, perform step 148; Preferably, the first preset value is 0x6B.
Step 116: card reader sends binding instruction to card;
In the present embodiment, binding instruction comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code binding instruction is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05?,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12;
The transmission sequence counter of binding instruction is: 0x00,0x00;
The command code of binding instruction is: 0x00,0x02;
Such as, card reader to card transmission binding instruction is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x00,0x02,0x00,0x00,0x02; Namely the APDU comprising 0 byte in instruction is bound.
Step 117: card reader time delay Preset Time, reads binding response data, upgrades the first reading times from card;
Preferably, Preset Time is 5 milliseconds.
In the present embodiment, the binding response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code binding response data is:
0x060F19161F160C0B1F1F180E1A1903021F0C0412160F050D061BD051A130B121;
The transmission sequence counter of binding response data is: 0x00,0x00;
Such as, the binding response data that card reader reads is:
0x060F19161F160C0B1F1F180E1A1903021F0C0412160F050D061BD?051A130B12100000000000000;
Step 118: card reader judges whether the first reading times is less than preset value, is, performs step 119; Otherwise perform step 133;
Preferably, preset value is 30.
Step 119: card reader judges whether binding response data reads successfully, is perform step 120; Otherwise return step 117;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the binding response data in card, binding response data according to reading judges whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of the binding response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 120: the first reading times resets by card reader, sends open command to card, performs step 121;
In the present embodiment, open command comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of open command is identical with the command id code of binding instruction; The transmission sequence counter of open command is identical with the transmission sequence counter of binding instruction;
The command code of open command is: 0x01,0x01;
Such as, card reader to card transmission open command is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05?,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x01,0x00,0x00,0x00; Namely the APDU of 0 byte is comprised in open command.
Step 121: card reader time delay Preset Time, reads and disconnects response data, upgrade the second reading times from card;
In the present embodiment, the disconnection response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code disconnecting response data is identical with the response identification code of binding response data,
The transmission sequence counter disconnecting response data is identical with the transmission sequence counter of open command;
Such as, the disconnection response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x00,0x00,0x00,0x00,0x00,0x00,0x00;
Step 122: card reader judges whether the second reading times is less than preset value, is, performs step 123; Otherwise perform step 133;
Step 123: card reader judges whether disconnect response data reads successfully, is perform step 124; Otherwise return step 121;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the disconnection response data in card, disconnection response data according to reading judges whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of the disconnection response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 124: the second reading times resets by card reader, sends link order to card, performs step 125;
In the present embodiment, link order comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of link order is identical with the command id code of binding instruction; The transmission sequence counter of link order is identical with the transmission sequence counter of binding instruction;
The command code of link order is: 0x01,0x02;
Such as, card reader to card transmission link order is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x02,0x00,0x01,0x00,0x02; Namely comprise the APDU of 1 byte in link order, APDU is 0x00.
Step 125: card reader time delay Preset Time, reads connection response data from card, upgrades third reading and gets number of times;
In the present embodiment, the connection response packet that card reader reads contains, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of connection response data is identical with the response identification code of binding response data;
The transmission sequence counter of connection response data is identical with the transmission sequence counter of binding response data;
Such as, the connection response data that card reader reads are:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x00,0x00,0x00,0x00,0x00,0x03,0x05,0x00,0x20,0x26;
Step 126: card reader judges that third reading is got number of times and whether is less than preset value, is perform step 127; Otherwise perform step 133;
Step 127: card reader judges whether connection response data read successfully, are, perform step 128; Otherwise return step 125;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the connection response data in card, connection response data according to reading judge whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of the connection response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
In the present embodiment, when reading successfully, also comprise:
Card reader obtains the 38 of connection response data the, the data in the 39 byte, using the data that get as current transmission sequence counter;
Such as, the 38 of the connection response data that card reader gets the, the data in the 39 byte are 0x50,0x00.
Step 128: third reading is got number of times and reset by card reader, sends to card and obtains ATR instruction, perform step 129;
In the present embodiment, obtain command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that ATR instruction comprises 32 bytes, wherein, the command id code obtaining ATR instruction is identical with the command id code of binding instruction; Card reader obtains and upgrades current transmission sequence counter, using the current transmission sequence counter after renewal as the transmission sequence counter obtaining ATR instruction; Particularly, the method that card reader upgrades current transmission sequence counter is, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading.
The command code obtaining ATR instruction is: 0x01,0x03;
Such as, the current sequence counter that send is 0x05,0x00, default step-length is 1, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading, and the transmission sequence counter namely obtaining ATR instruction is 0x50,0x01.
Card reader sends acquisition ATR instruction to card:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x50,0x01,0x01,0x03,0x00,0x00,0x00; Namely the APDU comprising 0 byte in ATR instruction is obtained.
It should be noted that, card reader sends link order to card, after card receives link order, card generates a random number meeting preset range as transmission sequence counter, and using the part of described transmission sequence counter as connection response data in card, when having read the connection response data in card when card reader, obtain from the connection response data read and send sequence counter, and upgrade transmission sequence counter, judge whether the transmission sequence counter after upgrading meets preset range, it is the transmission sequence counter of next instruction that then the transmission sequence counter after renewal will be sent to card as card reader, otherwise transmission sequence counter is updated to 1, using the transmission sequence counter of next instruction that the transmission sequence counter after upgrading will send to card as card reader,
Wherein, card reader will send result that sequence counter and default step-length do additive operation as the transmission sequence counter after upgrading.
Step 129: card reader time delay Preset Time, reads ATR response data from card, upgrades the 4th reading times;
In the present embodiment, the ATR response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of ATR response data is identical with the response identification code of binding response data,
The transmission sequence counter of ATR response data is identical with the transmission sequence counter obtaining ATR instruction;
Such as, the ATR response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x05,0x01,0x00,0x00,0x00,0x20,0x76,0x5E,0x37,0x16,0x2F,0x56,0x0C,0x0B,0xEA,0x1F,0x19,0x0B,0x1A,0x19,0x03,0x05,0x4E?,0xCE,0x04,0x12,0x16,0x0F,0x05,0x0D,0x46,0x1B,0xD5,0x71,0xA6,0x40,0xBE,0x53,0xE4;
Step 130: card reader judges whether the 4th reading times is less than preset value, is perform step 131; Otherwise perform step 133;
Step 131: card reader judges whether ATR response data reads successfully, is, performs step 132; Otherwise return step 129;
In the present embodiment, judge whether that reading successful method is specially,
Card reader reads the ATR response data in card, ATR response data according to reading judges whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of the ATR response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 132: the 4th reading times resets by card reader, sends ATR response data to host computer, returns step 106;
Step 133: card reader sends to host computer and reads failure information, returns step 106;
Step 134: card reader sends open command to card;
In the present embodiment, in the present embodiment, open command comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of open command is identical with the command id code of binding instruction; The transmission sequence counter of open command is identical with the transmission sequence counter of binding instruction;
The command code of open command is: 0x01,0x01;
Such as, card reader to card transmission open command is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x01,0x00,0x00,0x00; Namely the APDU of 0 byte is comprised in open command.
Step 135: card reader time delay Preset Time, reads and disconnects response data, upgrade the second reading times from card;
In the present embodiment, the disconnection response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code disconnecting response data is identical with the response identification code of binding response data,
The transmission sequence counter disconnecting response data is identical with the transmission sequence counter of open command;
Such as, the disconnection response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00;
Step 136: card reader judges whether the second reading times is less than preset value, is, performs step 137; Otherwise card reader sends to host computer and reads failure information, returns step 106;
Step 137: card reader judges whether disconnect response data reads successfully, is perform step 138; Otherwise return step 135;
In the present embodiment, judge whether to read successful Methods and steps 123 identical.
Step 138: the second reading times resets by card reader, sends to card and unlocks binding instruction, perform step 139;
In the present embodiment, unlock command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that binding instruction comprises 32 bytes, wherein, the command id code unlocking binding instruction is identical with the command id code of binding instruction; The transmission sequence counter unlocking binding instruction is identical with the transmission sequence counter of binding instruction;
The command code unlocking binding instruction is: 0x00,0x03;
Such as, card reader to card transmission unblock binding instruction is:
0x06,0x0F, 0x19,0x16,0x1F, 0x16,0x0C, 0x0B, 0x1F, 0x1F, 0x18,0x0E, 0x1A, 0x19,0x03,0x02,0x1F, 0x0C, 0x04,0x12,0x16,0x0F, 0x05,0x0D, 0x06,0x1B, 0x0D, 0x15,0x1A, 0x03,0x1B, 0x12,0x00,0x00,0x00,0x03,0x00,0x00,0x03; Namely the APDU comprising 0 byte in binding instruction is unlocked.
Step 139: card reader time delay Preset Time, reads and unlocks binding response data, upgrade the 5th reading times from card;
In the present embodiment, the unblock binding response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code unlocking binding response data is identical with the response identification code of binding response data;
The transmission sequence counter unlocking binding response data is identical with the transmission sequence counter of binding response data;
Such as, the unblock binding response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,0x00,0x00,0x00,0x00,0x00,0x14;
Step 140: card reader judges whether the 5th reading times is less than preset value, is perform step 141; Otherwise card reader sends to host computer and reads failure information, returns step 106;
Step 141: card reader judges whether disconnect response data reads successfully, is perform step 142; Otherwise return step 139;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the unblock binding response data in card, unblock binding response data according to reading judges whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of the unblock binding response read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 142: the 5th reading times resets by card reader, sends lower electric successful information to host computer, returns step 106;
Step 143: card reader sends to card and obtains APDU instruction;
In the present embodiment, obtain command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that APDU instruction comprises 32 bytes, wherein, the command id code obtaining APDU instruction is identical with the command id code of binding instruction; Card reader obtains current transmission sequence counter, upgrades current transmission sequence counter, using the transmission sequence counter after renewal as the transmission sequence counter obtaining APDU instruction;
Particularly, the method that card reader upgrades current transmission sequence counter is, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading.
The command code obtaining APDU instruction is: 0x01,0x04;
Such as, the current sequence counter that send is 0x05,0x01, default step-length is 1, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading, and the transmission sequence counter namely obtaining ATR instruction is 0x50,0x02.
Card reader sends acquisition APDU instruction to card:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x05,0x02,0x01,0x04,0x00,0x40,0x51,0x0F,0x18,0x16,0x1F,0x24,0x84,0xEC,0x24,0x5F,0x09,0x02,0x1B,0x3C,0x03,0x0b,0x1F,0x04,0x31,0x15,0x23,0x9A,0x7C,0x14,0x06,0x1B,0x0D,0x15,0x34,0x40,0x1C,0x42,0x5C,0x4F,0x78,0x34,0x15,0x62,0x36,0xE2,0x62,0x51,0x09,0x02,0x1B,0x3C,0x18,0x1F,0x04,0x31,0x15,0x2E,0x4A,0x7D,0x32,0x17,0x5B,0x0D,0x28,0x36,0x41,0x38,0x22;
Step 144: card reader time delay Preset Time, reads APDU response data from card, upgrades the 6th reading times;
In the present embodiment, APDU response data in the card that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of APDU response data is identical with the response identification code of binding response data, and the transmission sequence counter of APDU response data is identical with the transmission sequence counter obtaining APDU instruction;
Such as, the APDU response data in the card that reads of card reader is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x05,0x02,0x00,0x00,0x00,0x38,0x84,0xEC,0x24,0x5F,0x09,0x02,0x1B,0x3C,0x03,0x0b,0xA3,0x14,0x38,0x15,0x23,0x9A,0x7C,0x14,0x06,0x1B,0x0D,0x26,0x34,0x3A,0x1C,0x42,0x5C,0x4F,0x78,0x34,0x37,0x62,0x36,0xE2,0x62,0x51,0x09,0x02,0x74,0x3C,0x39,
0x1F,0x90,0x31,0x15,0x2E,0x4A,0x4D,0x53,0x17,0x5B,0x81,0x2A,0x36,0x41,0x5E,0x48;
Step 145: card reader judges whether the 6th reading times is less than preset value, is perform step 146; Otherwise card reader sends to host computer and reads failure information, returns step 106;
Step 146: card reader judges whether APDU response data reads successfully, is, performs step 147; Otherwise return step 144;
In the present embodiment, judge whether that reading successful method is specially,
Card reader reads the APDU response data in card, APDU response data according to reading judges whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of APDU response data, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 147: the 6th reading times resets by card reader, by APDU response data, sends to host computer, returns step 106;
Step 148: the first data preset in byte that card reader obtains memory channel instruction it can be used as destination address, judge whether destination address is assigned address, is perform step 149; Otherwise perform step 151;
In the present embodiment, first presets the ten two to ten five bytes that byte is memory channel instruction.Judge whether the data in the 12 to the 15 byte of memory channel instruction are the second preset value, if it is perform step 149; Otherwise perform step 151; Preferably, the second preset value is 0x07862208.
Step 149: card reader judges whether card mark is intelligent SD card mark, is perform step 150; Otherwise perform step 151;
In the present embodiment, step 148 to step 149 can also be,
Step 148 ': card reader judges whether card mark is intelligent SD card mark, is perform step 149 '; Otherwise perform step 151;
Step 149 ': the first data preset in byte that card reader obtains memory channel instruction it can be used as destination address, judge whether destination address is assigned address, is perform step 150; Otherwise perform step 151;
Step 150: card reader sends can not write data to destination address to host computer, returns step 106;
Step 151: card reader presets according to second of memory channel instruction the type that byte judges memory channel instruction, if read operation instruction, then performs step 152; If write operation instruction, then perform step 153;
In the present embodiment, second presets the 11 byte that byte is memory channel instruction, if the data in the 11 byte of memory channel instruction are the 3rd preset value, then memory channel instruction is read operation instruction, performs step 152; If the data in the 11 byte of memory channel instruction are the 4th preset value, then memory channel instruction is write operation instruction; Preferably, the 3rd preset value is 0x01; 4th preset value is 0x02.
Step 152: card reader reads the data in destination address, and sends it to host computer, returns step 106;
In the present embodiment, card reader obtains the data in the 3rd default byte of extended instruction, and it can be used as the length of data to be read, card reader reads the data that length equals the length of data to be read from destination address.Preferably, the 3rd the 16 byte that byte is memory channel instruction is preset.
Step 153: card reader obtains the data in the 3rd default byte of memory channel instruction, it can be used as data length to be written, from memory channel instruction, data to be written are obtained next byte after the 3rd default byte according to data length to be written, and write in destination address, send write operation to host computer and complete information, return step 106.
In the present embodiment, card reader obtains the data that length is data length to be written presetting after byte from the obtain memory channel instruction the 3rd, it can be used as data to be written.
Embodiment 2
As shown in Fig. 4 to Fig. 5, the present embodiment 2 provides the method for work of the card reader of a kind of operative intelligence SD card and common SD card, specifically comprises:
Step 201: card reader carries out initialization;
In the present embodiment, comprise during initialization, interrupt identification resets by card reader, first reading times is reset, the second reading times resets, third reading gets number of times clearing clearing, the 4th reading times resets, the 5th reading times resets, the 6th reading times resets, draw-in groove state is initially set to nothing and blocks;
Step 202: the card reader definition configuration information of CCID and the configuration information of scsi interface, enable USB connects, and when receiving the acquisition interface configuration information instruction that host computer issues, the configuration information of CCID and the configuration information of scsi interface is sent to host computer;
Step 203: card reader is carried out USB and enumerated and judge whether USB is connection status, is perform step 204; Otherwise return step 203;
Step 204: card reader judges whether the interrupt identification that there is set, is, performs step 205; Otherwise return step 203;
Step 205: card reader judges the type of the interrupt identification of set, if snap into bit flag, then performs step 206; If USB receives Data Labels, then perform step 209; If other marks, then return step 203;
In the present embodiment, when card reader detects that snapping into a pin level changes, enter plug-in card and interrupt, bit flag set will be snapped into; When card reader receives data, enter USB and receive data interruption, USB is received Data Labels set, and the data received are stored in the USB storage of card reader.
Step 206: card reader, according to the electrical level judging draw-in groove state snapping into a pin, if there is card not power on, then performs step 207; If without card, then perform step 208;
In the present embodiment, card reader is specially according to the electrical level judging draw-in groove state snapping into a pin, if snapping into a pin is high level, draw-in groove state does not power on for there being card; If snapping into a pin is low level, draw-in groove state is without card.
Step 207: card reader sends to host computer has card to respond, and draw-in groove state has been saved as card does not power on, and returns step 203;
In the present embodiment, when card reader detects that the level snapping into a pin is high level, card is had to respond by INT end points to host computer transmission.
Step 208: card reader sends without card response to host computer, and draw-in groove state is saved as without card, returns step 203;
In the present embodiment, when card reader detects that the level snapping into a pin is high level, card is had to respond by INT end points to host computer transmission.
Step 209: card reader obtains the data in USB storage, judges the interface of the data received in USB storage, if first interface, then performs step 210; If the second interface, then perform step 212;
In the present embodiment, card reader receives data in the mode of interrupting, and is kept in USB storage by the data received;
Step 210: card reader, according to the configuration information of scsi interface, performs corresponding operating to the data got, and generating run code;
In the present embodiment, card reader judges that second of the data got presets data in byte, if the second data preset in byte are the 3rd preset value, then and the first default byte of data of getting of card reader, it can be used as destination address, read the data in destination address; If the second data preset in byte are the 4th preset value, what then card reader got the 3rd of data presets byte, it can be used as data length to be written, obtain to be written data from after the 3rd of the data got preset byte a byte according to data length to be written, and write in destination address;
Preferably, second presets the 11 byte that byte is the data got, and the 3rd presets the 16 byte that byte is the data got; 3rd preset value is 0x01; 4th preset value is 0x02.
Step 211: card reader, to host computer transmit operation code, returns step 203;
In the present embodiment, if second of the data got the default byte is the 3rd preset value, the data read are sent to host computer as operational code by card reader; If the 4th preset value of the data got, then card reader generates write operation and completes information after data to be written are write destination address, it can be used as operational code to send to host computer.
Step 212: card reader judges the instruction type of the data got, if power on instruction, then performs step 213; If lower electric instruction, then perform step 231; If exchanges data instruction, then perform step 240;
In the present embodiment, card reader according to the first byte decision instruction type of the data got,
If the first byte is 0x62, then the data got are the instruction that powers on, and perform step 213;
If the first byte is 0X63, then the data got are lower electric instruction, perform step 231;
If the first byte is 0x6f, then the data got are exchanges data instructions, then perform step 240;
Step 213: card reader sends binding instruction to intelligent SD card;
In the present embodiment, binding instruction comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code binding instruction is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12;
The transmission sequence counter of binding instruction is: 0x00,0x00;
The command code of binding instruction is: 0x00,0x02;
Such as, card reader to intelligent SD card transmission binding instruction is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x00,0x02,0x00,0x00,0x02; Namely the APDU comprising 0 byte in instruction is bound.
Step 214: card reader time delay Preset Time, reads binding response data, upgrades the first reading times from intelligent SD card;
Preferably, Preset Time is 5 milliseconds.
In the present embodiment, the binding response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code binding response data is:
0x060F19161F160C0B1F1F180E1A1903021F0C0412160F050D061BD051A130B121;
The transmission sequence counter of binding response data is: 0x00,0x00;
Such as, the binding response data that card reader reads is:
0x060F19161F160C0B1F1F180E1A1903021F0C0412160F050D061BD051A130B12100000000000000;
Step 215: card reader judges whether the first reading times is less than preset value, is, performs step 216; Otherwise perform step 230;
Preferably, preset value is 30.
Step 216: card reader judges whether binding response data reads successfully, is perform step 217; Otherwise return step 214;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the binding response data in intelligent SD card, binding response data according to reading judges whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of the binding response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 217: the first reading times resets by card reader, sends open command to intelligent SD card, performs step 218;
In the present embodiment, open command comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of open command is identical with the command id code of binding instruction; The transmission sequence counter of open command is identical with the transmission sequence counter of binding instruction;
The command code of open command is: 0x01,0x01;
Such as, card reader to intelligent SD card transmission open command is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x01,0x00,0x00,0x00; Namely the APDU of 0 byte is comprised in open command.
Step 218: card reader time delay Preset Time, reads and disconnects response data, upgrade the second reading times from intelligent SD card;
In the present embodiment, the disconnection response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code disconnecting response data is identical with the response identification code of binding response data,
The transmission sequence counter disconnecting response data is identical with the transmission sequence counter of open command;
Such as, the disconnection response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x00,0x00,0x00,0x00,0x00,0x00,0x00;
Step 219: card reader judges whether the second reading times is less than preset value, is, performs step 220; Otherwise perform step 230;
Step 220: card reader judges whether disconnect response data reads successfully, is perform step 221; Otherwise return step 218;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the disconnection response data in intelligent SD card, disconnection response data according to reading judges whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of the disconnection response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 221: the second reading times resets by card reader, sends link order to intelligent SD card, performs step 222;
In the present embodiment, link order comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of link order is identical with the command id code of binding instruction; The transmission sequence counter of link order is identical with the transmission sequence counter of binding instruction;
The command code of link order is: 0x01,0x02;
Such as, card reader to intelligent SD card transmission link order is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x02,0x00,0x01,0x00,0x02; Namely comprise the APDU of 1 byte in link order, APDU is 0x00.
Step 222: card reader time delay Preset Time, reads connection response data from intelligent SD card, upgrades third reading and gets number of times;
In the present embodiment, the connection response packet that card reader reads contains, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of connection response data is identical with the response identification code of binding response data;
The transmission sequence counter of connection response data is identical with the transmission sequence counter of binding response data; Such as, the connection response data that card reader reads are:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x00,0x00,0x00,0x00,0x00,0x03,0x05,0x00,0x20,0x26;
Step 223: card reader judges that third reading is got number of times and whether is less than preset value, is perform step 224; Otherwise perform step 230;
Step 224: card reader judges whether connection response data read successfully, are, perform step 225; Otherwise return step 222;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the connection response data in intelligent SD card, connection response data according to reading judge whether to read successfully, particularly, card reader obtains the 34 to the 35 byte of the connection response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
In the present embodiment, when reading successfully, also comprise:
Card reader obtains the 38 of connection response data the, the data in the 39 byte, using the data that get as current transmission sequence counter;
Such as, the 38 of the connection response data that card reader gets the, the data in the 39 byte are 0x50,0x00.
Step 225: third reading is got number of times and reset by card reader, sends to intelligent SD card and obtains ATR instruction, perform step 226;
In the present embodiment, obtain command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that ATR instruction comprises 32 bytes, wherein, the command id code obtaining ATR instruction is identical with the command id code of binding instruction; Card reader obtains and upgrades current transmission sequence counter, using the current transmission sequence counter after renewal as the transmission sequence counter obtaining ATR instruction; Particularly, the method that card reader upgrades current transmission sequence counter is, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading.
The command code obtaining ATR instruction is: 0x01,0x03;
Such as, the current sequence counter that send is 0x05,0x00, default step-length is 1, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading, and the transmission sequence counter namely obtaining ATR instruction is 0x50,0x01.
Card reader sends acquisition ATR instruction to intelligent SD card:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x50,0x01,0x01,0x03,0x00,0x00,0x00; Namely the APDU comprising 0 byte in ATR instruction is obtained.
It should be noted that, card reader sends link order to intelligent SD card, after intelligent SD card receives link order, intelligent SD card generates a random number meeting preset range as transmission sequence counter, and using the part of described transmission sequence counter as connection response data in intelligent SD card, when having read the connection response data in intelligent SD card when card reader, obtain from the connection response data read and send sequence counter, and upgrade transmission sequence counter, judge whether the transmission sequence counter after upgrading meets preset range, it is the transmission sequence counter of next instruction that then the transmission sequence counter after renewal will be sent to intelligent SD card as card reader, otherwise transmission sequence counter is updated to 1, using the transmission sequence counter of next instruction that the transmission sequence counter after upgrading will send to intelligent SD card as card reader,
Wherein, card reader will send result that sequence counter and default step-length do additive operation as the transmission sequence counter after upgrading.
Step 226: card reader time delay Preset Time, reads ATR response data from intelligent SD card, upgrades the 4th reading times;
In the present embodiment, the ATR response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of ATR response data is identical with the response identification code of binding response data,
The transmission sequence counter of ATR response data is identical with the transmission sequence counter obtaining ATR instruction;
Such as, the ATR response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x05,0x01,0x00,0x00,0x00,0x20,0x76,0x5E,0x37,0x16,0x2F,0x56,0x0C,0x0B,0xEA,0x1F,0x19,0x0B,0x1A,0x19,0x03,0x05,0x4E,0xCE,0x04,0x12,0x16,0x0F,0x05,0x0D,0x46,0x1B,0xD5,0x71,0xA6,0x40,0xBE,0x53,0xE4;
Step 227: card reader judges whether the 4th reading times is less than preset value, is perform step 228; Otherwise perform step 230;
Step 228: card reader judges whether ATR response data reads successfully, is, performs step 229; Otherwise return step 226;
In the present embodiment, judge whether that reading successful method is specially,
Card reader reads the ATR response data in intelligent SD card, ATR response data according to reading judges whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of the ATR response data read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 229: the 4th reading times resets by card reader, sends ATR response data to host computer, returns step 203;
Step 230: card reader sends to host computer and reads failure information, returns step 203;
Step 231: card reader sends open command to intelligent SD card;
In the present embodiment, in the present embodiment, open command comprises command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes of 32 bytes, wherein, the command id code of open command is identical with the command id code of binding instruction; The transmission sequence counter of open command is identical with the transmission sequence counter of binding instruction;
The command code of open command is: 0x01,0x01;
Such as, card reader to intelligent SD card transmission open command is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x00,0x00,0x01,0x01,0x00,0x00,0x00; Namely the APDU of 0 byte is comprised in open command.
Step 232: card reader time delay Preset Time, reads and disconnects response data, upgrade the second reading times from intelligent SD card;
In the present embodiment, the disconnection response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code disconnecting response data is identical with the response identification code of binding response data,
The transmission sequence counter disconnecting response data is identical with the transmission sequence counter of open command;
Such as, the disconnection response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,0x00,0x00,0x0?0,0x00,0x00,0x00,0x00;
Step 233: card reader judges whether the second reading times is less than preset value, is, performs step 234; Otherwise card reader sends to host computer and reads failure information, returns step 203;
Step 234: card reader judges whether disconnect response data reads successfully, is perform step 235; Otherwise return step 232;
In the present embodiment, judge whether to read successful Methods and steps 220 identical.
Step 235: the second reading times resets by card reader, sends to intelligent SD card and unlocks binding instruction, perform step 236;
In the present embodiment, unlock command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that binding instruction comprises 32 bytes, wherein, the command id code unlocking binding instruction is identical with the command id code of binding instruction; The transmission sequence counter unlocking binding instruction is identical with the transmission sequence counter of binding instruction;
The command code unlocking binding instruction is: 0x00,0x03;
Such as, card reader to intelligent SD card transmission unblock binding instruction is:
0x06,0x0F, 0x19,0x16,0x1F, 0x16,0x0C, 0x0B, 0x1F, 0x1F, 0x18,0x0E, 0x1A, 0x19,0x03,0x02,0x1F, 0x0C, 0x04,0x12,0x16,0x0F, 0x05,0x0D, 0x06,0x1B, 0x0D, 0x15,0x1A, 0x03,0x1B, 0x12,0x00,0x00,0x00,0x03,0x00,0x00,0x03; Namely the APDU comprising 0 byte in binding instruction is unlocked.
Step 236: card reader time delay Preset Time, reads and unlocks binding response data, upgrade the 5th reading times from intelligent SD card;
In the present embodiment, the unblock binding response data that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code unlocking binding response data is identical with the response identification code of binding response data;
The transmission sequence counter unlocking binding response data is identical with the transmission sequence counter of binding response data;
Such as, the unblock binding response data that card reader reads is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,0x00,0x00,0x00,0x00,0x00,0x14;
Step 237: card reader judges whether the 5th reading times is less than preset value, is perform step 238; Otherwise card reader sends to host computer and reads failure information, returns step 203;
Step 238: card reader judges whether unlock binding response data reads successfully, is perform step 239; Otherwise return step 236;
In the present embodiment, judge whether that reading successful method is specially:
Card reader reads the unblock binding response data in intelligent SD card, unblock binding response data according to reading judges whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of the unblock binding response read, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 239: the 5th reading times resets by card reader, sends lower electric successful information to host computer, returns step 203;
Step 240: card reader sends to intelligent SD card and obtains APDU instruction;
In the present embodiment, obtain command id code, the transmission sequence counter of 2 bytes, command code, the order length of 2 bytes, the APDU of some bytes, the byte check code of 1 byte of 2 bytes that APDU instruction comprises 32 bytes, wherein, the command id code obtaining APDU instruction is identical with the command id code of binding instruction; Card reader obtains current transmission sequence counter, upgrades current transmission sequence counter, using the transmission sequence counter after renewal as the transmission sequence counter obtaining APDU instruction;
Particularly, the method that card reader upgrades current transmission sequence counter is, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading.
The command code obtaining APDU instruction is: 0x01,0x04;
Such as, the current sequence counter that send is 0x05,0x01, default step-length is 1, the card reader result of current transmission sequence counter and default step-length being done additive operation is as the current transmission sequence counter after upgrading, and the transmission sequence counter namely obtaining ATR instruction is 0x50,0x02.
Card reader sends acquisition APDU instruction to intelligent SD card:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0x0D,0x15,0x1A,0x03,0x1B,0x12,
0x05,0x02,0x01,0x04,0x00,0x40,0x51,0x0F,0x18,0x16,0x1F,0x24,0x84,0xEC,0x24,0x5F,0x09,0x02,0x1B,0x3C,0x03,0x0b,0x1F?,0x04,0x31,0x15,0x23,0x9A,0x7C,0x14,0x06,0x1B,0x0D,0x15,0x34,0x40,0x1C,0x42,0x5C,0x4F,0x78,0x34,0x15,0x62,0x36,0xE2,0x62,0x51,0x09,0x02,0x1B,0x3C,0x18,0x1F,0x04,0x31,0x15,0x2E,0x4A,0x7D,0x32,0x17,0x5B,0x0D,0x28,0x36,0x41,0x38,0x22;
Step 241: card reader time delay Preset Time, reads APDU response data from intelligent SD card, upgrades the 6th reading times;
In the present embodiment, APDU response data in the intelligent SD card that card reader reads comprises, the response identification code of 32 bytes, the transmission sequence counter of 2 bytes, the communication state code of 2 bytes, the response data length of 2 bytes, the response data of some bytes, the byte check code of 1 byte; Wherein, the response identification code of APDU response data is identical with the response identification code of binding response data, and the transmission sequence counter of APDU response data is identical with the transmission sequence counter obtaining APDU instruction;
Such as, the APDU response data in the intelligent SD card that reads of card reader is:
0x06,0x0F,0x19,0x16,0x1F,0x16,0x0C,0x0B,0x1F,0x1F,0x18,0x0E,0x1A,0x19,0x03,0x02,0x1F,0x0C,0x04,0x12,0x16,0x0F,0x05,0x0D,0x06,0x1B,0xD0,0x51,0xA1,0x30,0xB1,0x21,
0x05,0x02,0x00,0x00,0x00,0x38,0x84,0xEC,0x24,0x5F,0x09,0x02,0x1B,0x3C,0x03,0x0b,0xA3,0x14,0x38,0x15,0x23,0x9A,0x7C,0x14,0x06,0x1B,0x0D,0x26,0x34,0x3A,0x1C,0x42,0x5C,0x4F,0x78,0x34,0x37,0x62,0x36,0xE2,0x62,0x51,0x09,0x02,0x74,0x3C,0x39,
0x1F,0x90,0x31,0x15,0x2E,0x4A,0x4D,0x53,0x17,0x5B,0x81,0x2A,0x36,0x41,0x5E,0x48;
Step 242: card reader judges whether the 6th reading times is less than preset value, is perform step 243; Otherwise card reader sends to host computer and reads failure information, returns step 203;
Step 243: card reader judges whether APDU response data reads successfully, is, performs step 244; Otherwise return step 230;
In the present embodiment, judge whether that reading successful method is specially,
Card reader reads the APDU response data in intelligent SD card, APDU response data according to reading judges whether to read successfully, particularly, card reader obtains the data in the 34 to the 35 byte of APDU response data, it can be used as communication state code, if communication state code is 0x00,0x00, then represents and read successfully; Otherwise represent and read unsuccessfully.
Step 244: the 6th reading times resets by card reader, by APDU response data, sends to host computer, returns step 203.
Embodiment 3
The present embodiment provides the card reader of a kind of operative intelligence SD card and common SD card, as shown in Figure 6, comprising:
Initialization module 301, for carrying out initialization, card mark is set to intelligent SD card mark, draw-in groove state is set to without card, the first reading times is reset, the second reading times is reset, third reading is got number of times to reset, 4th reading times is reset, the 5th reading times is reset, the 6th reading times is reset;
Read module 302, for reading the data in assigned address, and using the data that read as Backup Data, and triggers the first processing module 303;
First processing module 303, for sending binding instruction to card, reading the data that card returns, and triggering the first judge module 304 from described assigned address;
Whether the first judge module 304 is identical with described binding instruction for judging the data that described card returns;
Second processing module 305, for when described first judge module 304 judges that the data that described card returns are identical with described binding instruction, described card mark is set to common SD card mark, described Backup Data is write in described assigned address, the configuration information of definition scsi interface, and trigger the first configuration information sending module 306;
First configuration information sending module 306, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the configuration information of described scsi interface, and detection trigger module 309;
3rd processing module 307, for when described first judge module 304 judges that the data that described card returns are not identical with described binding instruction, the configuration information of definition CCID interface and the configuration information of scsi interface, and trigger the second configuration information sending module 308;
Second configuration information sending module 308, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and detection trigger module 309;
Detection module 309, for judging whether the interrupt identification that there is set, and judges the type of the interrupt identification of set;
First acquisition module 310, for judging at described detection module 309 interrupt identification that there is set, and when the interrupt identification of described set is USB reception Data Labels, obtains the data in USB storage, and triggers the second judge module 312;
Second acquisition module 311, for judging at described detection module 309 interrupt identification that there is set, and when the interrupt identification of described set is other marks, performs corresponding operating, and triggers described detection module 309;
In the present embodiment, described second acquisition module 311, specifically for detecting at described detection module 309 interrupt identification that there is set, and when the interrupt identification of described set is for snapping into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sends to described host computer and has card to respond, and described draw-in groove state has been saved as card do not power on, and trigger described detection module 309; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, and trigger described detection module 309.
Second judge module 312, judges for the data got described first acquisition module 310;
4th processing module 313, when data for judging to get at described second judge module 312 are intelligent SD card communication instruction, communicate with described card according to described intelligent SD card communication instruction, communication response is read from described card, and described communication response is sent to described host computer, and trigger described detection module 309;
In the present embodiment, the 4th processing module 313, comprising:
First binding submodule Q1, for the data that judge to get at described second judge module 312 as power on instruction time, send binding instruction to card, read from described card and bind response data, and trigger the first disconnection submodule Q2;
Described first binding submodule Q1, comprising:
First sends binding command unit Q1-1, for the data that judge to get at described second judge module 312 as power on instruction time, binding instruction is sent to described card, time delay Preset Time, binding response data is read from described card, upgrade described first reading times, and trigger the first judging unit Q1-2;
First judging unit Q1-2, for judging whether described first reading times is less than preset value;
Second judging unit Q1-3, for when described first judging unit Q1-2 judges that described first reading times is less than preset value, judges whether successfully to read described binding response data;
First zero unit Q1-4, for when described second judging unit Q1-3 judges successfully to read described binding response data, resets described first reading times, and triggers the first disconnection submodule Q2.
First disconnects submodule Q2, for sending open command to described card, reading and disconnecting response data, and trigger the first connexon module Q3 from described card;
Described first disconnects submodule Q2, comprising:
First sends open command unit Q2-1, for sending open command to described card, time delay Preset Time, reading and disconnecting response data, upgrade described second reading times, and trigger the 3rd judging unit Q2-2 from described card;
3rd judging unit Q2-2, for judging whether described second reading times is less than preset value;
4th judging unit Q2-3, for when described 3rd judging unit Q2-2 judges that described second reading times is less than preset value, judges whether successfully to read described disconnection response data;
Second zero unit Q2-4, for when described 4th judging unit Q2-3 judges successfully to read described disconnection response data, resets described second reading times, and triggers the first connexon module Q3.
First connexon module Q3, for sending link order to described card, reading connection response data, and triggering the first acquisition ATR submodule Q4 from described card;
Described first connexon module Q3, specifically comprises:
First sends link order unit Q3-1, for sending link order time delay Preset Time to described card, reading connection response data, upgrading described third reading and get number of times, and trigger the 5th judging unit Q3-2 from described card;
5th judging unit Q3-2, for judging that described third reading is got number of times and whether is less than preset value;
6th judging unit Q3-3, at described 5th judging unit Q3-2, judges that described third reading gets number of times when being less than preset value, judges whether successfully to read described connection response data;
3rd zero unit Q3-4, for when described 6th judging unit Q3-3 judges successfully to read described connection response data, gets number of times and resets, and trigger the first acquisition ATR submodule Q4 by described third reading.
First obtains ATR submodule Q4, obtaining ATR instruction, reading ATR response data from described card, sending ATR response data, and trigger described detection module 309 to described host computer for sending to described card.
Described first obtains ATR submodule Q4, specifically comprises:
First sends acquisition ATR command unit Q4-4, and obtain ATR instruction for sending to described card, time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times, and triggers the 7th judging unit Q4-4;
7th judging unit Q4-4, for judging whether described 4th reading times is less than preset value;
8th judging unit Q4-4, for when described 7th judging unit Q4-4 judges that described 4th reading times is less than preset value, judges whether successfully to read described ATR response data;
4th zero unit Q4-4, for when described 8th judging unit Q4-4 judges successfully to read described ATR response data, resets described 4th reading times, sends ATR response data, and trigger described detection module 309 to described host computer.
Second disconnects submodule Q5, when the data for judging to get at described second judge module 312 are lower electric instruction, sends open command to card, reads and disconnect response data from described card, and triggers the first unblock binding submodule Q6;
First unlocks binding submodule Q6, unlocking binding instruction, reading and unlocking binding response data from described card for sending to described card, sends lower electric successful information, and trigger described detection module 309 to described host computer.
Described first unlocks binding submodule Q6, comprising:
First sends unblock binding command unit Q6-1, and unlock binding instruction, time delay Preset Time for sending to described card, from described card, reading unlocks binding response data, upgrades described 5th reading times, and triggers the 9th judging unit Q6-2;
9th judging unit Q6-2, for judging whether described 5th reading times is less than preset value;
Tenth judging unit Q6-3, for when described 9th judging unit Q6-2 judges that described 5th reading times is less than preset value, judges whether successfully to read described unblock binding response data;
5th zero unit Q6-4, during for judging at described tenth judging unit Q6-3 successfully to read described unblock binding response data, resetting described 5th reading times, sending lower electric successful information, and trigger described detection module 309 to described host computer.
3rd judge module 314, for judge at described second judge module 312 data got as memory channel instruction time, judge whether to perform described memory channel instruction according to described card mark and described memory channel instruction;
In the present embodiment, described 3rd judge module 314, specifically for obtaining described memory channel instruction first presets the data in byte, it can be used as destination address, if described destination address is described assigned address, and described card mark is intelligent SD card mark, then determine to perform described memory channel instruction; Otherwise determine to perform described memory channel instruction.
5th processing module 315, for when described 3rd judge module 314 judges to perform described memory channel instruction, performs described memory channel instruction, and triggers described detection module 309.
In the present embodiment, described 5th processing module 315, specifically comprises:
5th processing module judges submodule R1, for when described 3rd judge module 314 judges to perform described memory channel instruction, judges the type of described memory channel instruction according to the second data preset in byte of described memory channel instruction;
5th processing module read operation module R2, for when described 5th processing module judges that submodule R1 judges that memory channel instruction is read operation instruction, reads the data in described destination address, and sends it to described host computer, and detection trigger module 309;
5th processing module write operation module R3, for when described 5th processing module judges that submodule R1 judges that memory channel instruction is write operation instruction, obtain the data in the 3rd default byte of described memory channel instruction, it can be used as data length to be written, data to be written are obtained according to next byte of described data length to be written 3rd default byte from described memory channel instruction, and write in described destination address, send write operation to described host computer and complete information, and detection trigger module 309.
First enable module 316, for described card mark being set to common SD card mark in described second processing module 305, described Backup Data is write in described assigned address, when defining the configuration information of scsi interface, enable USB connects, and triggers the first configuration information sending module 306;
First enable module 317, during for defining the configuration information of the configuration information of CCID interface and scsi interface in described 3rd processing module 307, enable USB connects, and triggers the second configuration information sending module 308;
4th judge module 318, for when the configuration information of described scsi interface is sent to described host computer by described first configuration information sending module 306, carry out USB and enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module 309; When the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described second configuration information sending module 308, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module 309.
6th processing module 319, specifically for when intelligent SD card communication instruction is exchanges data instruction described in described 4th processing module 313, sends to described card and obtains APDU instruction, and trigger the 7th processing module 320;
7th processing module 320, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the 5th judge module 321;
5th judge module 321, for judging whether described 6th reading times is less than preset value;
6th judge module 322, for when described 5th judge module 321 judges that described 6th reading times is less than preset value, judges whether APDU response data reads successfully;
8th processing module 323, for when described 6th judge module 322 judges that APDU response data reads successfully, resets described 6th reading times, described APDU response data is sent to described host computer, and detection trigger module 309.
Embodiment 4
The present embodiment provides the card reader of a kind of operative intelligence SD card and common SD card, comprising:
Initial mark module 401, for carrying out initialization, the configuration information of definition CCID interface and the configuration information of scsi interface, draw-in groove state is set to without card, first reading times is reset, the second reading times is reset, third reading is got number of times and reset, 4th reading times is reset, the 5th reading times is reset;
Interface configuration information sending module 402, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and triggering judges interrupt module 403;
Judging interrupt module 403, for judging whether the interrupt identification that there is set, and judging the type of the interrupt identification of set;
First interruption processing module 404, for judging at described judgement interrupt module 403 interrupt identification that there is set, and when the interrupt identification of set is USB reception Data Labels, obtains the data in USB storage, and triggers the first judgement interface module 406;
Operational module 405, for judging at described judgement interrupt module 403 interrupt identification that there is set, and the interrupt identification of set for other indicate time, execution corresponding operating, and trigger described judgement interrupt module 403;
In the present embodiment, described operational module 405, specifically for judging at described judgement interrupt module 403 interrupt identification that there is set, and when the interruption of set is designated and snaps into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sends to described host computer and has card to respond, and described draw-in groove state has been saved as card do not power on, and trigger described judgement interrupt module 403; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, trigger described judgement interrupt module 403.
First judges interface module 406, for judging the interface of the data received in described USB storage;
First interface processing module 407, for when described first judges that interface module 406 judges that the interface of the data received in USB storage is first interfaces, corresponding operating is performed according to the data in the described USB storage of the configuration information of described scsi interface, and generating run code, send described operational code to host computer, and trigger described judgement interrupt module 403;
Second interface processing module 408, for when described first judges that interface module 406 judges that the interface of the data received in USB storage is second interfaces, communicate with card according to the data in described USB storage, communication response is read from described card, and described communication response is sent to host computer, and trigger described judgement interrupt module 403.
In the present embodiment, described second interface processing module 408, comprising:
First decision instruction type submodule, for when described first judges that interface module 406 judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
First instruction process submodule, for judge at described first decision instruction type submodule data in described USB storage as power on instruction time, send binding instruction to card, from described card, read binding response data, and trigger the second instruction process submodule;
In the present embodiment, it is identical that described first instruction process submodule and first in embodiment 3 bind submodule.
Second instruction process submodule, for sending open command to described card, reading and disconnecting response data, and triggering the 3rd instruction process submodule from described card;
In the present embodiment, it is identical that described second instruction process submodule and first in embodiment 3 disconnect submodule.
3rd instruction process submodule, for sending link order to described card, reading connection response data, and triggering the 4th instruction process submodule from described card;
In the present embodiment, described 3rd instruction process submodule is identical with the first connexon module in embodiment 3.
4th instruction process submodule, obtaining ATR instruction for sending to described card, reading ATR response data, sending described ATR response data to described host computer, and trigger described judgement interrupt module 403 from described card.
In the present embodiment, it is identical that described 4th instruction process submodule and first in embodiment 3 obtain ATR submodule.
Second decision instruction type submodule, for when described first judges that interface module 406 judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
5th instruction process submodule, when data for judging in described USB storage at described second decision instruction type submodule are lower electric instruction, send open command to card, read from described card and disconnect response data, and trigger the 6th instruction process submodule;
6th instruction process submodule, unlocking binding instruction for sending to described card, reading and unlocking binding response data from described card, sends lower electric successful information, and trigger described judgement interrupt module 403 to described host computer.
In the present embodiment, described 6th instruction process submodule and first in embodiment 3 unlock that to bind submodule identical.
7th instruction process submodule, when the data for judging in described USB storage at described 3rd decision instruction type submodule being exchanges data instruction, sending to card and obtaining APDU instruction, and triggering the first reading submodule;
First reading submodule, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the first judgement submodule;
First judges submodule, for judging whether described 6th reading times is less than preset value;
Second judges submodule, for when described first judges that submodule judges that described 6th reading times is less than preset value, judges whether successfully to read described APDU response data;
First sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, described 6th reading times being reset, described APDU response data is sent to described host computer;
Second sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, sending read failure information to described host computer.
Enable link block 409, for carrying out initialization in described initial mark module 401, during the configuration information of the configuration information of definition CCID interface and scsi interface, enable USB connects, and trigger interface configuration information sending module 402;
Enumerate judge module 410, for when the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described interface configuration information sending module 402, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, triggers and judge interrupt module 403.
The above; be only the specific embodiment of the present invention, but protection scope of the present invention is not limited thereto, is anyly familiar with those skilled in the art in the technical scope that the present invention discloses; change can be expected easily or replace, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should described be as the criterion with the protection domain of claim.

Claims (48)

1. a method of work for the card reader of operative intelligence SD card and common SD card, is characterized in that, comprising:
Step S1: described card reader carries out initialization, is set to intelligent SD card mark by card mark, reads the data in assigned address, and using the data that read as Backup Data;
Step S2: described card reader sends binding instruction to card, the data that described card returns are read from described assigned address, judge that whether the data that described card returns are identical with described binding instruction, that described card mark is set to common SD card mark, described Backup Data is write in described assigned address, the configuration information of definition scsi interface, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of described scsi interface is sent to described host computer, and performs step S3; Otherwise the configuration information of definition CCID interface and the configuration information of scsi interface, when receiving the configuration information instruction of the acquisition interface that host computer issues, the configuration information of described CCID interface and the configuration information of described scsi interface are sent to described host computer, and performs step S3;
Step S3: described card reader judges whether the interrupt identification that there is set, the interrupt identification of if there is no set, then return step S3; If there is the interrupt identification of set, then judge the type of the interrupt identification of described set, if the interrupt identification of described set is USB receive Data Labels, then obtain the data in USB storage, and the data got are judged, if intelligent SD card communication instruction, then perform step S4; If memory channel instruction, then perform step S5;
Step S4: described card reader communicates with described card according to described intelligent SD card communication instruction, reads communication response from described card, and described communication response is sent to described host computer, returns step S3;
Step S5: described card reader, according to described card mark and described memory channel instruction, judges whether to perform described memory channel instruction, is, perform described memory channel instruction, return step S3; Otherwise return step S3.
2. the method for claim 1, is characterized in that, in described step S2, after the configuration information of described card reader definition scsi interface, also comprises: the enable USB of described card reader connects;
In described step S2, described card reader also comprises after defining the configuration information of CCID interface and the configuration information of scsi interface: the enable USB of described card reader connects;
Before described step S3, also comprise:
Step S3-1: described card reader is carried out USB and enumerated, judges whether USB interface is connection status, is, performs described step S3; Otherwise return step S3-1.
3. the method for claim 1, is characterized in that, described card reader carries out initialization, comprising: draw-in groove state is set to without card by described card reader;
Described step S3, also comprises:
If the interrupt identification of described set snaps into bit flag, described card reader performs following steps:
Step a1: described card reader is draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then performs step a2; If without card, then perform step a3;
Step a2: described card reader sends to host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and returns step S3;
Step a3: described card reader sends without card response to host computer, and described draw-in groove state is saved as without card, returns step S3.
4. the method for claim 1, is characterized in that, described intelligent SD card communication instruction is the instruction that powers on;
Described step S4, is specially:
Step c1: described card reader sends binding instruction to described card;
Step c2: described card reader reads binding response data from described card, sends open command to described card;
Step c3: described card reader reads and disconnects response data from described card, sends link order to described card;
Step c4: described card reader reads connection response data from described card, sends to described card and obtains ATR instruction;
Step c5: described card reader reads ATR response data from described card, sends described ATR response data to described host computer, returns step S3.
5. method as claimed in claim 4, it is characterized in that, described card reader carries out initialization, also comprises: the first reading times reset;
Described step c2, comprising:
Step c2-1: described card reader time delay Preset Time, reads binding response data, upgrades described first reading times from described card;
Step c2-2: described card reader judges whether described first reading times is less than preset value, is perform step c2-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c2-3: described card reader judges whether successfully to read described binding response data, is perform step c2-4; Otherwise return step c2-1;
Step c2-4: described first reading times resets by described card reader, sends open command to described card, performs step c3.
6. method as claimed in claim 4, it is characterized in that, described card reader carries out initialization, comprising: the second reading times reset;
Described step c3 comprises:
Step c3-1: described card reader time delay Preset Time, reads and disconnects response data, upgrade described second reading times from described card;
Step c3-2: described card reader judges whether described second reading times is less than preset value, is perform step c3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c3-3: described card reader judges whether successfully to read described disconnection response data, is perform step c3-4; Otherwise return step c3-1;
Step c3-4: described second reading times resets by described card reader, sends link order to described card, performs step c4.
7. method as claimed in claim 4, it is characterized in that, described card reader is carried out initialization and is comprised: third reading is got number of times and reset;
Described step c4, specifically comprises:
Step c4-1: described card reader time delay Preset Time, reads connection response data, upgrades described third reading and get number of times from described card;
Step c4-2: described card reader judges that described third reading is got number of times and whether is less than preset value, is perform step c4-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c4-3: described card reader judges whether successfully to read described connection response data, is perform step c4-4; Otherwise return step c4-1;
Step c4-4: described third reading is got number of times and reset by described card reader, sends to described card and obtains ATR instruction, perform step c5.
8. method as claimed in claim 4, it is characterized in that, described card reader carries out initialization, comprising: the 4th reading times reset;
Described step c5 comprises:
Step c5-1: described card reader time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times;
Step c5-2: described card reader judges whether described 4th reading times is less than preset value, is perform step c5-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Step c5-3: described card reader judges whether successfully to read described ATR response data, is perform step c5-4; Otherwise return step c5-1;
Step c5-4: described 4th reading times resets by described card reader, sends described ATR response data, return step S3 to described host computer.
9. the method for claim 1, is characterized in that, described intelligent SD card communication instruction is lower electric instruction;
Described step S4, is specially:
Steps d 1: described card reader sends open command to described card;
Steps d 2: described card reader reads and disconnects response data from described card, sends to described card and unlocks binding instruction;
Steps d 3: described card reader reads and unlocks binding response data from described card, sends lower electric successful information to described host computer, returns step S3.
10. method as claimed in claim 9, it is characterized in that, described card reader is carried out initialization and is comprised: the 5th reading times reset;
Described steps d 3 comprises:
Steps d 3-1: described card reader time delay Preset Time, reads described unblock binding response data, upgrades described 5th reading times from described card;
Steps d 3-2: described card reader judges whether described 5th reading times is less than preset value, is perform steps d 3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step S3;
Steps d 3-3: described card reader judges whether successfully to read described unblock binding response data, is perform steps d 3-4; Otherwise return steps d 3-1;
Steps d 3-4: described 5th reading times resets by described card reader, sends lower electric successful information to described host computer, returns step S3.
11. the method for claim 1, is characterized in that, described card reader is carried out initialization and comprised: the 6th reading times reset;
Described intelligent SD card communication instruction is exchanges data instruction;
Described step S4, is specially:
Step b1: described card reader sends to described card and obtains APDU instruction;
Step b2: described card reader time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times;
Step b3: described card reader judges whether described 6th reading times is less than preset value, is perform step b4; Otherwise send to described host computer and read failure information, return step S3;
Step b4: described card reader judges whether successfully to read described APDU response data, is perform step b5; Otherwise return step b2;
Step b5: described 6th reading times resets by described card reader, described APDU response data is sent to described host computer, returns step S3.
12. the method for claim 1, is characterized in that,
Described card reader, according to described card mark and described memory channel instruction, judges whether to perform described memory channel instruction, is specially:
Described card reader obtains the data in the first default byte of described memory channel instruction, it can be used as destination address, if described destination address is described assigned address, and described card mark is intelligent SD card mark, then perform described memory channel instruction, return step S3; Otherwise return step S3.
13. methods as claimed in claim 12, is characterized in that, described card reader performs described memory channel instruction and specifically comprises:
Step e1: described card reader judges the type of described memory channel instruction according to second of described memory channel instruction the data preset in byte, if read operation instruction, then performs step e2; If write operation instruction, then perform step e3;
Step e2: described card reader reads the data in described destination address, and send it to described host computer, return step S3;
Step e3: described card reader obtains the data in the 3rd default byte of described memory channel instruction, it can be used as data length to be written, data to be written are obtained according to next byte of described data length to be written 3rd default byte from described memory channel instruction, and write in described destination address, send write operation to described host computer and complete information, return step S3.
The method of work of the card reader of 14. 1 kinds of operative intelligence SD cards and common SD card, is characterized in that, comprising:
Step W1: card reader carries out initialization, the configuration information of definition CCID interface and the configuration information of scsi interface, when described card reader receives the configuration information instruction of the acquisition interface that host computer issues, the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer;
Step W2: described card reader judges whether the interrupt identification that there is set, the interrupt identification of if there is no set, then return step W2; If there is the interrupt identification of set, then judge the type of the interrupt identification of described set, if the interrupt identification of described set is USB receive Data Labels, then perform step W3; If the interrupt identification of described set is other marks, then performs corresponding operating, return step W2;
Step W3: described card reader obtains the data in USB storage, judges the interface of the data received in described USB storage, if first interface, then performs step W4; If the second interface, then perform step W5;
Step W4: described card reader performs corresponding operating according to the configuration information of scsi interface to the data in described USB storage, and generating run code, send described operational code to described host computer, return step W2;
Step W5: described card reader communicates with card according to the data in described USB storage, reads communication response from described card, and described communication response is sent to described host computer, returns step W2.
15. methods as claimed in claim 14, is characterized in that, between described W1 and step W2, comprising: the enable USB of described card reader connects;
In described step W2, described card reader judges whether the interrupt identification that there is set, and before judging the type of the interrupt identification of set, also comprises:
Step W2-1: described card reader is carried out USB and enumerated, judges whether USB interface is connection status, is, described card reader judges whether the interrupt identification that there is set, and judges the type of the interrupt identification of set; Otherwise return step W2-1.
16. methods as claimed in claim 14, it is characterized in that, described card reader carries out initialization, comprising: draw-in groove state be set to without card;
When the type of the interrupt identification of described set is when snapping into bit flag, described card reader performs following steps:
Step k1: described card reader is draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then performs step k2; If without card, then perform step k3;
Step k2: described card reader sends to described host computer has card to respond, and described draw-in groove state has been saved as card do not power on, return step W2;
Step k3: described card reader sends without card response to described host computer, and described draw-in groove state is saved as without card, returns step W2.
17. methods as claimed in claim 14, it is characterized in that, the data in described USB storage are the instruction that powers on;
Described step W5, is specially:
Step m1: described card reader sends binding instruction to card;
Step m2: described card reader reads binding response data from described card, sends open command to described card;
Step m3: described card reader reads and disconnects response data from described card, sends link order to described card;
Step m4: described card reader reads connection response data from described card, sends to described card and obtains ATR instruction;
Step m5: described card reader reads ATR response data from described card, sends described ATR response data to described host computer, returns step W2.
18. methods as claimed in claim 17, it is characterized in that, described card reader carries out initialization, comprising: the first reading times reset;
Described step m2 comprises:
Step m2-1: described card reader time delay Preset Time, reads binding response data, upgrades described first reading times from described card;
Step m2-2: described card reader judges whether described first reading times is less than preset value, is perform step m2-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m2-3: described card reader judges whether successfully to read described binding response data, is perform step m2-4; Otherwise return step m2-1;
Step m2-4: described first reading times resets by described card reader, sends open command to described card, performs step m3.
19. methods as claimed in claim 17, it is characterized in that, described card reader carries out initialization, comprising: the second reading times reset;
Described step m3 comprises:
Step m3-1: described card reader time delay Preset Time, reads and disconnects response data, upgrade described second reading times from described card;
Step m3-2: described card reader judges whether described second reading times is less than preset value, is perform step m3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m3-3: described card reader judges whether successfully to read described disconnection response data, is perform step m3-4; Otherwise return step m3-1;
Step m3-4: described second reading times resets by described card reader, sends link order to described card, performs step m4.
20. methods as claimed in claim 17, it is characterized in that, described card reader carries out initialization, comprising: third reading is got number of times and reset;
Described step m4 comprises:
Step m4-1: described card reader time delay Preset Time, reads connection response data, upgrades described third reading and get number of times from described card;
Step m4-2: described card reader judges that described third reading is got number of times and whether is less than preset value, is perform step m4-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m4-3: described card reader judges whether successfully to read described connection response data, is perform step m4-4; Otherwise return step m4-1;
Step m4-4: described third reading is got number of times and reset by described card reader, sends to described card and obtains ATR instruction, perform step m5.
21. methods as claimed in claim 17, it is characterized in that, described card reader carries out initialization, comprising: the 4th reading times reset;
Described step m5 comprises:
Step m5-1: described card reader time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times;
Step m5-2: described card reader judges whether described 4th reading times is less than preset value, is perform step m5-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step m5-3: described card reader judges whether successfully to read described ATR response data, is perform step m5-4; Otherwise return step m5-1;
Step m5-4: described 4th reading times resets by described card reader, sends described ATR response data, return step W2 to described host computer.
22. methods as claimed in claim 14, is characterized in that, the data in described USB storage are lower electric instruction;
Described step W5, is specially:
Step n1: described card reader sends open command to card;
Step n2: described card reader reads and disconnects response data from described card, sends to described card and unlocks binding instruction;
Step n3: described card reader reads and unlocks binding response data from described card, sends lower electric successful information to described host computer, returns step W2.
23. methods as claimed in claim 22, it is characterized in that, described card reader is carried out initialization and is comprised: the 5th reading times reset;
Described step n3 comprises:
Step n3-1: described card reader time delay Preset Time, reads described unblock binding response data, upgrades described 5th reading times from described card;
Step n3-2: described card reader judges whether described 5th reading times is less than preset value, is perform step n3-3; Otherwise described card reader sends to described host computer and reads failure information, returns step W2;
Step n3-3: described card reader judges whether described unblock binding response data reads successfully, is perform step n3-4; Otherwise return step n3-1;
Step n3-4: described 5th reading times resets by described card reader, sends lower electric successful information to described host computer, returns step W2.
24. methods as claimed in claim 14, it is characterized in that, described card reader is carried out initialization and is comprised: the 6th reading times reset;
Data in described USB storage are exchanges data instruction;
Described step W5, is specially:
Step l1: described card reader sends to described card and obtains APDU instruction;
Step l2: described card reader time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times;
Step l3: described card reader judges whether described 6th reading times is less than preset value, is perform step l4; Otherwise send to described host computer and read failure information, return step W2;
Step l4: described card reader judges whether described APDU response data reads successfully, is perform step l5; Otherwise return step l2;
Step l5: described 6th reading times resets by described card reader, described APDU response data is sent to described host computer, returns step W2.
The card reader of 25. 1 kinds of operative intelligence SD cards and common SD card, is characterized in that, comprising:
Initialization module, for carrying out initialization, is set to intelligent SD card mark by card mark;
Read module, for reading the data in assigned address, and using the data that read as Backup Data, and triggers the first processing module;
First processing module, for sending binding instruction to card, reading the data that described card returns, and triggering the first judge module from described assigned address;
Whether the first judge module is identical with described binding instruction for judging the data that described card returns;
Second processing module, during for judging that the data that described card returns are identical with described binding instruction at described first judge module, described card mark is set to common SD card mark, described Backup Data is write in described assigned address, the configuration information of definition scsi interface, and trigger the first configuration information sending module;
First configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the configuration information of described scsi interface, and detection trigger module;
3rd processing module, during for judging that the data that described card returns are not identical with described binding instruction at described first judge module, the configuration information of definition CCID interface and the configuration information of scsi interface, and trigger the second configuration information sending module;
Second configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and detection trigger module;
Detection module, for judging whether the interrupt identification that there is set, and judges the type of the interrupt identification of set;
First acquisition module, for judging at described detection module the interrupt identification that there is set, and when the interrupt identification of described set is USB reception Data Labels, obtains the data in USB storage, and triggers the second judge module;
Second judge module, judges for the data got described first acquisition module;
4th processing module, when data for judging to get at described second judge module are intelligent SD card communication instruction, communicate with described card according to described intelligent SD card communication instruction, communication response is read from described card, and described communication response is sent to described host computer, and trigger described detection module;
3rd judge module, for judge at described second judge module the data got as memory channel instruction time, judge whether to perform described memory channel instruction according to described card mark and described memory channel instruction;
5th processing module, for when described 3rd judge module judges to perform described memory channel instruction, performs described memory channel instruction, and triggers described detection module.
26. card reader as claimed in claim 25, is characterized in that, also comprise:
First enable module, for described card mark being set to common SD card mark in described second processing module, described Backup Data is write in described assigned address, when defining the configuration information of scsi interface, enable USB connects, and triggers the first configuration information sending module;
Second enable module, for when the configuration information of the configuration information of described 3rd processing module definition CCID interface and scsi interface, enable USB connects, and triggers the second configuration information sending module;
4th judge module, for when the configuration information of described scsi interface is sent to described host computer by described first configuration information sending module, carry out USB and enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module; When the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described second configuration information sending module, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, detection trigger module.
27. card reader as claimed in claim 25, is characterized in that, described initialization module, also for draw-in groove state being set to without card;
Also comprise: the second acquisition module, for the interrupt identification that there is set being detected at described detection module, and when the interrupt identification of described set is for snapping into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sending to described host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and triggers described detection module; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, and trigger described detection module.
28. card reader as claimed in claim 25, is characterized in that,
4th processing module, comprising:
First binding submodule, for the data that judge to get at described second judge module as power on instruction time, send binding instruction to card, read from described card and bind response data, and trigger the first disconnection submodule;
First disconnects submodule, for sending open command to described card, reading and disconnecting response data, and trigger the first connexon module from described card;
First connexon module, for sending link order to described card, reading connection response data, and triggering the first acquisition ATR submodule from described card;
First obtains ATR submodule, obtaining ATR instruction, reading ATR response data from described card, sending ATR response data, and trigger described detection module to described host computer for sending to described card.
29. card reader as claimed in claim 28, is characterized in that, described initialization module, for the first reading times being reset;
Described first binding submodule, comprising:
First sends binding command unit, for the data that judge to get at described second judge module as power on instruction time, send to described card and bind instruction, time delay Preset Time, from described card, read binding response data, upgrade described first reading times, and trigger the first judging unit;
First judging unit, for judging whether described first reading times is less than preset value;
Second judging unit, for when described first judging unit judges that described first reading times is less than preset value, judges whether successfully to read described binding response data;
First zero unit, for when described second judging unit judges successfully to read described binding response data, resets described first reading times, and triggers the first disconnection submodule.
30. card reader as claimed in claim 28, is characterized in that, described initialization module, also for the second reading times being reset;
Described first disconnects submodule, comprising:
First sends open command unit, for sending open command to described card, time delay Preset Time, reading and disconnecting response data, upgrade described second reading times, and trigger the 3rd judging unit from described card;
3rd judging unit, for judging whether described second reading times is less than preset value;
4th judging unit, for when described 3rd judging unit judges that described second reading times is less than preset value, judges whether successfully to read described disconnection response data;
Second zero unit, for when described 4th judging unit judges successfully to read described disconnection response data, resets described second reading times, and triggers the first connexon module.
31. card reader as claimed in claim 28, is characterized in that, described initialization module, also reset for third reading being got number of times;
Described first connexon module, specifically comprises:
First sends link order unit, for sending link order time delay Preset Time to described card, reading connection response data, upgrading described third reading and get number of times, and trigger the 5th judging unit from described card;
5th judging unit, for judging that described third reading is got number of times and whether is less than preset value;
6th judging unit, at described 5th judging unit, judges that described third reading gets number of times when being less than preset value, judges whether successfully to read described connection response data;
3rd zero unit, for when described 6th judging unit judges successfully to read described connection response data, gets number of times and resets, and trigger the first acquisition ATR submodule by described third reading.
32. card reader as claimed in claim 28, is characterized in that, described initialization module, also for the 4th reading times being reset;
Described first obtains ATR submodule, specifically comprises:
First sends acquisition ATR command unit, and obtain ATR instruction for sending to described card, time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times, and triggers the 7th judging unit;
7th judging unit, for judging whether described 4th reading times is less than preset value;
8th judging unit, for when described 7th judging unit judges that described 4th reading times is less than preset value, judges whether successfully to read described ATR response data;
4th zero unit, for when described 8th judging unit judges successfully to read described ATR response data, resets described 4th reading times, sends ATR response data, and trigger described detection module to described host computer.
33. card reader as claimed in claim 25, is characterized in that,
Described 4th processing module, comprising:
Second disconnects submodule, when the data for judging to get at described second judge module are lower electric instruction, sends open command to card, reads and disconnect response data from described card, and triggers the first unblock binding submodule;
First unlocks binding submodule, unlocking binding instruction, reading and unlocking binding response data from described card for sending to described card, sends lower electric successful information, and trigger described detection module to described host computer.
34. card reader as claimed in claim 33, is characterized in that, described initialization module, for the 5th reading times being reset;
Described first unlocks binding submodule, comprising:
First sends unblock binding command unit, unlocks binding instruction, time delay Preset Time for sending to described card, and from described card, reading unlocks binding response data, upgrades described 5th reading times, and triggers the 9th judging unit;
9th judging unit, for judging whether described 5th reading times is less than preset value;
Tenth judging unit, for when described 9th judging unit judges that described 5th reading times is less than preset value, judges whether successfully to read described unblock binding response data;
5th zero unit, during for judging at described tenth judging unit successfully to read described unblock binding response data, resetting described 5th reading times, sending lower electric successful information, and trigger described detection module to described host computer.
35. card reader as claimed in claim 25, is characterized in that, described initialization module, also for the 6th reading times being reset;
Described card reader also comprises:
6th processing module, specifically for when intelligent SD card communication instruction is exchanges data instruction described in described 4th processing module, sends to described card and obtains APDU instruction, and trigger the 7th processing module;
7th processing module, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the 5th judge module;
5th judge module, for judging whether described 6th reading times is less than preset value;
6th judge module, for when described 5th judge module judges that described 6th reading times is less than preset value, judges whether APDU response data reads successfully;
8th processing module, for when described 6th judge module judges that APDU response data reads successfully, resets described 6th reading times, described APDU response data is sent to described host computer, and detection trigger module.
36. card reader as claimed in claim 25, is characterized in that,
Described 3rd judge module, specifically for obtaining described memory channel instruction first presets the data in byte, it can be used as destination address, if described destination address is described assigned address, and described card mark is intelligent SD card mark, then determine to perform described memory channel instruction; Otherwise determine to perform described memory channel instruction.
37. card reader as claimed in claim 36, is characterized in that, described 5th processing module, specifically comprises:
5th processing module judges submodule, for when described 3rd judge module judges to perform described memory channel instruction, judges the type of described memory channel instruction according to the second data preset in byte of described memory channel instruction;
5th processing module read operation module, for when described 5th processing module judges that submodule judges that memory channel instruction is read operation instruction, reads the data in described destination address, and sends it to described host computer, and trigger described detection module;
5th processing module write operation module, for when described 5th processing module judges that submodule judges that memory channel instruction is write operation instruction, obtain the data in the 3rd default byte of described memory channel instruction, it can be used as data length to be written, data to be written are obtained according to next byte of described data length to be written 3rd default byte from described memory channel instruction, and write in described destination address, send write operation to described host computer and complete information, and trigger described detection module.
The card reader of 38. 1 kinds of operative intelligence SD cards and common SD card, its feature is being, comprising:
Initial mark module, for carrying out initialization, the configuration information of definition CCID interface and the configuration information of scsi interface;
Interface configuration information sending module, for when receiving the configuration information instruction of the acquisition interface that host computer issues, sends to described host computer by the described configuration information of CCID interface and the configuration information of scsi interface, and triggering judges interrupt module;
Judging interrupt module, for judging whether the interrupt identification that there is set, and judging the type of the interrupt identification of set;
First interruption processing module, for judging at described judgement interrupt module the interrupt identification that there is set, and when the interrupt identification of set is USB reception Data Labels, obtains the data in USB storage, and triggers the first judgement interface module;
First judges interface module, for judging the interface of the data received in described USB storage;
First interface processing module, for when described first judges that interface module judges that the interface of the data received in USB storage is first interfaces, corresponding operating is performed according to the data in the described USB storage of the configuration information of described scsi interface, and generating run code, send described operational code to host computer, and trigger described judgement interrupt module;
Second interface processing module, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, communicate with card according to the data in described USB storage, communication response is read from described card, and described communication response is sent to host computer, and trigger described judgement interrupt module.
39. card reader as claimed in claim 38, is characterized in that, also comprise:
Enable link block, for carrying out initialization in described initial mark module, during the configuration information of the configuration information of definition CCID interface and scsi interface, enable USB connects, and trigger interface configuration information sending module;
Enumerate judge module, for when the described configuration information of CCID interface and the configuration information of scsi interface are sent to described host computer by described interface configuration information sending module, carry out USB to enumerate, judge whether USB interface is connection status, and when described USB interface is connection status, triggers and judge interrupt module.
40. card reader as claimed in claim 38, is characterized in that, described initial mark module, also for draw-in groove state being set to without card;
Also comprise: operational module, for judging at described judgement interrupt module the interrupt identification that there is set, and when the interruption of set is designated and snaps into bit flag, draw-in groove state according to the electrical level judging snapping into a pin, if there is card not power on, then sending to described host computer has card to respond, and described draw-in groove state has been saved as card does not power on, and triggers described judgement interrupt module; If without card, then send without card response to described host computer, and described draw-in groove state is saved as without card, trigger described judgement interrupt module.
41. card reader as claimed in claim 38, it is characterized in that, described second interface processing module, comprising:
First decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
First instruction process submodule, for judge at described first decision instruction type submodule data in described USB storage as power on instruction time, send binding instruction to card, from described card, read binding response data, and trigger the second instruction process submodule;
Second instruction process submodule, for sending open command to described card, reading and disconnecting response data, and triggering the 3rd instruction process submodule from described card;
3rd instruction process submodule, for sending link order to described card, reading connection response data, and triggering the 4th instruction process submodule from described card;
4th instruction process submodule, obtaining ATR instruction for sending to described card, reading ATR response data, sending described ATR response data to described host computer, and trigger described judgement interrupt module from described card.
42. card reader as claimed in claim 41, is characterized in that, described initial mark module, also for the first reading times being reset;
Described first instruction process submodule, comprising:
First sends binding command unit, for the first decision instruction type submodule judge data in described USB storage as power on instruction time, binding instruction is sent to described card, time delay Preset Time, binding response data is read from described card, upgrade described first reading times, and trigger the first judging unit;
First judging unit, for judging whether described first reading times is less than preset value;
Second judging unit, for when described first judging unit judges that described first reading times is less than preset value, judges whether successfully to read described binding response data;
First zero unit, for when described second judging unit judges successfully to read described binding response data, resets described first reading times, and triggers the second instruction process submodule.
43. card reader as claimed in claim 41, is characterized in that, described initial mark module, also for the second reading times being reset;
Described second instruction process submodule, specifically comprises:
First sends open command unit, for sending open command to described card, time delay Preset Time, reading and disconnecting response data, upgrade described second reading times, and trigger the 3rd judging unit from described card;
3rd judging unit, for judging whether described second reading times is less than preset value;
4th judging unit, for when described 3rd judging unit judges that described second reading times is less than preset value, judges whether successfully to read described disconnection response data;
Second zero unit, for when described 4th judging unit judges successfully to read described disconnection response data, resets described second reading times, and triggers the 3rd instruction process submodule.
44. card reader as claimed in claim 41, is characterized in that, described initial mark module, also reset for third reading being got number of times;
Described 3rd instruction process submodule, specifically comprises:
First sends link order unit, for sending link order time delay Preset Time to described card, reading connection response data, upgrading described third reading and get number of times, and trigger the 5th judging unit from described card;
5th judging unit, for judging that described third reading is got number of times and whether is less than preset value;
6th judging unit, at described 5th judging unit, judges that described third reading gets number of times when being less than preset value, judges whether successfully to read described connection response data;
3rd zero unit, for when described 6th judging unit judges successfully to read described connection response data, gets number of times and resets, and trigger the 4th instruction process submodule by described third reading.
45. card reader as claimed in claim 41, is characterized in that, described initial mark module, also for the 4th reading times being reset;
Described 4th instruction process submodule, specifically comprises:
First sends acquisition ATR command unit, and obtain ATR instruction for sending to described card, time delay Preset Time, reads ATR response data from described card, upgrades described 4th reading times, and triggers the 7th judging unit;
7th judging unit, for judging whether described 4th reading times is less than preset value;
8th judging unit, for when described 7th judging unit judges that described 4th reading times is less than preset value, judges whether successfully to read described ATR response data;
4th zero unit, for when described 8th judging unit judges successfully to read described ATR response data, resets described 4th reading times, sends ATR response data, and trigger described judgement interrupt module to described host computer.
46. card reader as claimed in claim 38, it is characterized in that, described second interface processing module, also comprises:
Second decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
5th instruction process submodule, when data for judging in described USB storage at described second decision instruction type submodule are lower electric instruction, send open command to card, read from described card and disconnect response data, and trigger the 6th instruction process submodule;
6th instruction process submodule, unlocking binding instruction for sending to described card, reading and unlocking binding response data from described card, sends lower electric successful information, and trigger described judgement interrupt module to described host computer.
47. card reader as claimed in claim 46, is characterized in that, described initial mark module, for the 5th reading times being reset;
Described 6th instruction process submodule, comprising:
First sends unblock binding command unit, unlocks binding instruction, time delay Preset Time for sending to described card, and from described card, reading unlocks binding response data, upgrades described 5th reading times, and triggers the 9th judging unit;
9th judging unit, for judging whether described 5th reading times is less than preset value;
Tenth judging unit, for when described 9th judging unit judges that described 5th reading times is less than preset value, judges whether successfully to read described unblock binding response data;
5th zero unit, during for judging at described tenth judging unit successfully to read described unblock binding response data, resetting described 5th reading times, sending lower electric successful information, and trigger described judgement interrupt module to described host computer.
48. card reader as claimed in claim 38, it is characterized in that, described second interface processing module, comprising:
3rd decision instruction type submodule, for when described first judges that interface module judges that the interface of the data received in USB storage is second interfaces, judges the data in described USB storage;
7th instruction process submodule, when the data for judging in described USB storage at described 3rd decision instruction type submodule being exchanges data instruction, sending to card and obtaining APDU instruction, and triggering the first reading submodule;
First reading submodule, for time delay Preset Time, reads APDU response data from described card, upgrades described 6th reading times, and triggers the first judgement submodule;
First judges submodule, for judging whether described 6th reading times is less than preset value;
Second judges submodule, for when described first judges that submodule judges that described 6th reading times is less than preset value, judges whether successfully to read described APDU response data;
First sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, described 6th reading times being reset, described APDU response data is sent to described host computer;
Second sends submodule, for judging submodule described second, when judging successfully to read described APDU response data, sending read failure information to described host computer.
CN201410413476.8A 2014-08-21 2014-08-21 The card reader and its method of work of a kind of operation intelligent SD card and common SD card Expired - Fee Related CN104268605B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410413476.8A CN104268605B (en) 2014-08-21 2014-08-21 The card reader and its method of work of a kind of operation intelligent SD card and common SD card

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410413476.8A CN104268605B (en) 2014-08-21 2014-08-21 The card reader and its method of work of a kind of operation intelligent SD card and common SD card

Publications (2)

Publication Number Publication Date
CN104268605A true CN104268605A (en) 2015-01-07
CN104268605B CN104268605B (en) 2017-06-06

Family

ID=52160125

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410413476.8A Expired - Fee Related CN104268605B (en) 2014-08-21 2014-08-21 The card reader and its method of work of a kind of operation intelligent SD card and common SD card

Country Status (1)

Country Link
CN (1) CN104268605B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104915616A (en) * 2015-05-15 2015-09-16 飞天诚信科技股份有限公司 Method for accessing smart card and card reader
CN108108317A (en) * 2017-12-29 2018-06-01 飞天诚信科技股份有限公司 A kind of method and apparatus for realizing the multiplex roles equipment for apple mobile terminal
CN109684885A (en) * 2018-12-27 2019-04-26 飞天诚信科技股份有限公司 A method of detection snaps into
CN110361784A (en) * 2019-08-23 2019-10-22 北京市燃气集团有限责任公司 A kind of pig tracing localization method and position indicator based on wireless transmission
CN111447779A (en) * 2020-04-28 2020-07-24 深圳市龙控智能技术有限公司 Intelligent data acquisition unit

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1996030857A1 (en) * 1995-03-31 1996-10-03 Cybermark, L.L.C. Intelligent card reader having emulation features
CN102737206A (en) * 2011-03-31 2012-10-17 深圳市文鼎创数据科技有限公司 Method for card reader to support multidevice and card reader
CN103310175A (en) * 2013-06-24 2013-09-18 飞天诚信科技股份有限公司 Standard CCID protocol based working method for multi-card-slot card reader

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1996030857A1 (en) * 1995-03-31 1996-10-03 Cybermark, L.L.C. Intelligent card reader having emulation features
CN102737206A (en) * 2011-03-31 2012-10-17 深圳市文鼎创数据科技有限公司 Method for card reader to support multidevice and card reader
CN103310175A (en) * 2013-06-24 2013-09-18 飞天诚信科技股份有限公司 Standard CCID protocol based working method for multi-card-slot card reader

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104915616A (en) * 2015-05-15 2015-09-16 飞天诚信科技股份有限公司 Method for accessing smart card and card reader
CN104915616B (en) * 2015-05-15 2017-11-28 飞天诚信科技股份有限公司 A kind of method and card reader for accessing smart card
CN108108317A (en) * 2017-12-29 2018-06-01 飞天诚信科技股份有限公司 A kind of method and apparatus for realizing the multiplex roles equipment for apple mobile terminal
CN108108317B (en) * 2017-12-29 2019-11-15 飞天诚信科技股份有限公司 A kind of method and apparatus for realizing the multiplex roles equipment for apple mobile terminal
CN109684885A (en) * 2018-12-27 2019-04-26 飞天诚信科技股份有限公司 A method of detection snaps into
CN110361784A (en) * 2019-08-23 2019-10-22 北京市燃气集团有限责任公司 A kind of pig tracing localization method and position indicator based on wireless transmission
CN111447779A (en) * 2020-04-28 2020-07-24 深圳市龙控智能技术有限公司 Intelligent data acquisition unit
CN111447779B (en) * 2020-04-28 2024-04-12 依米康软件技术(深圳)有限责任公司 Intelligent data acquisition device

Also Published As

Publication number Publication date
CN104268605B (en) 2017-06-06

Similar Documents

Publication Publication Date Title
CN104268605A (en) Card reader operating intelligent SD cards and ordinary SD cards and working method thereof
CN103310175B (en) A kind of method of work of the many draw-in grooves card reader based on standard CC ID agreement
CN101656974A (en) SIM card compatibility automated test method and device
EP3046393A1 (en) Switching device and method for automatically connecting to nfc chip and switching security element
CN215897719U (en) SIM card switching device and electronic equipment
CN102496814A (en) Intelligent socket and intelligent control system
CN103001075A (en) Mobile terminal (MT) and SIM card connector thereof
CN104077083A (en) New added storage method, device and system
CN104216829A (en) Method and system for concurrent testing of embedded module
CN102891716A (en) Intelligent management device for contact type optical fiber physical port
CN112822087B (en) Data distinguishing method, data distinguishing device, router and network relay equipment
CN104571942A (en) Data storage system and method analyzing non-signal
CN205049781U (en) Novel module is joined in marriage to intelligence light
CN208445551U (en) SIM card device applied to electric power acquisition remote communication module
CN101326538A (en) Memory card and memory card control changeover method
CN102496035A (en) System for realizing acquisition of data interacted between intelligent card and card terminal and method thereof
CN1878172A (en) USB unidirectional physical insulation network gap
CN103812720B (en) Network acceleration management method and device
CN107145913B (en) Application selection in a mobile terminal
CN202872787U (en) Intelligent device for managing contact type fiber physical port
CN1794635A (en) Digital filtering mode for communication data message transmission at multichannel field equipment state
CN203930122U (en) Detect optical fiber line concentrator and the supporting RFID label carrier of recognition function with RFID pairing
CN201340604Y (en) Composite contact card reader
CN101840344B (en) USB (Universal Serial Bus) device and method for automatically opening same on computer
CN101505233A (en) Method for switching optical transmission physical channel and physical interface equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20170606