CT-BCS(3)
π CT-BCS(3) β Cardterminal basic command set, bestie edition π
part of the Library Functions Manual β¨
πΈ NAME πΈ
CT-BCS β the Cardterminal basic command set for integrated circuit card applications. periodt.
π¦ DESCRIPTION π¦
okay so. this manpage is gonna walk you through the subset of the Cardterminal Basic Command Set (aka CT-BCS) that you use to control cardterminals β specifically the ones with one or more integrated circuit card slots, and no keypad, no display. that's the vibe.
real talk though: this is not the whole CT-BCS spec, it's just a general overview of the most common functionalities. so don't come for me if your fave niche command isn't here π
the CT-BCS commands are built in compliance with ISO/IEC 7816-4 interindustry commands, and you use them to control a cardterminal by way of the CT-API function CT_data(). that's the whole pipeline, bestie.
π COMMAND STRUCTURE π
a CT-BCS command is an array of bytes that gets sent to the cardterminal to perform an administrative action. the CT-BCS response is an array of bytes that the cardterminal hands back to tell you how it went β aka the completion status of the action you asked for. no cap.
here's the general structure of a CT-BCS command, look at her:
|<------------------------------------------>|
| Header (4 Bytes) and body |
| (mandatory) (optional) |
|<----------------->|<---------------------->|
|___________________|________________________|
|CLA |INS |P1 |P2 |Lc |Data |Le |
|____|____|____|____|____|______________|____|
and here's the general structure of a CT-BCS response:
|<------------------------------>|<--------->|
| Body Trailer |
| (optional) (2 Bytes) |
| (mandatory)|
|________________________________|___________|
|Data |SW1-SW2 |
|________________________________|___________|
the fields inside a CT-BCS command and response are equivalent to the ones defined by ISO/IEC 7816-4, so let's go field by field π₯
CLAβ Class. theCLAvalue used for CT-BCS commands is0x20.INSβ Instruction. this defines the action the cardterminal is gonna perform. it's giving "what are we doing today."P1,P2β Command parameters 1 and 2.Lcβ Length of the command data field.Leβ Length of expected data:- Case 1: no command data, no response data (no
Lcand noLe). - Case 2: command data, no response data (
0<=Lc<=254and noLe). - Case 3: no command data, response data (no
Lcand0<=Le<=254). - Case 4: command data, response data (
0<=Lc<=254and0<=Le<=254).
- Case 1: no command data, no response data (no
SW1,SW2β Status bytes. this is the completion status of the command, the moment of truth tbh.
the address value 0x01 (CT) shall be used as the destination address (dad) given to CT_data() when you're sending CT-BCS commands (see CT_data (3)). don't forget it, bestie π«Ά
the following commands are present in every CT-BCS implementation:
β Basic CT commands β
RESET CTβ INS code0x11REQUEST ICCβ INS code0x12GET STATUSβ INS code0x13EJECT ICCβ INS code0x15
the following general return codes SW1-SW2 may occur:
π General return codes π
0x6700β Wrong length0x6900β Command not allowed0x6A00β Wrong parametersP1,P20x6D00β Wrong instruction0x6E00β Class not supported
π§ FUNCTIONAL UNITS π§
functional units are entities that can be addressed as the target of CT-BCS commands. in some CT-BCS commands you have to specify a target functional unit β so like, you can't just vibe your way through those ones.
π Functional units π
- CT kernel β coding
0x00 - CT/ICC slot 1 β coding
0x01 - CT/ICC slot 2 β coding
0x02 - ... β coding
... - CT/ICC slot 14 β coding
0x0E
support for slots 2-14 depends on the cardterminal. functional units for keypad and display are defined for some cardterminals, but they are not described here. π
to be continued, bestie β part 2 is coming and we're not done yet π
π« COMMANDS DESCRIPTION π«
π RESET CT π
okay so the RESET CT command is literally just you asking the cardterminal to reset one specific functional unit, bestie. If that functional unit happens to be the CT kernel, then what goes down is a software reset β meaning all the status info (like, say, the info about which cards are inserted) gets wiped and then gathered all over again. And for ICC functional units? That's a full-on card reset. slay.
Optionally the answer to reset of the functional unit comes back to you in the response data. cute.
You can fire off a RESET CT command either after the cardterminal has been initialized, or after a communication error has happened. both valid, both iconic. β¨
The command structure is giving:
CLAβ0x20INSβ0x11(=RESET CT)P1β Functional unit:0x00= CT0x01-0x0E= ICC Interface 1-14
P2β Command qualifier:- In case
P1=0x00:0x00= No response
- In case
P1=0x01-0x0E:0x00= No response data0x01= Return complete ATR0x02= Return Historical Bytes
- In case
Lcfield β EmptyLefield β Empty or0x00: return full length of requested information
And the response structure, periodt:
- Data β Empty, ATR or Historical Bytes
- SW1-SW2 β Status Bytes
When the functional unit is CT (0x00), these status bytes can come back at you:
0x9000β Reset successful0x6400β Reset not successful
When the functional unit is a ICC slot (0x01 - 0x0E), these status bytes can come back:
0x9000β Synchronous ICC, reset successful0x9001β Asynchronous ICC, reset successful0x6400β Reset not successful
π REQUEST ICC π
The REQUEST ICC command is you telling the cardterminal: bestie, wait for an ICC to show up on this specific slot, for this specific amount of time. The command synchronously blocks the caller application β yes, it just sits there and waits, no cap β unless a time limit of 0 is specified. And the moment an ICC is presented, it gets automatically activated and reset. it's giving main character energy fr fr. π₯
The command structure is as follows:
CLAβ0x20INSβ0x12(=REQUEST ICC)P1β Functional unit:0x01-0x0E= ICC-Interface 1 - 14
P2β Command qualifier: Request handling instructions for the CTLcfield β Empty or length of subsequent data field- Data field β Empty (= immediate response required) or max. waiting time in seconds (1 byte, binary coding) for presenting the ICC
Lefield β Empty or0x00= Return full length of requested information
The parameter P2 carries the request handling instructions for the CT. The value of P2 is constructed of two 4-bits subfields:
- Bits b8-b5
0x0= No meaning- Other values reserved for future use
- Bits b4-b1
0x0= No response data0x1= Return complete ATR0x2= Return Historical Bytes
The response structure is as follows:
- Data β Empty, ATR or Historical Bytes
- SW1-SW2 β Status Bytes
The following status bytes can be returned:
0x9000β Synchronous ICC presented, reset successful0x9001β Asynchronous ICC, reset successful0x6200β No card presented within specified time0x6201β Card already present and activated0x6400β Reset not successful0x6900β Command with timer not supported
π GET STATUS π
The GET STATUS command is your lil info-gathering moment: it pulls cardterminal manufacturer information and ICC status information straight from the cardterminal. The info is represented by TLV (tag, length, value) encoded data objects. You specify the tag of the data object you want in the command, and the value comes back to you in the response. obsessed. π
The command structure is as follows:
CLAβ0x20INSβ0x13(=GET STATUS)P1β Functional unit:0x00= CT
P2β Command qualifier: Tag of data object to be returnedLcfield β Empty- Data field β Empty
Lefield βHx00= Return full length of requested information
The response structure is as follows:
- Data β Status information (only value field of data object)
- SW1-SW2 β Status Bytes
The following data objects are defined. Note that only value field is returned in the response:
Cardterminal manufacturer data object
- Tag =
0x46 - Length >=
15 - Value:
- CTM: Cardterminal manufacturer (5 bytes ASCII encoded). It consists of 2 bytes with the country code and 3 bytes with the manufacturer acronym
- CTT: Cardterminal type (5 bytes ASCII encoded). The value is manufacturer dependant
- CTSV: Cardterminal software version (5 bytes ASCII encoded). The value is manufacturer dependant
- DD: Discretionary data (any number of bytes including 0)
ICC status data object
- Tag =
0x80 - Length
- Value: One ICC status byte per ICC slot in the cardterminal.
- If b8-b1 =
0x00then no ICC is present in the slot. - If b1 = 1 and ICC is present in the slot and the bytes b3-b2 indicate whether the ICC is electrically connected (value 10) or electrically disconnected (value 01).
- If b8-b1 =
The following status bytes can be returned:
0x9000β Command successful
π€ EJECT ICC π€
The EJECT ICC command asks the cardterminal to deactivate the ICC. bestie, you must use this at the end of your communication with the card, or whenever an irreparable communication error occurs. like, not optional. it's the responsible thing to do. π
The command structure is as follows:
CLAβ0x20INSβ0x15(=EJECT ICC)P1β Functional unit:0x01-0x0E= ICC-Interface 1-14
P2β Command qualifier: Eject handling instructions for the CT (0x00for cardterminals without keypad and display)Lcfield β Empty or length of subsequent data field- Data field β Empty or time in seconds for removing the ICC
Lefield β Empty
The response structure is as follows:
- Data β Empty
- SW1-SW2 β Status Bytes
The following status bytes can be returned
0x9000β Command successful0x9001β Command successful, card removed0x6200β Card not removed within specified time
π SEE ALSO π
ctapi(3).
The MKT (Multifunktionale KartenTerminals) specifications, available for download from Teletrust web site http://www.teletrust.de (link to URL http://www.teletrust.de). In special the documents:
- Part 3: CT-API. Cardterminal Applications Programming Interface.
- Part 4: CT-BCS. Cardterminal Basic Command Set.
- Part 7: IC cards with synchronous transmission Part3: Usage of interindustry Commands.
ISO/IEC 7816: Identification cards - Integrated circuit(s) cards with contacts:
- Part 4: Interindustry commands for interchange.
π AUTHOR π
This manual page was written by Carlos Prados <cprados@yahoo.com>. π
and that's a wrap on the whole thing, bestie π the footer of this page is just CT-BCS(3) β that's your source/version tag and the date stamp hanging out at the bottom, so if you're citing it, that's the vibe to reference. go forth and reset some functional units. you ate. π¦β¨
π¦ where this page comes from
- ubuntu jammy: libtowitoko-dev 2.0.7-9build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms