00001
00002
00003
00004
00005
00006
00007 #include <ccid.h>
00008 #include <list.h>
00009 #include <emv.h>
00010 #include <ber.h>
00011 #include "emv-internal.h"
00012
00013 static int bop_po(const uint8_t *ptr, size_t len, void *priv)
00014 {
00015 struct _emv *e = priv;
00016
00017 if ( len < sizeof(e->e_aip) )
00018 return 9;
00019
00020 memcpy(e->e_aip, ptr, sizeof(e->e_aip));
00021
00022 e->e_afl_len = len - sizeof(e->e_aip);
00023 e->e_afl = malloc(e->e_afl_len);
00024 if ( NULL == e->e_afl )
00025 return 0;
00026
00027 memcpy(e->e_afl, ptr + sizeof(e->e_aip), e->e_afl_len);
00028
00029 return 1;
00030 }
00031
00032 static int get_aip(emv_t e)
00033 {
00034 static const uint8_t pdol[] = {0x83, 0x00};
00035 static const struct ber_tag tags[] = {
00036 { .tag = "\x80", .tag_len = 1, .op = bop_po},
00037 };
00038 const uint8_t *res;
00039 size_t len;
00040
00041
00042
00043 if ( !_emv_get_proc_opts(e, pdol, sizeof(pdol)) )
00044 return 0;
00045 res = xfr_rx_data(e->e_xfr, &len);
00046 if ( NULL == res )
00047 return 0;
00048 return ber_decode(tags, sizeof(tags)/sizeof(*tags), res, len, e);
00049 }
00050
00051 int emv_app_init(emv_t e)
00052 {
00053 if ( !get_aip(e) )
00054 return 0;
00055
00056 #if 0
00057 if ( e->e_aip[0] & EMV_AIP_ISS )
00058 printf("AIP: Issuer authentication\n");
00059 if ( e->e_aip[0] & EMV_AIP_TRM )
00060 printf("AIP: Terminal risk management required\n");
00061 if ( e->e_aip[0] & EMV_AIP_CVM )
00062 printf("AIP: Cardholder verification supported\n");
00063 if ( e->e_aip[0] & EMV_AIP_DDA )
00064 printf("AIP: Dynamic data authentication\n");
00065 if ( e->e_aip[0] & EMV_AIP_SDA)
00066 printf("AIP: Static data authentication\n");
00067 if ( e->e_aip[0] & EMV_AIP_CDA)
00068 printf("AIP: Combined data authentication\n");
00069 #endif
00070
00071 _emv_success(e);
00072 return 1;
00073 }
00074
00075 int emv_app_aip(emv_t e, emv_aip_t aip)
00076 {
00077 if ( NULL == e->e_app ) {
00078 _emv_error(e, EMV_ERR_APP_NOT_SELECTED);
00079 return 0;
00080 }
00081
00082 memcpy(aip, e->e_aip, sizeof(e->e_aip));
00083 return 1;
00084 }