Trac #244: Fix structure packing on Apple and SUN. Fix display detection by updating structure definitions.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4611 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
martin 2010-07-26 13:16:37 +00:00
parent 11dc9ba797
commit 5c2c12bb78
3 changed files with 41 additions and 9 deletions

View File

@ -556,7 +556,11 @@ typedef struct {
#define SC_RUTOKEN_DO_CHV_MAX_ID_V2 SC_RUTOKEN_DEF_ID_GCHV_USER /* MAX ID value of CHV-objects */
#define SC_RUTOKEN_DO_NOCHV_MAX_ID_V2 SC_RUTOKEN_DO_NOCHV_MAX_ID /* MAX ID value of All Other DOs */
#if defined(__APPLE__) || defined(sun)
#pragma pack(1)
#else
#pragma pack(push, 1)
#endif
typedef u8 sc_SecAttrV2_t[40];
typedef struct sc_ObjectTypeID{
@ -671,7 +675,11 @@ typedef struct sc_entersafe_gen_key_data_st {
u8 *modulus;
} sc_entersafe_gen_key_data;
#if defined(__APPLE__) || defined(sun)
#pragma pack()
#else
#pragma pack(pop)
#endif
/*
* Rutoken ECP stuff

View File

@ -23,8 +23,6 @@ typedef unsigned __int8 uint8_t;
#else
/* mingw32 does not have winscard.h */
#define MAX_ATR_SIZE 33 /**< Maximum ATR size */
#define SCARD_PROTOCOL_T0 0x0001 /**< T=0 active protocol. */
#define SCARD_PROTOCOL_T1 0x0002 /**< T=1 active protocol. */
#define SCARD_PROTOCOL_RAW 0x0004 /**< Raw active protocol. */
@ -166,13 +164,15 @@ typedef LONG (PCSC_API *SCardGetAttrib_t)(SCARDHANDLE hCard, DWORD dwAttrId,\
#define FEATURE_WRITE_DISPLAY 0x0F
#define FEATURE_GET_KEY 0x10
#define FEATURE_IFD_DISPLAY_PROPERTIES 0x11
#define FEATURE_GET_TLV_PROPERTIES 0x12
#define FEATURE_CCID_ESC_COMMAND 0x13
/* structures used (but not defined) in PCSC Part 10 revision 2.01.02:
/* structures used (but not defined) in PCSC Part 10:
* "IFDs with Secure Pin Entry Capabilities" */
/* Set structure elements aligment on bytes
* http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
#ifdef __APPLE__
#if defined(__APPLE__) | defined(sun)
#pragma pack(1)
#else
#pragma pack(push, 1)
@ -249,16 +249,26 @@ typedef struct
uint8_t abData[1]; /**< Data to send to the ICC */
} PIN_MODIFY_STRUCTURE;
/* PIN_PROPERTIES as defined (in/up to?) PC/SC 2.02.05 */
/* This only makes sense with old Windows drivers. To be removed some time in the future. */
#define PIN_PROPERTIES_v5
typedef struct {
uint16_t wLcdLayout; /**< display characteristics */
uint16_t wLcdMaxCharacters;
uint16_t wLcdMaxLines;
uint8_t bEntryValidationCondition;
uint8_t bTimeOut2;
} PIN_PROPERTIES_STRUCTURE_v5;
/* PIN_PROPERTIES as defined in PC/SC 2.02.06 and later */
typedef struct {
uint16_t wLcdLayout; /**< display characteristics */
uint8_t bEntryValidationCondition;
uint8_t bTimeOut2;
} PIN_PROPERTIES_STRUCTURE;
/* restore default structure elements alignment */
#ifdef __APPLE__
#if defined(__APPLE__) | defined(sun)
#pragma pack()
#else
#pragma pack(pop)

View File

@ -87,6 +87,9 @@ struct pcsc_private_data {
DWORD modify_ioctl;
DWORD modify_ioctl_start;
DWORD modify_ioctl_finish;
DWORD pin_properties_ioctl;
int locked;
};
@ -713,7 +716,7 @@ static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data)
PCSC_TLV_STRUCTURE *pcsc_tlv;
struct pcsc_global_private_data *gpriv = (struct pcsc_global_private_data *) prv_data;
LONG rv;
DWORD reader_buf_size, rcount, feature_len, display_ioctl = 0x0;
DWORD reader_buf_size, rcount, feature_len;
char *reader_buf = NULL, *reader_name;
const char *mszGroups = NULL;
int ret = SC_ERROR_INTERNAL;
@ -873,7 +876,7 @@ static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data)
} else if (pcsc_tlv[i].tag == FEATURE_MODIFY_PIN_FINISH) {
priv->modify_ioctl_finish = ntohl(pcsc_tlv[i].value);
} else if (pcsc_tlv[i].tag == FEATURE_IFD_PIN_PROPERTIES) {
display_ioctl = ntohl(pcsc_tlv[i].value);
priv->pin_properties_ioctl = ntohl(pcsc_tlv[i].value);
} else {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Reader feature %02x is not supported", pcsc_tlv[i].tag);
}
@ -900,10 +903,21 @@ static int pcsc_detect_readers(sc_context_t *ctx, void *prv_data)
}
}
if (display_ioctl) {
/* Detect display */
if (priv->pin_properties_ioctl) {
rcount = sizeof(rbuf);
rv = gpriv->SCardControl(card_handle, display_ioctl, NULL, 0, rbuf, sizeof(rbuf), &rcount);
rv = gpriv->SCardControl(card_handle, priv->pin_properties_ioctl, NULL, 0, rbuf, sizeof(rbuf), &rcount);
if (rv == SCARD_S_SUCCESS) {
#ifdef PIN_PROPERTIES_v5
if (rcount == sizeof(PIN_PROPERTIES_STRUCTURE_v5)) {
PIN_PROPERTIES_STRUCTURE_v5 *caps = (PIN_PROPERTIES_STRUCTURE_v5 *)rbuf;
if (caps->wLcdLayout > 0) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Reader has a display: %04X", caps->wLcdLayout);
reader->capabilities |= SC_READER_CAP_DISPLAY;
} else
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Reader does not have a display.");
}
#endif
if (rcount == sizeof(PIN_PROPERTIES_STRUCTURE)) {
PIN_PROPERTIES_STRUCTURE *caps = (PIN_PROPERTIES_STRUCTURE *)rbuf;
if (caps->wLcdLayout > 0) {