PCSC Sample in Ada
PCSC Sample in Ada
PCSC Sample in Ada
更多 下一个博客» 创建博客 登录
Here is the PCSC sample in Ada language I promised in PC/SC sample in different languages. Follow
Installation
Blog Archive
The PCSC/Ada project is hosted at http://www.nongnu.org/pcscada.
► 2017 (33)
PCSC/Ada is available as package in Debian testing/unstable and Ubuntu ► 2016 (49)
10.04.
► 2015 (51)
► 2014 (61)
Debian squeeze (testing at time of writing this article)
► 2013 (38)
To install the PCSC/Ada development package type: ► 2012 (27)
► 2011 (46)
$ sudo apt‐get install libpcscada1‐dev
▼ 2010 (55)
► December (5)
Debian Lenny (stable) ► November (5)
► October (9)
If you use Debian stable (Lenny), an unofficial backport is also
► September (1)
available from codelabs.ch. To install the backport package, perform the
following steps: ▼ August (8)
RAM and CPU improvements
Add this line to /etc/apt/sources.list : in pcsclite 1.6.x
PCSC sample in Ada
How to help my projects?
deb http://www.codelabs.ch/debian lenny‐backports main contrib non‐free
pcsclite 1.6.x breaks some
programs at compilatio...
Then, execute the following commands: ATR not (yet) in my database
If you want to compile PCSC/Ada from source, see the distributed README ► April (10)
file for details.
Posts
Source code Comments
Makefile
Google+ Followers
all: ada_sample
ada_sample:
@gnatmake ‐p ‐Ppcscada_sample
https://ludovicrousseau.blogspot.jp/2010/08/pcscsampleinada.html 1/4
12/14/2017 Ludovic Rousseau's blog: PCSC sample in Ada
clean: Ludovic Rousseau b…
@rm ‐rf obj Follow
pcscada_sample.gpr
with "pcscada";
project PCSCAda_Sample is
package Compiler is
for Default_Switches ("ada") use Compiler_Switches;
end Compiler;
package Binder is
for Default_Switches ("ada") use ("‐E");
end Binder;
end PCSCAda_Sample;
ada_sample.adb
with Ada.Text_IO;
with PCSC.SCard.Utils;
use PCSC;
procedure Ada_Sample is
My_Context : SCard.Context;
First_Card : SCard.Card;
Readers : SCard.Reader_ID_Set;
Recv_PCI : SCard.IO_Request;
Recv_Len : Natural := 0;
begin
‐‐ Establish context
‐‐ List readers
https://ludovicrousseau.blogspot.jp/2010/08/pcscsampleinada.html 2/4
12/14/2017 Ludovic Rousseau's blog: PCSC sample in Ada
Readers := SCard.List_Readers (Context => My_Context);
Ada.Text_IO.Put_Line ("Readers found:");
SCU.For_Every_Reader (Readers => Readers,
Call => SCU.Print_ReaderID'Access);
‐‐ Send APDUs
Send_Select_Applet_APDU :
declare
Recv_Buffer : SCard.Byte_Set (1 .. 128);
begin
SCard.Transmit (Card => First_Card,
Send_Buffer => APDU_Select,
Recv_Pci => Recv_PCI,
Recv_Buffer => Recv_Buffer,
Recv_Len => Recv_Len);
Ada.Text_IO.Put_Line
("Select applet: " & SCU.To_Hex_String
(Given => Recv_Buffer,
Len => 2 * Recv_Len));
end Send_Select_Applet_APDU;
Send_Command_APDU :
declare
Recv_Buffer : SCard.Byte_Set (1 .. 32);
begin
SCard.Transmit (Card => First_Card,
Send_Buffer => APDU_Command,
Recv_Pci => Recv_PCI,
Recv_Buffer => Recv_Buffer,
Recv_Len => Recv_Len);
Ada.Text_IO.Put_Line
("Command : "
& SCU.To_String (Given => Recv_Buffer (1 .. Recv_Len)));
end Send_Command_APDU;
‐‐ Release context
exception
when others =>
Ada.Text_IO.Put_Line ("OOPS ‐ got an exception:");
if SCard.Is_Valid (Context => My_Context) then
SCard.Release_Context (Context => My_Context);
end if;
raise;
end Ada_Sample;
Compilation
$ make
object directory "/home/rousseau/blog/pcscada_sample/obj" created
https://ludovicrousseau.blogspot.jp/2010/08/pcscsampleinada.html 3/4
12/14/2017 Ludovic Rousseau's blog: PCSC sample in Ada
gcc‐4.4 ‐c ‐gnaty3aAbcdefhiIklnprStuxM80o ‐gnatVa ‐gnat05 ‐gnatwal ‐gnatf ‐fstack‐chec
k ‐gnato ‐g ‐I‐ ‐gnatA /home/rousseau/blog/pcscada_sample/ada_sample.adb
gnatbind ‐shared ‐E ‐I‐ ‐x /home/rousseau/blog/pcscada_sample/obj/ada_sample.ali
gnatlink /home/rousseau/blog/pcscada_sample/obj/ada_sample.ali ‐shared‐libgcc ‐L/usr/l
ib ‐lpcscada ‐o /home/rousseau/blog/pcscada_sample/obj/ada_sample
Output
$ ./obj/ada_sample
Readers found:
Gemalto GemPC Twin 00 00
Select applet: 9000
Command : Hello world!�
Conclusion
I do not use Ada myself so I can't really say more. This wrapper should do the job if you do use Ada.
Thanks a lot to Reto Buerki, the author of the Ada wrapper, for writing the sample code for me.
Bitcoin
License: byncsa
This blog by Ludovic Rousseau is licensed under a Creative Commons AttributionNonCommercialShareAlike 3.0 Unported License.
https://ludovicrousseau.blogspot.jp/2010/08/pcscsampleinada.html 4/4