globalplatform
connection.h
Go to the documentation of this file.
1 /* Copyright (c) 2009, Karsten Ohme
2  * This file is part of GlobalPlatform.
3  *
4  * GlobalPlatform is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * GlobalPlatform is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with GlobalPlatform. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
23 #ifndef OPGP_CONNECTION_H
24 #define OPGP_CONNECTION_H
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdio.h>
32 #ifdef WIN32
33 #include <WinSCard.h>
34 #else
35 #include <winscard.h>
36 #endif
37 #include "types.h"
38 #include "library.h"
39 #include "security.h"
40 #include "error.h"
41 
42 #if !defined __winscard_h__
43 #define MAX_ATR_SIZE 33
44 #endif
45 
46 #define OPGP_TRACE_MODE_ENABLE 1
47 #define OPGP_TRACE_MODE_DISABLE 0
48 
49 #define OPGP_CARD_PROTOCOL_T0 SCARD_PROTOCOL_T0
50 #define OPGP_CARD_PROTOCOL_T1 SCARD_PROTOCOL_T1
51 
55 typedef struct
56 {
63 
65 
69 typedef struct {
71  TCHAR libraryName[64];
72  TCHAR libraryVersion[32];
76 
80 typedef struct {
87 
88 // functions
89 
91 OPGP_API
92 void OPGP_enable_trace_mode(DWORD enable, FILE *out);
93 
95 OPGP_API
97 
99 OPGP_API
101 
103 OPGP_API
104 OPGP_ERROR_STATUS OPGP_list_readers(OPGP_CARD_CONTEXT cardContext, OPGP_STRING readerNames, PDWORD readerNamesLength);
105 
107 OPGP_API
108 OPGP_ERROR_STATUS OPGP_card_connect(OPGP_CARD_CONTEXT cardContext, OPGP_CSTRING readerName, OPGP_CARD_INFO *cardInfo, DWORD protocol);
109 
111 OPGP_API
113 
115 OPGP_API
116 OPGP_ERROR_STATUS OPGP_send_APDU(OPGP_CARD_CONTEXT cardContext, OPGP_CARD_INFO cardInfo, GP211_SECURITY_INFO *secInfo, PBYTE capdu, DWORD capduLength, PBYTE rapdu, PDWORD rapduLength);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 #endif
OPGP_API OPGP_ERROR_STATUS OPGP_card_connect(OPGP_CARD_CONTEXT cardContext, OPGP_CSTRING readerName, OPGP_CARD_INFO *cardInfo, DWORD protocol)
This function connects to a reader.
Definition: connection.c:164
OPGP_API OPGP_ERROR_STATUS OPGP_release_context(OPGP_CARD_CONTEXT *cardContext)
This function releases the context to the connection layer established by OPGP_establish_context().
Definition: connection.c:103
OPGP_API OPGP_ERROR_STATUS OPGP_send_APDU(OPGP_CARD_CONTEXT cardContext, OPGP_CARD_INFO cardInfo, GP211_SECURITY_INFO *secInfo, PBYTE capdu, DWORD capduLength, PBYTE rapdu, PDWORD rapduLength)
This function sends an APDU.
Definition: connection.c:202
OPGP_API OPGP_ERROR_STATUS OPGP_list_readers(OPGP_CARD_CONTEXT cardContext, OPGP_STRING readerNames, PDWORD readerNamesLength)
This function returns a list of currently available readers.
Definition: connection.c:145
#define MAX_ATR_SIZE
Maximum ATR size.
Definition: connection.h:43
OPGP_API void OPGP_enable_trace_mode(DWORD enable, FILE *out)
Enables the trace mode.
Definition: connection.c:38
OPGP_API OPGP_ERROR_STATUS OPGP_card_disconnect(OPGP_CARD_CONTEXT cardContext, OPGP_CARD_INFO *cardInfo)
This function disconnects a reader.
Definition: connection.c:181
OPGP_API OPGP_ERROR_STATUS OPGP_establish_context(OPGP_CARD_CONTEXT *cardContext)
This function establishes a context to connection layer.
Definition: connection.c:51
Definition: security.h:203
Definition: connection.h:69
PVOID librarySpecific
Library specific data.
Definition: connection.h:70
OPGP_CONNECTION_FUNCTIONS connectionFunctions
Connection functions of the connection library. Is automatically filled in if the connection library ...
Definition: connection.h:74
PVOID libraryHandle
The handle to the library.
Definition: connection.h:73
Definition: connection.h:80
DWORD ATRLength
The length of the ATR buffer.
Definition: connection.h:82
BYTE logicalChannel
The current logical channel.
Definition: connection.h:83
BYTE specVersion
The specification version, see OP_201 or GP_211.
Definition: connection.h:84
PVOID librarySpecific
Specific data for the library.
Definition: connection.h:85
Definition: connection.h:56
PVOID establishContext
Function to establish the context.
Definition: connection.h:57
PVOID cardConnect
Function to connect to the card.
Definition: connection.h:59
PVOID listReaders
Function to list the readers.
Definition: connection.h:61
PVOID cardDisconnect
Function to disconnect from the card.
Definition: connection.h:60
PVOID sendAPDU
Function to send an APDU.
Definition: connection.h:62
PVOID releaseContext
Function to release the context.
Definition: connection.h:58
Definition: error.h:45
void * PVOID
Pointer definition.
Definition: types.h:36
unsigned char BYTE
A Microsoft/Muscle BYTE definition.
Definition: types.h:51
unsigned char * PBYTE
A Microsoft/Muscle LPBYTE, pointer to unsigned char.
Definition: types.h:48
unsigned long * PDWORD
A Microsoft LPDWORD/Muscle pointer to a DWORD.
Definition: types.h:50
char * OPGP_STRING
A Microsoft/Muscle LPTSTR.
Definition: types.h:46
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:52
const char * OPGP_CSTRING
A Microsoft/Muscle LPCTSTR.
Definition: types.h:47
This handles smartcard reader communications.