00001
00002
00003
00004
00005
00006 #ifndef _EMV_H
00007 #define _EMV_H
00008
00009 #define EMV_AIP_LEN 2
00010 #define EMV_RID_LEN 5
00011 #define EMV_AID_LEN 11
00012
00013 #define EMV_DATA_BINARY 0x0
00014 #define EMV_DATA_TEXT 0x1
00015 #define EMV_DATA_INT 0x2
00016 #define EMV_DATA_BCD 0x3
00017 #define EMV_DATA_DATE 0x4
00018
00019 #define EMV_ERR_SYSTEM 0x0
00020 #define EMV_ERR_CCID 0x1
00021 #define EMV_ERR_ICC 0x2
00022 #define EMV_ERR_EMV 0x3
00023 #define EMV_ERR_SUCCESS 0x00
00024 #define EMV_ERR_DATA_ELEMENT_NOT_FOUND 0x01
00025 #define EMV_ERR_BAD_PIN_FORMAT 0x02
00026 #define EMV_ERR_FUNC_NOT_SUPPORTED 0x03
00027 #define EMV_ERR_KEY_NOT_FOUND 0x04
00028 #define EMV_ERR_KEY_SIZE_MISMATCH 0x05
00029 #define EMV_ERR_RSA_RECOVERY 0x06
00030 #define EMV_ERR_CERTIFICATE 0x07
00031 #define EMV_ERR_SSA_SIGNATURE 0x08
00032 #define EMV_ERR_BAD_PIN 0x09
00033 #define EMV_ERR_BER_DECODE 0x0a
00034 #define EMV_ERR_APP_NOT_SELECTED 0x0b
00035 typedef uint32_t emv_err_t;
00036
00037 typedef struct _emv *emv_t;
00038 typedef struct _emv_app *emv_app_t;
00039 typedef uint8_t emv_aip_t[EMV_AIP_LEN];
00040 typedef const struct _emv_data *emv_data_t;
00041 typedef uint8_t emv_rid_t[EMV_RID_LEN];
00042 typedef const uint8_t *(*emv_mod_cb_t)(void *priv, unsigned int index,
00043 size_t *len);
00044 typedef const uint8_t *(*emv_exp_cb_t)(void *priv, unsigned int index,
00045 size_t *len);
00046 typedef int (*emv_dol_cb_t)(uint16_t tag, uint8_t *ptr, size_t len, void *priv);
00047
00048
00049 _public emv_t emv_init(chipcard_t cc);
00050 _public void emv_fini(emv_t e);
00051
00052
00053 _public emv_err_t emv_error(emv_t e);
00054 _public unsigned int emv_error_type(emv_err_t e);
00055 _public unsigned int emv_error_additional(emv_err_t e);
00056 _public const char *emv_error_string(emv_err_t err);
00057
00058
00059 _public emv_app_t emv_current_app(emv_t e);
00060 _public int emv_appsel_pse(emv_t e);
00061 _public emv_app_t emv_appsel_pse_first(emv_t e);
00062 _public emv_app_t emv_appsel_pse_next(emv_t e, emv_app_t app);
00063 _public int emv_app_select_pse(emv_t e, emv_app_t app);
00064 _public int emv_app_select_aid(emv_t e, const uint8_t *aid, size_t len);
00065 _public int emv_app_select_aid_next(emv_t e, const uint8_t *aid, size_t len);
00066
00067
00068 _public void emv_app_delete(emv_app_t a);
00069 _public void emv_app_rid(emv_app_t a, emv_rid_t ret);
00070 _public void emv_app_aid(emv_app_t a, uint8_t *ret, size_t *len);
00071 _public const char *emv_app_label(emv_app_t a);
00072 _public const char *emv_app_pname(emv_app_t a);
00073 _public uint8_t emv_app_prio(emv_app_t a);
00074 _public int emv_app_confirm(emv_app_t a);
00075
00076
00077 _public int emv_app_init(emv_t e);
00078 _public int emv_app_aip(emv_t e, emv_aip_t aip);
00079
00080
00081 _public int emv_read_app_data(emv_t e);
00082 _public emv_data_t emv_retrieve_data(emv_t e, uint16_t id);
00083 _public emv_data_t *emv_retrieve_records(emv_t e, unsigned int *nmemb);
00084
00085 _public emv_data_t *emv_data_children(emv_data_t d, unsigned int *nmemb);
00086 _public const uint8_t *emv_data(emv_data_t d, size_t *len);
00087 _public int emv_data_int(emv_data_t d);
00088 _public int emv_data_sda(emv_data_t d);
00089 _public unsigned int emv_data_type(emv_data_t d);
00090 _public uint16_t emv_data_tag(emv_data_t d);
00091 _public const char *emv_data_tag_label(emv_data_t d);
00092
00093
00094 _public int emv_authenticate_static_data(emv_t e, emv_mod_cb_t mod,
00095 emv_exp_cb_t exp, void *priv);
00096 _public int emv_sda_ok(emv_t e);
00097
00098
00099 _public int emv_authenticate_dynamic(emv_t e, emv_mod_cb_t mod,
00100 emv_exp_cb_t exp, void *priv);
00101 _public int emv_dda_ok(emv_t e);
00102
00103
00104 _public int emv_cvm_pin(emv_t e, const char *pin);
00105 _public int emv_pin_try_counter(emv_t e);
00106
00107
00108 _public int emv_trm_last_online_atc(emv_t e);
00109 _public int emv_trm_atc(emv_t e);
00110
00111
00112 _public uint8_t *emv_construct_dol(emv_dol_cb_t cbfn,
00113 const uint8_t *ptr, size_t len,
00114 size_t *ret_len, void *priv);
00115
00116 _public const uint8_t *emv_generate_ac(emv_t e, uint8_t ref,
00117 const uint8_t *tx, uint8_t len,
00118 size_t *rlen);
00119
00120
00121 #define EMV_AC_AAC 0x00
00122 #define EMV_AC_TC 0x40
00123 #define EMV_AC_ARQC 0x80
00124 #define EMV_AC_CDA 0x10
00125
00126
00127 #define EMV_AIP_CDA 0x01
00128 #define EMV_AIP_ISS 0x04
00129 #define EMV_AIP_TRM 0x08
00130 #define EMV_AIP_CVM 0x10
00131 #define EMV_AIP_DDA 0x20
00132 #define EMV_AIP_SDA 0x40
00133
00134
00135 #define EMV_AUC1_DOMESTIC_CASH (1<<7)
00136 #define EMV_AUC1_INT_CASH (1<<6)
00137 #define EMV_AUC1_DOMESTIC_GOODS (1<<5)
00138 #define EMV_AUC1_INT_GOODS (1<<4)
00139 #define EMV_AUC1_DOMESTIC_SERVICES (1<<3)
00140 #define EMV_AUC1_INT_SERVICES (1<<2)
00141 #define EMV_AUC1_ATM (1<<1)
00142 #define EMV_AUC1_NON_ATM_TERMINALS (1<<0)
00143
00144 #define EMV_AUC2_DOMESTIC_CASHBACK (1<<7)
00145 #define EMV_AUC2_INT_CASHBACK (1<<6)
00146
00147
00148 #define EMV_TAG_MAGSTRIP_TRACK2 0x0057
00149 #define EMV_TAG_PAN 0x005a
00150 #define EMV_TAG_RECORD 0x0070
00151 #define EMV_TAG_CDOL1 0x008c
00152 #define EMV_TAG_CDOL2 0x008d
00153 #define EMV_TAG_CVM_LIST 0x008e
00154 #define EMV_TAG_CA_PK_INDEX 0x008f
00155 #define EMV_TAG_ISS_PK_CERT 0x0090
00156 #define EMV_TAG_ISS_PK_R 0x0092
00157 #define EMV_TAG_SSA_DATA 0x0093
00158 #define EMV_TAG_CARDHOLDER_NAME 0x5f20
00159 #define EMV_TAG_DATE_EXP 0x5f24
00160 #define EMV_TAG_DATE_EFF 0x5f25
00161 #define EMV_TAG_ISSUER_COUNTRY 0x5f28
00162 #define EMV_TAG_SERVICE_CODE 0x5f30
00163 #define EMV_TAG_PAN_SEQ 0x5f34
00164 #define EMV_TAG_USAGE_CONTROL 0x9f07
00165 #define EMV_TAG_APP_VER 0x9f08
00166 #define EMV_TAG_IAC_DEFAULT 0x9f0d
00167 #define EMV_TAG_IAC_DENY 0x9f0e
00168 #define EMV_TAG_IAC_ONLINE 0x9f0f
00169 #define EMV_TAG_MAGSTRIP_TRACK1 0x9f1f
00170 #define EMV_TAG_ISS_PK_EXP 0x9f32
00171 #define EMV_TAG_CURRENCY_EXP 0x9f44
00172 #define EMV_TAG_ICC_PK_CERT 0x9f46
00173 #define EMV_TAG_ICC_PK_EXP 0x9f47
00174 #define EMV_TAG_ICC_PK_R 0x9f48
00175 #define EMV_TAG_DDOL 0x9f49
00176 #define EMV_TAG_SDA_TAG_LIST 0x9f4a
00177
00178 #define EMV_TAG_UNPREDICTABLE_NUMBER 0x9f37
00179
00180 #endif