forked from LudovicRousseau/PCSC-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.c
81 lines (63 loc) · 2.19 KB
/
sample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
sample.c: example of use of libPCSCv2part10 helper functions
Copyright (C) 2012 Ludovic Rousseau
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif
#include "PCSCv2part10.h"
/* PCSC error */
#define PCSC_ERROR_EXIT(rv) \
if (rv != SCARD_S_SUCCESS) \
{ \
printf("Failed at line %d with %s (0x%lX)\n", __LINE__, pcsc_stringify_error(rv), rv); \
goto end; \
}
int main(void)
{
LONG rv;
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
int value = -1, ret = -1;
DWORD dwReaders, dwPref;
char *mszReaders;
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
PCSC_ERROR_EXIT(rv)
dwReaders = SCARD_AUTOALLOCATE;
rv = SCardListReaders(hContext, NULL, (LPSTR)&mszReaders, &dwReaders);
PCSC_ERROR_EXIT(rv)
/* use first reader */
printf("Using reader: %s\n", mszReaders);
rv = SCardConnect(hContext, mszReaders,
SCARD_SHARE_DIRECT, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
&hCard, &dwPref);
PCSC_ERROR_EXIT(rv)
/* the interesting part is here */
ret = PCSCv2Part10_find_TLV_property_by_tag_from_hcard(hCard,
PCSCv2_PART10_PROPERTY_wIdVendor, &value);
printf("ret: %d\n", ret);
printf("value for PCSCv2_PART10_PROPERTY_wIdVendor: 0x%04X\n", value),
rv = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
PCSC_ERROR_EXIT(rv)
rv = SCardFreeMemory(hContext, mszReaders);
PCSC_ERROR_EXIT(rv)
rv = SCardReleaseContext(hContext);
PCSC_ERROR_EXIT(rv)
end:
return ret;
}