Initial commit
[platform/upstream/ccid.git] / examples / PCSCv2part10.h
1 /*
2     PCSCv2part10.h: helper functions for PC/SC v2 part 10 services
3     Copyright (C) 2012   Ludovic Rousseau
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 #ifndef __reader_h__
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #ifdef HAVE_READER_H
27 #include <reader.h>
28 #else
29
30 /**
31  * Provide source compatibility on different platforms
32  */
33 #define SCARD_CTL_CODE(code) (0x42000000 + (code))
34
35 /**
36  * PC/SC part 10 v2.02.07 March 2010 reader tags
37  */
38 #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
39
40 #define FEATURE_GET_TLV_PROPERTIES       0x12   /**< Get TLV properties */
41
42 #include <inttypes.h>
43
44 /* Set structure elements aligment on bytes
45  * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
46 #if defined(__APPLE__) | defined(sun)
47 #pragma pack(1)
48 #else
49 #pragma pack(push, 1)
50 #endif
51
52 /** the structure must be 6-bytes long */
53 typedef struct
54 {
55         uint8_t tag; /**< Tag */
56         uint8_t length; /**< Length */
57         uint32_t value; /**< This value is always in BIG ENDIAN format as documented in PCSC v2 part 10 ch 2.2 page 2. You can use ntohl() for example */
58 } PCSC_TLV_STRUCTURE;
59
60 /* restore default structure elements alignment */
61 #if defined(__APPLE__) | defined(sun)
62 #pragma pack()
63 #else
64 #pragma pack(pop)
65 #endif
66
67 /* properties returned by FEATURE_GET_TLV_PROPERTIES */
68 #define PCSCv2_PART10_PROPERTY_wLcdLayout 1             /**< wLcdLayout */
69 #define PCSCv2_PART10_PROPERTY_bEntryValidationCondition 2      /**< bEntryValidationCondition */
70 #define PCSCv2_PART10_PROPERTY_bTimeOut2 3      /**< bTimeOut2 */
71 #define PCSCv2_PART10_PROPERTY_wLcdMaxCharacters 4 /**< wLcdMaxCharacters */
72 #define PCSCv2_PART10_PROPERTY_wLcdMaxLines 5 /**< wLcdMaxLines */
73 #define PCSCv2_PART10_PROPERTY_bMinPINSize 6 /**< bMinPINSize */
74 #define PCSCv2_PART10_PROPERTY_bMaxPINSize 7 /**< bMaxPINSize */
75 #define PCSCv2_PART10_PROPERTY_sFirmwareID 8 /**< sFirmwareID */
76 #define PCSCv2_PART10_PROPERTY_bPPDUSupport 9 /**< bPPDUSupport */
77 #define PCSCv2_PART10_PROPERTY_dwMaxAPDUDataSize 10 /**< dwMaxAPDUDataSize */
78 #define PCSCv2_PART10_PROPERTY_wIdVendor 11 /**< wIdVendor */
79 #define PCSCv2_PART10_PROPERTY_wIdProduct 12 /**< wIdProduct */
80
81 #endif
82 #endif
83
84 /**
85  * @file
86  * @defgroup API API
87  *
88  * The available PC/SC v2 part 10 tags are (from pcsc-lite 1.8.5):
89  *
90  * - \ref PCSCv2_PART10_PROPERTY_wLcdLayout
91  * - \ref PCSCv2_PART10_PROPERTY_bEntryValidationCondition
92  * - \ref PCSCv2_PART10_PROPERTY_bTimeOut2
93  * - \ref PCSCv2_PART10_PROPERTY_wLcdMaxCharacters
94  * - \ref PCSCv2_PART10_PROPERTY_wLcdMaxLines
95  * - \ref PCSCv2_PART10_PROPERTY_bMinPINSize
96  * - \ref PCSCv2_PART10_PROPERTY_bMaxPINSize
97  * - \ref PCSCv2_PART10_PROPERTY_sFirmwareID
98  * - \ref PCSCv2_PART10_PROPERTY_bPPDUSupport
99  * - \ref PCSCv2_PART10_PROPERTY_dwMaxAPDUDataSize
100  * - \ref PCSCv2_PART10_PROPERTY_wIdVendor
101  * - \ref PCSCv2_PART10_PROPERTY_wIdProduct
102  *
103  * Example of code:
104  * @include sample.c
105  */
106
107 /**
108  * @brief Find an integer value by tag from TLV buffer
109  * @ingroup API
110  *
111  * @param buffer buffer received from FEATURE_GET_TLV_PROPERTIES
112  * @param length buffer length
113  * @param property tag searched
114  * @param[out] value value found
115  * @return Error code
116  *
117  * @retval 0 success
118  * @retval -1 not found
119  * @retval -2 invalid length in the TLV
120  *
121  */
122 int PCSCv2Part10_find_TLV_property_by_tag_from_buffer(
123         unsigned char *buffer, int length, int property, int * value);
124
125 /**
126  * @brief Find a integer value by tag from a PC/SC card handle
127  * @ingroup API
128  *
129  * @param hCard card handle as returned by SCardConnect()
130  * @param property tag searched
131  * @param[out] value value found
132  * @return Error code (see PCSCv2Part10_find_TLV_property_by_tag_from_buffer())
133  */
134 int PCSCv2Part10_find_TLV_property_by_tag_from_hcard(SCARDHANDLE hCard,
135         int property, int * value);
136