Card(3)
π³ Card(3) β the Chipcard::PCSC::Card glow-up π
ok so bestie, this is the <pink>Chipcard::PCSC::Card</pink> page from the User Contributed Perl Documentation section, and honestly? She's a whole personality. Buckle up π
β¨ NAME β¨
Chipcard::PCSC::Card β the smart card communication library. that's it, that's the vibe. she talks to cards. π³
πΈ SYNOPSIS πΈ
ok here's the whole group chat in one screenshot, no cap:
$hCard = new Chipcard::PCSC::Card ($hContext, "GemPC430 0 0",
$Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE);
$RecvData = $hCard->Transmit([0xBC,0xB0,0x09,0xC8, 2]);
$hCard->Disconnect($Chipcard::PCSC::SCARD_LEAVE_CARD);
$hCard->Status();
$hCard->BeginTransaction();
$hCard->EndTransaction();
$hCard->TransmitWithCheck($apdu, $sw_expected [, $debug]);
$hCard->Control($control_code, \@data);
ISO7816Error($sw);
likeβ¦ look at her go π she's doing SO much.
π¦ DESCRIPTION π¦
so the <pink>Chipcard::PCSC::Card</pink> module implements the <pink>Chipcard::PCSC::Card</pink> class (yes, the module and the class have the same name, that's just how Perl rolls, we don't ask questions π).
objects from this class are literally your little messengers to a given reader. π you build them out of a reference to a PCSC object β that's the thing that actually drives the reader.
for more info about PC/SC (the whole ecosystem, not just this class), go read the pcscd(1) man page. it's giving required reading π
a <pink>Chipcard::PCSC::Card</pink> object uses the following properties (her little accessory collection π
):
$pcsccard_object->{hContext}β the reference to the underlying PCSC object$pcsccard_object->{hCard}β the current PCSC connection handle$pcsccard_object->{dwProtocol}β the protocol being used
π CONSTRUCTORS π
these are the methods that make a <pink>Chipcard::PCSC::Card</pink> object exist. main character creation energy β¨
$hCard = new Chipcard::PCSC::Card ($hContext);
constructs a brand new <pink>Chipcard::PCSC::Card</pink> object without connecting to any reader. she's here, she's just not linked up yet π
$hContext is mandatory and contains the reference to a valid PCSC object.
$hCard = new Chipcard::PCSC::Card ($hContext, $reader_name, $share_mode, $preferred_protocol);
constructs a new Chipcard::PCSC::Card object and connects to the specified reader. glow-up complete π₯
$hContextβ is mandatory and contains the reference to a valid PCSC object.$reader_nameβ is the name of the reader you want to connect to. it's of the form"GemPC410 0 0".
π pls note: you can get the list of available readers with a call to"$hContext->ListReaders()". (see the section named PCSC METHODS in theChipcard::PCSCman page for more info on"ListReaders".)
$share_modeβ is the desired mode of connection to the reader. it can be any of the following:$Chipcard::PCSC::SCARD_SHARE_EXCLUSIVEβ the application do not share the reader (she's possessive, it's fine π )$Chipcard::PCSC::SCARD_SHARE_SHAREDβ the application will allow others to share the reader.$Chipcard::PCSC::SCARD_SHARE_DIRECTβ (not used by PC/SC-lite)
$preferred_protocolβ is the protocol which should be used if possible. if the protocol is not available, another protocol will be used and"$hCard->{dwProtocol}"will be set accordingly. both"$hCard->{dwProtocol}"and$preferred_protocolaccept the following values:$Chipcard::PCSC::SCARD_PROTOCOL_T0β the T=0 protocol$Chipcard::PCSC::SCARD_PROTOCOL_T1β the T=1 protocol$Chipcard::PCSC::SCARD_PROTOCOL_RAWβ raw protocol
$hCard = new Chipcard::PCSC::Card ($hContext, $reader_name, $share_mode);
this method is equivalent to:
$hCard = new Chipcard::PCSC::Card ($hContext, $reader_name,
$share_mode,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1);
$hCard = new Chipcard::PCSC::Card ($hContext, $reader_name);
this method is equivalent to:
$hCard = new Chipcard::PCSC::Card ($hContext, $reader_name,
$Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1);
π CONSTRUCTION FAILURE π
not every glow-up goes to plan, and that's okay. <pink>Chipcard::PCSC::Card</pink> constructors return an undef value when the object can not be created. π
$Chipcard::PCSC::errno can be used to get more information about the error β she will tell you what went wrong, you just gotta ask. see the section ERROR HANDLING in the Chipcard::PCSC man page for more info.
π«Ά Chipcard::PCSC::Card METHODS π«Ά
here's the full roster of every method that can be used with a <pink>Chipcard::PCSC::Card</pink> object. she's versatile, she contains multitudes β¨
β $hCard->Connect($reader_name, $share_mode, $preferred_protocol);
Connect() can be used to connect to the reader and its smart card β but only if the connection hasn't been established yet. the default constructor can establish the connection if you give it enough parameters. (yes, she can do it herself, she just needs the info first π)
the return value upon successful completion is the protocol used to communicate with the smart card. it can be any of the following:
$Chipcard::PCSC::SCARD_PROTOCOL_T0β the T=0 protocol$Chipcard::PCSC::SCARD_PROTOCOL_T1β the T=1 protocol$Chipcard::PCSC::SCARD_PROTOCOL_RAWβ raw protocol$reader_nameβ is mandatory. it contains the name of the reader you want to connect to. it's of the form"GemPC410 0 0".
π pls note: you can get the list of available readers with a call to"$hContext->ListReaders()". (see the section named PCSC METHODS in theChipcard::PCSCman page for more info on"ListReaders".)
$share_modeβ is the desired mode of connection to the reader. it can be any of the following:$Chipcard::PCSC::SCARD_SHARE_EXCLUSIVEβ the application do not share the reader$Chipcard::PCSC::SCARD_SHARE_SHAREDβ the application will allow others to share the reader.$Chipcard::PCSC::SCARD_SHARE_DIRECTβ (not used by PCSClite)
$preferred_protocolβ is the protocol which should be used if possible. if the protocol is not available, another protocol will be used and"$hCard->{dwProtocol}"will be set accordingly.$preferred_protocolaccept the following values:$Chipcard::PCSC::SCARD_PROTOCOL_T0β the T=0 protocol$Chipcard::PCSC::SCARD_PROTOCOL_T1β the T=1 protocol$Chipcard::PCSC::SCARD_PROTOCOL_RAWβ raw protocol
β $hCard->Connect($reader_name, $share_mode);
this method is equivalent to:
$hCard->Connect($reader_name, $share_mode,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1);
β $hCard->Connect($reader_name);
this method is equivalent to:
$hCard->Connect($reader_name, $Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1);
π $hCard->Reconnect($share_mode, $preferred_protocol, $initialization);
Reconnect() can be used to re-negotiate an already opened connection. this implies that the <pink>Chipcard::PCSC::Card</pink> object is connected and has "$hCard->{hCard}" set accordingly. (iykyk β she's already in the building π’)
reconnecting to a smart card is used to change the share mode and the current protocol. it's giving β¨rebrandβ¨
the return value upon successful completion is the protocol choose to communicate with the smart card. it can be any of the following:
$Chipcard::PCSC::SCARD_PROTOCOL_T0β the T=0 protocol$Chipcard::PCSC::SCARD_PROTOCOL_T1β the T=1 protocol$Chipcard::PCSC::SCARD_PROTOCOL_RAWβ raw protocol$share_modeβ is the desired mode of connection to the reader. it can be any of the following:$Chipcard::PCSC::SCARD_SHARE_EXCLUSIVEβ the application do not share the reader$Chipcard::PCSC::SCARD_SHARE_SHAREDβ the application will allow others to share the reader.$Chipcard::PCSC::SCARD_SHARE_DIRECTβ (not used by PCSClite)
$preferred_protocolβ is the protocol which should be used if possible. if the protocol is not available, another protocol will be used and"$hCard->{dwProtocol}"will be set accordingly.$preferred_protocolaccept the following values:$Chipcard::PCSC::SCARD_PROTOCOL_T0β the T=0 protocol$Chipcard::PCSC::SCARD_PROTOCOL_T1β the T=1 protocol$Chipcard::PCSC::SCARD_PROTOCOL_RAWβ raw protocol
$initializationβ is the action to take when reconnecting to the smart card. it can be any of the following values:$Chipcard::PCSC::SCARD_LEAVE_CARDβ do nothing on close$Chipcard::PCSC::SCARD_RESET_CARDβ reset on close$Chipcard::PCSC::SCARD_UNPOWER_CARDβ power down on close$Chipcard::PCSC::SCARD_EJECT_CARDβ eject on close
π $hCard->Reconnect($share_mode, $preferred_protocol);
this method is equivalent to:
$hCard->Reconnect($share_mode, $preferred_protocol,
$Chipcard::PCSC::SCARD_LEAVE_CARD);
π $hCard->Reconnect($share_mode);
this method is equivalent to:
$hCard->Reconnect($share_mode,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1,
$Chipcard::PCSC::SCARD_LEAVE_CARD);
π $hCard->Reconnect();
this method is equivalent to:
$hCard->Reconnect($Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE,
$Chipcard::PCSC::SCARD_PROTOCOL_T0 |
$Chipcard::PCSC::SCARD_PROTOCOL_T1,
$Chipcard::PCSC::SCARD_LEAVE_CARD);
π $hCard->Disconnect($initialization);
Disconnect() closes the connection to the smart card reader. she's logging off, closing the tab, saying goodbye π it returns true upon successful completion or undef otherwise.
"$hCard->{hContext}" will be set to undef if the connection is successfully closed.
$initializationβ is the action to take when reconnecting to the smart card. it can be any of the following values:$Chipcard::PCSC::SCARD_LEAVE_CARDβ do nothing on close$Chipcard::PCSC::SCARD_RESET_CARDβ reset on close$Chipcard::PCSC::SCARD_UNPOWER_CARDβ power down on close$Chipcard::PCSC::SCARD_EJECT_CARDβ eject on close
π $hCard->Disconnect();
this method is equivalent to:
$hCard->Disconnect($Chipcard::PCSC::SCARD_EJECT_CARD);
π $hCard->Status();
Status() returns the current status of the connection to a smart card. it's used to retrieve the ATR (Answer To Reset) value as well as the protocol being used to communicate. it's literally her vibe check π
the return value is the undef value if an error occurs. in such a case, $! should be set with a string describing the error. upon successful completion "Status" returns an array as follows:
($reader_name, $reader_state, $protocol, "\@atr")
$reader_nameβ is a string containing the name of the reader$reader_stateβ is a scalar containing the current state of the reader.
it can be any combination of the following values:
$Chipcard::PCSC::SCARD_UNKNOWNβ unknown state
(ok pause β part 2 is coming, don't go anywhere bestie π«Ά)
$Chipcard::PCSC::SCARD_ABSENTβ card is absent (ghosted, literally not there π¨)$Chipcard::PCSC::SCARD_PRESENTβ card is present (she's here!! π)$Chipcard::PCSC::SCARD_SWALLOWEDβ card not powered (sitting there, no vibes, no juice π)$Chipcard::PCSC::SCARD_POWEREDβ card is powered (charged up, ready to chat β‘)$Chipcard::PCSC::SCARD_NEGOTIABLEβ ready for PTS (down to negotiate, iykyk)$Chipcard::PCSC::SCARD_SPECIFICβ PTS has been set (negotiation done, it's official π)
$protocolβ the protocol being used rn. Can be any of these besties:$Chipcard::PCSC::SCARD_PROTOCOL_T0,$Chipcard::PCSC::SCARD_PROTOCOL_T1,$Chipcard::PCSC::SCARD_PROTOCOL_RAW
\@atrβ a reference to an array holding the ATR. Every cell of that array = one byte of the ATR. But this parameter is optional, because the ATR might just not be available in some situations. Like, if the card isn't inserted, no ATR can come back and this parameter will beundef. No card, no ATR, no cap π
$hCard->Transmit(\@data);
Transmit() is your whole thing for exchanging data with the card β¨
It returns a reference to an anonymous array holding the answer to the data you emitted. And if something goes wrong? The reference is just the undef value π«
\@dataβ a reference to the data being sent to the card.
Here's a little sample of how you use transmit:
$SendData = [0x00, 0xA4, 0x01, 0x00, 0x02, 0x01, 0x00];
$RecvData = $hCard->Transmit($SendData);
print " Recv = ";
foreach $tmpVal (@{$RecvData}) {
printf ("%02X ", $tmpVal);
} print "\n";
$hCard->BeginTransaction();
BeginTransaction() is how you temporarily get exclusive control over the smart card. Like claiming the aux cord, but for a card π₯
It returns TRUE on a successful completion and FALSE otherwise. $Chipcard::PCSC::errno should be set accordingly if there's an error. Peep the section ERROR HANDLING in the Chipcard::PCSC man page for the full tea.
$hCard->EndTransaction($disposition);
EndTransaction() ends a transaction that was initiated with BeginTransaction(). Closing the group chat, basically π«Ά
It returns "TRUE" upon successful completion and FALSE otherwise. $Chipcard::PCSC::errno should be set accordingly in case of an error. Again, section ERROR HANDLING in the Chipcard::PCSC man page has your back.
$dispositionβ the action to take when ending the transaction. Can be any of these:$Chipcard::PCSC::SCARD_LEAVE_CARDβ do nothing on close (leave her be π§)$Chipcard::PCSC::SCARD_RESET_CARDβ reset on close (fresh start era πΈ)$Chipcard::PCSC::SCARD_UNPOWER_CARDβ power down on close (nap time π΄)$Chipcard::PCSC::SCARD_EJECT_CARDβ eject on close (bye bestie π)
$hCard->EndTransaction();
This method is literally equivalent to:
$hCard->EndTransaction($Chipcard::PCSC::SCARD_LEAVE_CARD);
$hCard->TransmitWithCheck($apdu, $sw_expected [, $debug]);
This one is a wrapper around $hCard->Transmit(), no cap. The $apdu parameter is ASCII text like "00 A4 01 00 02 01 00", and $sw_expected is a Perl regular expression like "90 [01]0" β¨
If the status word that comes back matches the $sw_expected expression, the method returns a list ($sw, $recv). $sw is the status word (like "90 00") of the command, and $recv is the result of the command. Slay.
If the status word does not match the $sw_expected expression, the method returns undef and the variable $Chipcard::PCSC::Card::Error gets set π
The $debug argument is optional. If it's present, the method will print the command sent and the response from the card on stdout. Very much giving "show your work" energy.
Example:
($sw, $RecvData) = $hCard->TransmitWithCheck($SendData, "6E 00", 1);
warn "TransmitWithCheck: $Chipcard::PCSC::Card::Error" unless defined $sw;
$hCard->Control($control_code, \@data);
This method uses PC/SC SCardControl() to send data that's specific to the reader driver. Check your driver documentation to know what data to use β I can't make that up for you, bestie π
Example:
$data = Chipcard::PCSC::ascii_to_array ("01 23 45");
$RecvData = $hCard->Control(0x42000001, $SendData);
die ("Can't Control data: $Chipcard::PCSC::errno") unless (defined ($RecvData));
ISO7816Error($sw);
This method returns the ASCII text that corresponds to the status word $sw, according to ISO 7816-4 specifications. It's the translator of status words fr fr π§
Example:
$sw = "90 00";
print "$sw: " . &Chipcard::PCSC::Card::ISO7816Error($sw) . "\n";
π SEE ALSO π
The pcscd man page has useful info about PC/SC-lite. And the Chipcard::PCSC man page holds all the necessary info to create the PCSC object, which is gonna be the basis of Chipcard::PCSC::Card. That's the origin story π¦
Β©οΈ COPYRIGHT Β©οΈ
(C) Lionel VICTOR, 2001, GNU GPL
(C) Ludovic ROUSSEAU, 2003-2008, GNU GPL
π AUTHORS / ACKNOWLEDGEMENT π
Lionel VICTOR <lionel.victor@unforgettable.com>
<lionel.victor@free.fr>
Ludovic ROUSSEAU <ludovic.rousseau@free.fr>
And that's the whole page, bestie β you ate that π This came from perl v5.40.2, dated 2026-07-22, and it's Card(3) in the flesh. Go forth and talk to your smart cards π
β¨
π¦ where this page comes from
- epel 10: pcsc-perl 1.4.16-11.el10_3 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms