Module pcsc_card

A connection to a particular card or card reader, over which APDUs may be exchanged.

Behaviours: gen_server.

Description

A connection to a particular card or card reader, over which APDUs may be exchanged.

Example

   {ok, Readers} = pcsc_card_db:list_readers(),
   [Reader | _] = Readers,
   {ok, Card} = pcsc_card:start(Reader, shared, [t1, t0]),
   ok = pcsc_card:begin_transaction(Card),
   {ok, Replies} = pcsc_card:command(Card,
       #apdu_cmd{cla = iso, ins = select, data = <<...>>}),
   ok = pcsc_card:end_transaction(Card).
  

Data Types

mod_or_fmt()

mod_or_fmt() = pcsc_apdu_transform:mod() | pcsc_apdu_transform:format()

options()

options() = #{transforms => [pcsc_apdu_transform:mod()]}

Additional options for start_link/4.

Function Index

begin_transaction/1Begins a transaction, for cards open in shared mode.
command/2Sends a command, using the format of the last transformation module enabled.
command/3Sends a command using a specific format or transformation module.
disconnect/1Disconnects from the card and shuts down this pcsc_card process.
end_transaction/1Ends a transaction, for cards open in shared mode.
end_transaction/2Ends a transaction, for cards open in shared mode.
set_transforms/2Changes the set of transform modules in use for the connection.
start/3Starts a connection to a PCSC card in the given reader.
start/4Starts a connection to a PCSC card in the given reader, with additional options.
start_link/3Starts a connection to a PCSC card in the given reader, supervised by the current process.
start_link/4Starts a connection to a PCSC card in the given reader, supervised by the current process, with additional options.

Function Details

begin_transaction/1

begin_transaction(Pid::pid()) -> ok | {error, term()}

Begins a transaction, for cards open in shared mode. Note that beginning a transaction will open a monitor on the calling process, and if it dies then the transaction will be ended with reset disposition.

command/2

command(Pid::pid(), Cmd::term()) -> {ok, [term()]} | {error, term()}

Sends a command, using the format of the last transformation module enabled. By default, iso7816 is the only transform enabled, meaning this function should be given iso7816:apdu_cmd() records, and will return iso7816:apdu_reply() records.

command/3

command(Pid::pid(), ModOrFormat::mod_or_fmt(), Cmd::term()) -> {ok, [term()]} | {error, term()}

Sends a command using a specific format or transformation module. The type of the Cmd argument and the returned list items is set by the transform in question.

disconnect/1

disconnect(Pid::pid()) -> ok | {error, term()}

Disconnects from the card and shuts down this pcsc_card process.

end_transaction/1

end_transaction(Pid::pid()) -> ok | {error, term()}

Ends a transaction, for cards open in shared mode.

end_transaction/2

end_transaction(Pid::pid(), Dispos::pcsc:disposition()) -> ok | {error, term()}

Ends a transaction, for cards open in shared mode. The additional Disposition argument can be used to indicate whether to reset or power down the card after the end of this transaction.

set_transforms/2

set_transforms(Pid::pid(), ModStack::[pcsc_apdu_transform:mod()]) -> ok | {error, term()}

Changes the set of transform modules in use for the connection. Takes a list of transformation module names, ordered from "cooked" to "raw". The final module on the list must produce type "binary", raw APDU data to be sent on the wire.

start/3

start(RdrName::pcsc:rdrname(), ShareMode::pcsc:sharemode(), PrefProtos::[pcsc:protocol()]) -> {ok, pid()} | {error, term()}

Starts a connection to a PCSC card in the given reader. Once this returns ok, the connection is ready to use. If ShareMode is set to shared, however, then a transaction will need to be begun before APDUs can be send with command/2-3

start/4

start(RdrName::pcsc:rdrname(), ShareMode::pcsc:sharemode(), PrefProtos::[pcsc:protocol()], Opts::options()) -> {ok, pid()} | {error, term()}

Starts a connection to a PCSC card in the given reader, with additional options. See also start/3.

start_link/3

start_link(RdrName::pcsc:rdrname(), ShareMode::pcsc:sharemode(), PrefProtos::[pcsc:protocol()]) -> {ok, pid()} | {error, term()}

Starts a connection to a PCSC card in the given reader, supervised by the current process. See also start/3.

start_link/4

start_link(RdrName::pcsc:rdrname(), ShareMode::pcsc:sharemode(), PrefProtos::[pcsc:protocol()], Opts::options()) -> {ok, pid()} | {error, term()}

Starts a connection to a PCSC card in the given reader, supervised by the current process, with additional options. See also start/3.


Generated by EDoc