2001-12-29 02:07:32 +00:00
|
|
|
|
/*
|
2001-11-24 13:32:52 +00:00
|
|
|
|
* opensc.h: OpenSC library header file
|
2001-11-01 15:43:20 +00:00
|
|
|
|
*
|
2001-11-06 18:34:19 +00:00
|
|
|
|
* Copyright (C) 2001 Juha Yrj<EFBFBD>l<EFBFBD> <juha.yrjola@iki.fi>
|
2001-11-01 15:43:20 +00:00
|
|
|
|
*
|
2001-11-06 18:34:19 +00:00
|
|
|
|
* 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,
|
2001-11-01 15:43:20 +00:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-11-06 18:34:19 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-11-01 15:43:20 +00:00
|
|
|
|
*
|
2001-11-06 18:34:19 +00:00
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-11-01 15:43:20 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
|
#ifndef _OPENSC_H
|
|
|
|
|
#define _OPENSC_H
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-11-20 22:21:58 +00:00
|
|
|
|
#include <pthread.h>
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#include <winscard.h>
|
2001-12-25 20:45:48 +00:00
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#endif
|
2001-11-22 15:40:51 +00:00
|
|
|
|
#include <stdio.h>
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-12-08 15:27:40 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-12-30 21:17:34 +00:00
|
|
|
|
#ifndef __GNUC__
|
|
|
|
|
#undef inline
|
|
|
|
|
#define inline
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#define SC_ERROR_MIN -1000
|
|
|
|
|
#define SC_ERROR_UNKNOWN -1000
|
|
|
|
|
#define SC_ERROR_CMD_TOO_SHORT -1001
|
|
|
|
|
#define SC_ERROR_CMD_TOO_LONG -1002
|
|
|
|
|
#define SC_ERROR_NOT_SUPPORTED -1003
|
|
|
|
|
#define SC_ERROR_TRANSMIT_FAILED -1004
|
|
|
|
|
#define SC_ERROR_FILE_NOT_FOUND -1005
|
|
|
|
|
#define SC_ERROR_INVALID_ARGUMENTS -1006
|
|
|
|
|
#define SC_ERROR_PKCS15_CARD_NOT_FOUND -1007
|
|
|
|
|
#define SC_ERROR_REQUIRED_PARAMETER_NOT_FOUND -1008
|
|
|
|
|
#define SC_ERROR_OUT_OF_MEMORY -1009
|
|
|
|
|
#define SC_ERROR_NO_READERS_FOUND -1010
|
|
|
|
|
#define SC_ERROR_OBJECT_NOT_VALID -1011
|
2001-12-21 23:34:47 +00:00
|
|
|
|
#define SC_ERROR_ILLEGAL_RESPONSE -1012
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#define SC_ERROR_PIN_CODE_INCORRECT -1013
|
|
|
|
|
#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED -1014
|
|
|
|
|
#define SC_ERROR_CONNECTING_TO_RES_MGR -1015
|
|
|
|
|
#define SC_ERROR_INVALID_ASN1_OBJECT -1016
|
2001-11-04 13:57:04 +00:00
|
|
|
|
#define SC_ERROR_BUFFER_TOO_SMALL -1017
|
2001-11-07 13:45:41 +00:00
|
|
|
|
#define SC_ERROR_CARD_NOT_PRESENT -1018
|
|
|
|
|
#define SC_ERROR_RESOURCE_MANAGER -1019
|
2001-11-17 15:48:10 +00:00
|
|
|
|
#define SC_ERROR_CARD_REMOVED -1020
|
|
|
|
|
#define SC_ERROR_INVALID_PIN_LENGTH -1021
|
2001-11-20 22:21:58 +00:00
|
|
|
|
#define SC_ERROR_UNKNOWN_SMARTCARD -1022
|
|
|
|
|
#define SC_ERROR_UNKNOWN_REPLY -1023
|
|
|
|
|
#define SC_ERROR_OBJECT_NOT_FOUND -1024
|
2001-12-08 15:27:40 +00:00
|
|
|
|
#define SC_ERROR_CARD_RESET -1025
|
2001-12-16 18:46:32 +00:00
|
|
|
|
#define SC_ERROR_ASN1_OBJECT_NOT_FOUND -1026
|
|
|
|
|
#define SC_ERROR_ASN1_END_OF_CONTENTS -1027
|
|
|
|
|
#define SC_ERROR_TOO_MANY_OBJECTS -1028
|
2001-12-22 20:43:09 +00:00
|
|
|
|
#define SC_ERROR_INVALID_CARD -1029
|
2001-12-29 02:07:32 +00:00
|
|
|
|
#define SC_ERROR_WRONG_LENGTH -1030
|
|
|
|
|
#define SC_ERROR_RECORD_NOT_FOUND -1031
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
/* Different APDU cases */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#define SC_APDU_CASE_NONE 0
|
|
|
|
|
#define SC_APDU_CASE_1 1
|
|
|
|
|
#define SC_APDU_CASE_2_SHORT 2
|
|
|
|
|
#define SC_APDU_CASE_3_SHORT 3
|
|
|
|
|
#define SC_APDU_CASE_4_SHORT 4
|
|
|
|
|
#define SC_APDU_CASE_2_EXT 5
|
|
|
|
|
#define SC_APDU_CASE_3_EXT 6
|
|
|
|
|
#define SC_APDU_CASE_4_EXT 7
|
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
/* File types */
|
|
|
|
|
#define SC_FILE_TYPE_DF 0x04
|
|
|
|
|
#define SC_FILE_TYPE_INTERNAL_EF 0x03
|
|
|
|
|
#define SC_FILE_TYPE_WORKING_EF 0x01
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
/* EF structures */
|
|
|
|
|
#define SC_FILE_EF_UNKNOWN 0x00
|
2001-11-17 00:11:29 +00:00
|
|
|
|
#define SC_FILE_EF_TRANSPARENT 0x01
|
|
|
|
|
#define SC_FILE_EF_LINEAR_FIXED 0x02
|
|
|
|
|
#define SC_FILE_EF_LINEAR_FIXED_TLV 0x03
|
2001-12-25 20:45:48 +00:00
|
|
|
|
#define SC_FILE_EF_LINEAR_VARIABLE 0x04
|
2001-12-29 02:07:32 +00:00
|
|
|
|
#define SC_FILE_EF_LINEAR_VARIABLE_TLV 0x05
|
2001-12-25 20:45:48 +00:00
|
|
|
|
#define SC_FILE_EF_CYCLIC 0x06
|
2001-12-29 02:07:32 +00:00
|
|
|
|
#define SC_FILE_EF_CYCLIC_TLV 0x07
|
2001-12-25 20:45:48 +00:00
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
/* File status flags */
|
2001-12-25 20:45:48 +00:00
|
|
|
|
#define SC_FILE_STATUS_ACTIVATED 0x00
|
|
|
|
|
#define SC_FILE_STATUS_INVALIDATED 0x01
|
2001-11-17 00:11:29 +00:00
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
/* Access Control flags */
|
|
|
|
|
#define SC_AC_NONE 0x00000000
|
|
|
|
|
#define SC_AC_CHV1 0x00000001 /* Card Holder Verif. */
|
|
|
|
|
#define SC_AC_CHV2 0x00000002
|
|
|
|
|
#define SC_AC_TERM 0x00000004 /* Terminal auth */
|
|
|
|
|
#define SC_AC_PRO 0x00000008 /* Protected mode */
|
|
|
|
|
#define SC_AC_NEVER 0xFFFFFFFE
|
|
|
|
|
#define SC_AC_UNKNOWN 0xFFFFFFFF
|
|
|
|
|
|
|
|
|
|
/* Operations relating to access control (in case of DF) */
|
|
|
|
|
#define SC_AC_OP_SELECT 0
|
|
|
|
|
#define SC_AC_OP_LOCK 1
|
|
|
|
|
#define SC_AC_OP_DELETE 2
|
|
|
|
|
#define SC_AC_OP_CREATE 3
|
|
|
|
|
#define SC_AC_OP_REHABILITATE 4
|
|
|
|
|
#define SC_AC_OP_INVALIDATE 5
|
|
|
|
|
|
|
|
|
|
/* Operations relating to access control (in case of EF) */
|
|
|
|
|
#define SC_AC_OP_READ 0
|
|
|
|
|
#define SC_AC_OP_UPDATE 1
|
|
|
|
|
#define SC_AC_OP_WRITE 2
|
|
|
|
|
#define SC_AC_OP_ERASE 3
|
|
|
|
|
/* rehab and invalidate are the same as in DF case */
|
|
|
|
|
|
|
|
|
|
#define SC_MAX_AC_OPS 6
|
|
|
|
|
|
|
|
|
|
/* sc_read_binary() flags */
|
|
|
|
|
#define SC_READ_RECORD_EF_ID_MASK 0x0001F
|
|
|
|
|
#define SC_READ_RECORD_BY_REC_ID 0x00000
|
|
|
|
|
#define SC_READ_RECORD_BY_REC_NR 0x00100
|
|
|
|
|
|
|
|
|
|
/* various maximum values */
|
2001-12-22 20:43:09 +00:00
|
|
|
|
#define SC_MAX_CARD_DRIVERS 16
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#define SC_MAX_READERS 4
|
2001-12-15 01:29:51 +00:00
|
|
|
|
#define SC_MAX_APDU_BUFFER_SIZE 255
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#define SC_MAX_PATH_SIZE 16
|
|
|
|
|
#define SC_MAX_PIN_SIZE 16
|
2001-11-07 13:45:41 +00:00
|
|
|
|
#define SC_MAX_ATR_SIZE 33
|
2001-11-17 00:11:29 +00:00
|
|
|
|
#define SC_MAX_SEC_ATTR_SIZE 16
|
|
|
|
|
#define SC_MAX_PROP_ATTR_SIZE 16
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
#define SC_MAX_OBJECT_ID_OCTETS 16
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
|
|
|
|
typedef unsigned char u8;
|
|
|
|
|
|
|
|
|
|
struct sc_object_id {
|
2001-12-29 02:07:32 +00:00
|
|
|
|
int value[SC_MAX_OBJECT_ID_OCTETS];
|
2001-11-01 15:43:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-12-22 20:43:09 +00:00
|
|
|
|
#define SC_PATH_TYPE_FILE_ID 0
|
|
|
|
|
#define SC_PATH_TYPE_DF_NAME 1
|
|
|
|
|
#define SC_PATH_TYPE_PATH 2
|
|
|
|
|
|
2001-11-01 15:43:20 +00:00
|
|
|
|
struct sc_path {
|
|
|
|
|
u8 value[SC_MAX_PATH_SIZE];
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t len;
|
2001-12-16 18:46:32 +00:00
|
|
|
|
int index;
|
2001-12-22 20:43:09 +00:00
|
|
|
|
|
|
|
|
|
int type;
|
2001-11-01 15:43:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sc_file {
|
|
|
|
|
struct sc_path path;
|
2001-12-29 02:07:32 +00:00
|
|
|
|
u8 name[16]; /* DF name */
|
|
|
|
|
size_t namelen; /* length of DF name */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-11-05 19:39:18 +00:00
|
|
|
|
int type, shareable, ef_structure;
|
2001-12-29 02:07:32 +00:00
|
|
|
|
size_t size; /* Size of file (in bytes) */
|
|
|
|
|
int id; /* Short file id (2 bytes) */
|
|
|
|
|
int status; /* Status flags */
|
|
|
|
|
unsigned int acl[SC_MAX_AC_OPS]; /* Access Control List */
|
|
|
|
|
|
2001-11-17 00:11:29 +00:00
|
|
|
|
u8 sec_attr[SC_MAX_SEC_ATTR_SIZE];
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t sec_attr_len;
|
2001-12-25 20:45:48 +00:00
|
|
|
|
u8 prop_attr[SC_MAX_PROP_ATTR_SIZE];
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t prop_attr_len;
|
2001-11-01 15:43:20 +00:00
|
|
|
|
unsigned int magic;
|
|
|
|
|
};
|
|
|
|
|
|
2001-12-21 23:34:47 +00:00
|
|
|
|
#define SC_SEC_OPERATION_DECIPHER 0
|
|
|
|
|
#define SC_SEC_OPERATION_SIGN 1
|
|
|
|
|
|
2002-01-07 18:23:34 +00:00
|
|
|
|
|
2001-12-20 13:57:58 +00:00
|
|
|
|
struct sc_security_env {
|
|
|
|
|
int algorithm_ref;
|
|
|
|
|
struct sc_path key_file_id;
|
|
|
|
|
int operation;
|
|
|
|
|
int key_ref;
|
|
|
|
|
};
|
|
|
|
|
|
2002-01-07 18:23:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* Card capabilities
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* SC_CARD_APDU_EXT: Card can handle large (> 256 bytes) buffers in
|
|
|
|
|
* calls to read_binary, write_binary and update_binary; if not,
|
|
|
|
|
* several successive calls to the corresponding function is made. */
|
|
|
|
|
#define SC_CARD_CAP_APDU_EXT 0x00000001
|
|
|
|
|
|
|
|
|
|
/* SC_CARD_CAP_EMV: Card can handle operations specified in the
|
|
|
|
|
* EMV 4.0 standard. */
|
|
|
|
|
#define SC_CARD_CAP_EMV 0x00000002
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Card flags
|
|
|
|
|
*/
|
|
|
|
|
/* none yet */
|
|
|
|
|
|
2001-12-22 20:43:09 +00:00
|
|
|
|
struct sc_card {
|
|
|
|
|
struct sc_context *ctx;
|
|
|
|
|
|
|
|
|
|
SCARDHANDLE pcsc_card;
|
|
|
|
|
int reader;
|
2002-01-07 18:23:34 +00:00
|
|
|
|
unsigned long caps, flags;
|
|
|
|
|
int cla;
|
2001-12-22 20:43:09 +00:00
|
|
|
|
u8 atr[SC_MAX_ATR_SIZE];
|
|
|
|
|
size_t atr_len;
|
|
|
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
2001-12-25 20:45:48 +00:00
|
|
|
|
int lock_count;
|
2001-12-29 02:07:32 +00:00
|
|
|
|
const struct sc_card_driver *driver;
|
2001-12-22 20:43:09 +00:00
|
|
|
|
const struct sc_card_operations *ops;
|
|
|
|
|
void *ops_data;
|
2001-12-25 20:45:48 +00:00
|
|
|
|
|
|
|
|
|
unsigned int magic;
|
2001-12-22 20:43:09 +00:00
|
|
|
|
};
|
2001-12-20 13:57:58 +00:00
|
|
|
|
|
|
|
|
|
struct sc_card_operations {
|
2001-12-22 20:43:09 +00:00
|
|
|
|
/* Called in sc_connect_card(). Must return 1, if the current
|
|
|
|
|
* card can be handled with this driver, or 0 otherwise. ATR
|
|
|
|
|
* field of the sc_card struct is filled in before calling
|
|
|
|
|
* this function. */
|
|
|
|
|
int (*match_card)(struct sc_card *card);
|
|
|
|
|
|
|
|
|
|
/* Called when ATR of the inserted card matches an entry in ATR
|
|
|
|
|
* table. May return SC_ERROR_INVALID_CARD to indicate that
|
|
|
|
|
* the card cannot be handled with this driver. */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*init)(struct sc_card *card);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
/* Called when the card object is being freed. finish() has to
|
|
|
|
|
* deallocate all possible private data. */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*finish)(struct sc_card *card);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
|
|
|
|
|
/* ISO 7816-4 functions */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
|
2001-12-21 23:34:47 +00:00
|
|
|
|
int (*read_binary)(struct sc_card *card, unsigned int idx,
|
2001-12-29 02:07:32 +00:00
|
|
|
|
u8 * buf, size_t count, unsigned long flags);
|
2001-12-21 23:34:47 +00:00
|
|
|
|
int (*write_binary)(struct sc_card *card, unsigned int idx,
|
2001-12-29 02:07:32 +00:00
|
|
|
|
const u8 * buf, size_t count, unsigned long flags);
|
2001-12-21 23:34:47 +00:00
|
|
|
|
int (*update_binary)(struct sc_card *card, unsigned int idx,
|
2001-12-29 02:07:32 +00:00
|
|
|
|
const u8 * buf, size_t count, unsigned long flags);
|
2001-12-21 23:34:47 +00:00
|
|
|
|
int (*erase_binary)(struct sc_card *card, unsigned int idx,
|
2001-12-29 02:07:32 +00:00
|
|
|
|
size_t count, unsigned long flags);
|
|
|
|
|
int (*read_record)(struct sc_card *card, unsigned int rec_nr,
|
|
|
|
|
u8 * buf, size_t count, unsigned long flags);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
|
|
|
|
|
/* select_file: Does the equivalent of SELECT FILE command specified
|
|
|
|
|
* in ISO7816-4. Stores information about the selected file to
|
2002-01-01 17:25:10 +00:00
|
|
|
|
* <file>, if not NULL. */
|
2001-12-22 23:51:12 +00:00
|
|
|
|
int (*select_file)(struct sc_card *card, const struct sc_path *path,
|
|
|
|
|
struct sc_file *file_out);
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*get_response)(struct sc_card *card, u8 * buf, size_t count);
|
|
|
|
|
int (*get_challenge)(struct sc_card *card, u8 * buf, size_t count);
|
|
|
|
|
|
2002-01-07 18:23:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* ISO 7816-8 functions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* verify: Verifies reference data identified by <ref_qualifier>.
|
|
|
|
|
* If <tries_left> is not NULL, number of verify tries left is
|
|
|
|
|
* saved in case of verification failure.
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*verify)(struct sc_card *card, int ref_qualifier,
|
|
|
|
|
const u8 *data, size_t data_len, int *tries_left);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
|
|
|
|
|
/* restore_security_env: Restores a previously saved security
|
|
|
|
|
* environment, and stores information about the environment to
|
|
|
|
|
* <env_out>, if not NULL. */
|
|
|
|
|
int (*restore_security_env)(struct sc_card *card, int se_num,
|
|
|
|
|
struct sc_security_env *env_out);
|
|
|
|
|
|
|
|
|
|
/* set_security_env: Initializes the security environment on card
|
|
|
|
|
* according to <env>, and stores the environment as <se_num> on the
|
|
|
|
|
* card. If se_num <= 0, the environment will not be stored. */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*set_security_env)(struct sc_card *card,
|
2001-12-22 20:43:09 +00:00
|
|
|
|
const struct sc_security_env *env, int se_num);
|
2002-01-07 18:23:34 +00:00
|
|
|
|
/* decipher: Engages the deciphering operation. Card will use the
|
|
|
|
|
* security environment set in a call to set_security_env or
|
|
|
|
|
* restore_security_env. */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*decipher)(struct sc_card *card, const u8 * crgram,
|
|
|
|
|
size_t crgram_len, u8 * out, size_t outlen);
|
2002-01-07 18:23:34 +00:00
|
|
|
|
/* compute_signature: Generates a digital signature on the card. Similiar
|
|
|
|
|
* to the function decipher. */
|
2001-12-20 13:57:58 +00:00
|
|
|
|
int (*compute_signature)(struct sc_card *card, const u8 * data,
|
|
|
|
|
size_t data_len, u8 * out, size_t outlen);
|
|
|
|
|
int (*change_reference_data)(struct sc_card *card, int ref_qualifier,
|
|
|
|
|
const u8 *old, size_t oldlen,
|
|
|
|
|
const u8 *newref, size_t newlen,
|
|
|
|
|
int *tries_left);
|
|
|
|
|
int (*reset_retry_counter)(struct sc_card *card, int ref_qualifier,
|
|
|
|
|
const u8 *puk, size_t puklen,
|
|
|
|
|
const u8 *newref, size_t newlen);
|
|
|
|
|
};
|
|
|
|
|
|
2001-12-22 20:43:09 +00:00
|
|
|
|
struct sc_card_driver {
|
|
|
|
|
char *libpath; /* NULL, if compiled in */
|
|
|
|
|
char *name;
|
2001-12-20 13:57:58 +00:00
|
|
|
|
struct sc_card_operations *ops;
|
2001-11-01 15:43:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sc_context {
|
|
|
|
|
SCARDCONTEXT pcsc_ctx;
|
|
|
|
|
char *readers[SC_MAX_READERS];
|
|
|
|
|
int reader_count;
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2001-12-19 21:58:04 +00:00
|
|
|
|
int debug;
|
|
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
|
int use_std_output, use_cache;
|
2002-01-07 18:23:34 +00:00
|
|
|
|
const struct sc_card_driver *card_drivers[SC_MAX_CARD_DRIVERS+1];
|
|
|
|
|
pthread_mutex_t mutex;
|
2001-11-01 15:43:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sc_apdu {
|
|
|
|
|
int cse; /* APDU case */
|
2001-12-29 02:07:32 +00:00
|
|
|
|
u8 cla, ins, p1, p2; /* CLA, INS, P1 and P2 bytes */
|
|
|
|
|
size_t lc, le; /* Lc and Le bytes */
|
|
|
|
|
const u8 *data; /* C-APDU data */
|
|
|
|
|
size_t datalen; /* length of data in C-APDU */
|
|
|
|
|
u8 *resp; /* R-APDU data buffer */
|
|
|
|
|
size_t resplen; /* in: size of R-APDU buffer,
|
|
|
|
|
* out: length of data returned in R-APDU */
|
|
|
|
|
|
|
|
|
|
unsigned int sw1, sw2; /* Status words returned in R-APDU */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-11-05 19:39:18 +00:00
|
|
|
|
/* Base64 encoding/decoding functions */
|
2001-12-22 13:38:25 +00:00
|
|
|
|
int sc_base64_encode(const u8 *in, size_t inlen, u8 *out, size_t outlen,
|
|
|
|
|
size_t linelength);
|
|
|
|
|
int sc_base64_decode(const char *in, u8 *out, size_t outlen);
|
2001-11-04 13:57:04 +00:00
|
|
|
|
|
2001-11-05 19:39:18 +00:00
|
|
|
|
/* APDU handling functions */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
int sc_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu);
|
2001-12-22 13:38:25 +00:00
|
|
|
|
void sc_format_apdu(struct sc_card *card, struct sc_apdu *apdu, int cse, int ins,
|
|
|
|
|
int p1, int p2);
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
|
|
|
|
int sc_establish_context(struct sc_context **ctx);
|
|
|
|
|
int sc_destroy_context(struct sc_context *ctx);
|
|
|
|
|
int sc_connect_card(struct sc_context *ctx,
|
|
|
|
|
int reader, struct sc_card **card);
|
|
|
|
|
int sc_disconnect_card(struct sc_card *card);
|
2001-12-29 02:07:32 +00:00
|
|
|
|
inline int sc_card_valid(const struct sc_card *card);
|
2001-11-17 15:48:10 +00:00
|
|
|
|
|
|
|
|
|
/* Checks if a card is present on the supplied reader
|
|
|
|
|
* Returns: 1 if card present, 0 if card absent and < 0 in case of an error */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
int sc_detect_card(struct sc_context *ctx, int reader);
|
2001-11-17 15:48:10 +00:00
|
|
|
|
|
|
|
|
|
/* Waits for card insertion on the supplied reader
|
|
|
|
|
* timeout of -1 means forever, reader of -1 means all readers
|
|
|
|
|
* Returns: 1 if a card was found, 0 if timeout occured
|
|
|
|
|
* and < 0 in case of an error */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
int sc_wait_for_card(struct sc_context *ctx, int reader, int timeout);
|
|
|
|
|
|
|
|
|
|
int sc_lock(struct sc_card *card);
|
|
|
|
|
int sc_unlock(struct sc_card *card);
|
|
|
|
|
|
2001-11-04 14:08:38 +00:00
|
|
|
|
/* ISO 7816-4 related functions */
|
2002-01-01 17:25:10 +00:00
|
|
|
|
|
2001-12-22 23:51:12 +00:00
|
|
|
|
int sc_select_file(struct sc_card *card, const struct sc_path *path,
|
|
|
|
|
struct sc_file *file);
|
2001-12-29 02:07:32 +00:00
|
|
|
|
int sc_read_binary(struct sc_card *card, unsigned int idx, u8 * buf,
|
|
|
|
|
size_t count, unsigned long flags);
|
|
|
|
|
int sc_read_record(struct sc_card *card, unsigned int rec_nr, u8 * buf,
|
|
|
|
|
size_t count, unsigned long flags);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
int sc_get_challenge(struct sc_card *card, u8 * rndout, size_t len);
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-11-06 18:34:19 +00:00
|
|
|
|
/* ISO 7816-8 related functions */
|
2001-11-01 15:43:20 +00:00
|
|
|
|
int sc_restore_security_env(struct sc_card *card, int se_num);
|
|
|
|
|
int sc_set_security_env(struct sc_card *card,
|
|
|
|
|
const struct sc_security_env *env);
|
2001-12-22 13:38:25 +00:00
|
|
|
|
int sc_decipher(struct sc_card *card, const u8 * crgram, size_t crgram_len,
|
|
|
|
|
u8 * out, size_t outlen);
|
2001-11-05 19:39:18 +00:00
|
|
|
|
int sc_compute_signature(struct sc_card *card, const u8 * data,
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t data_len, u8 * out, size_t outlen);
|
|
|
|
|
int sc_verify(struct sc_card *card, int ref, const u8 *buf, size_t buflen,
|
2001-11-20 22:21:58 +00:00
|
|
|
|
int *tries_left);
|
|
|
|
|
int sc_change_reference_data(struct sc_card *card, int ref, const u8 *old,
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t oldlen, const u8 *newref, size_t newlen,
|
2001-12-02 19:21:46 +00:00
|
|
|
|
int *tries_left);
|
2001-11-20 22:21:58 +00:00
|
|
|
|
int sc_reset_retry_counter(struct sc_card *card, int ref, const u8 *puk,
|
2001-12-22 13:38:25 +00:00
|
|
|
|
size_t puklen, const u8 *newref, size_t newlen);
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-11-17 00:11:29 +00:00
|
|
|
|
/* ISO 7816-9 */
|
|
|
|
|
int sc_create_file(struct sc_card *card, const struct sc_file *file);
|
|
|
|
|
int sc_delete_file(struct sc_card *card, int file_id);
|
|
|
|
|
|
2001-12-29 02:07:32 +00:00
|
|
|
|
inline int sc_file_valid(const struct sc_file *file);
|
|
|
|
|
void sc_format_path(const char *path_in, struct sc_path *path_out);
|
|
|
|
|
int sc_hex_to_bin(const char *in, u8 *out, size_t *outlen);
|
|
|
|
|
|
2002-01-07 18:23:34 +00:00
|
|
|
|
/* Possibly only valid on Setec cards */
|
2001-11-07 14:36:57 +00:00
|
|
|
|
int sc_list_files(struct sc_card *card, u8 * buf, int buflen);
|
2001-11-01 15:43:20 +00:00
|
|
|
|
|
2001-11-07 14:36:57 +00:00
|
|
|
|
const char *sc_strerror(int error);
|
2001-11-20 22:21:58 +00:00
|
|
|
|
|
2001-11-18 01:52:32 +00:00
|
|
|
|
extern const char *sc_version;
|
2001-11-04 14:08:38 +00:00
|
|
|
|
|
2001-12-22 20:43:09 +00:00
|
|
|
|
extern const struct sc_card_driver *sc_get_iso7816_driver(void);
|
2001-12-27 17:25:10 +00:00
|
|
|
|
extern const struct sc_card_driver *sc_get_emv_driver(void);
|
2001-12-22 20:43:09 +00:00
|
|
|
|
extern const struct sc_card_driver *sc_get_setec_driver(void);
|
2001-12-25 20:45:48 +00:00
|
|
|
|
extern const struct sc_card_driver *sc_get_mflex_driver(void);
|
|
|
|
|
extern const struct sc_card_driver *sc_get_default_driver(void);
|
2001-11-17 14:55:41 +00:00
|
|
|
|
|
2001-12-08 15:27:40 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-01 15:43:20 +00:00
|
|
|
|
#endif
|