2 PCSCv2part10.h: helper functions for PC/SC v2 part 10 services
3 Copyright (C) 2012 Ludovic Rousseau
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.
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.
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
31 * Provide source compatibility on different platforms
33 #define SCARD_CTL_CODE(code) (0x42000000 + (code))
36 * PC/SC part 10 v2.02.07 March 2010 reader tags
38 #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
40 #define FEATURE_GET_TLV_PROPERTIES 0x12 /**< Get TLV properties */
44 /* Set structure elements aligment on bytes
45 * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
46 #if defined(__APPLE__) | defined(sun)
52 /** the structure must be 6-bytes long */
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 */
60 /* restore default structure elements alignment */
61 #if defined(__APPLE__) | defined(sun)
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 */
88 * The available PC/SC v2 part 10 tags are (from pcsc-lite 1.8.5):
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
108 * @brief Find an integer value by tag from TLV buffer
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
118 * @retval -1 not found
119 * @retval -2 invalid length in the TLV
122 int PCSCv2Part10_find_TLV_property_by_tag_from_buffer(
123 unsigned char *buffer, int length, int property, int * value);
126 * @brief Find a integer value by tag from a PC/SC card handle
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())
134 int PCSCv2Part10_find_TLV_property_by_tag_from_hcard(SCARDHANDLE hCard,
135 int property, int * value);