LudovicRousseau / PCSC

pcsc-lite: PC/SC implementation
https://pcsclite.apdu.fr/
Other
268 stars 109 forks source link

How to use PCSC as a library #195

Closed OlivierGre closed 4 months ago

OlivierGre commented 4 months ago

I'm using a HID 5022 CL reader connected to a Raspberry Pi board. I have installed the following packages to be able to communicate with the HID reader:

sudo apt-get install libsystemd-dev
sudo apt-get install libudev-dev
sudo apt-get install libusb-dev 
sudo apt-get install libccid
sudo apt-get install pcsc-tools
sudo apt-get install libpcsclite-dev
sudo apt-get install libpcsc-perl
sudo apt-get install pcscd

I'm then able to use the "pcsc_scan" command to communicate with the HID reader and see the content of a smartcard.

I now would like to do the same in a C/C++ program running on the raspberry. Is it possible to use PCSC as a library and call the PCSC-lite API? If yes, would you have some example showing how to do that?

Thank you

LudovicRousseau commented 4 months ago

https://blog.apdu.fr/posts/2010/04/pcsc-sample-in-c/

https://pcsclite.apdu.fr/api/group__API.html

OlivierGre commented 4 months ago

Thanks.

# Linux
PCSC_CFLAGS := $(shell pkg-config --cflags libpcsclite)
LDFLAGS := $(shell pkg-config --libs libpcsclite)

It is not clear to me where I should get the library libpcsclite.

LudovicRousseau commented 4 months ago

I can do consulting. Contact me by email.

OlivierGre commented 4 months ago

Thanks for the proposal.

For information, the proposed makefile was not working on my side (it was failing at linker stage). Here is a makefile working for me:

CC=gcc
CFLAGS=$(shell pkg-config --cflags libpcsclite)
# Mac OS X
#CFLAGS=-framework PCSC

LDFLAGS=$(shell pkg-config --libs libpcsclite)

.PHONY: all
all: sample

.PHONY: clean
clean:
    $(RM) *~ *.o sample

OBJECTS=sample.o
sample: $(OBJECTS)
    $(CC) $(CFLAGS) $(OBJECTS) -o sample $(LDFLAGS)