#ifdef SCP11_ENABLE
#ifdef DEBUG_LOW

#include "SCP11_public.h"
#include "tz_debug.h"
//#define TESTAMSD

typedef struct cmd {
    int32_t cmd_id;
    int32_t ret;
    uint8_t data[256];
    uint32_t dataLen;
} cmd_t, *p_cmd_t;

typedef struct rsp {
    int32_t status;
    int32_t ret;
    uint8_t data[256];
    uint32_t dataLen;
} rsp_t, *p_rsp_t;

void scp11a_test(p_cmd_t cmd, p_rsp_t rsp) {
#ifdef TESTAMSD
    uint8_t scp11_aid[] = {0xA0,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF}; //Gem test SD
#else
    //uint8_t scp11_aid[] = {0xA0, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00, 0x00}; //ISD
    uint8_t scp11_aid[] = {0xA0,0x00,0x00,0x01,0x51,0x53,0x50,0x41,0x4C,0x43,0x43,0x4D,0x41,0x4D}; //LCCM_AMSD
#endif
    uint32_t scp11_aid_len = sizeof(scp11_aid);
    uint8_t channelId = 0;
#ifdef TESTAMSD
    uint8_t cpdu_data[10] = {0x4F,0x08,0xA0,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF};
#else
    uint8_t cpdu_data[2] = {0x4F,0x00};
#endif
    uint8_t rpdu_data[256] = {0,};
    secEse_7816_cpdu_t cpdu;
    secEse_7816_rpdu_t rpdu;
    uint16_t ret = 0;

    if (cmd==NULL || rsp==NULL) {
        LOGI("Ignore although cmd or rsp is NULL. ");
    }

    //memset(&cpdu,0, sizeof(secEse_7816_cpdu_t));
    //memset(&rpdu,0, sizeof(secEse_7816_rpdu_t));
#ifdef TESTAMSD
// SD get status command
    cpdu.cla = 0x80;
    cpdu.cpdu_type = 0x00;
    cpdu.ins = 0xF2;
    cpdu.lc = 0x12;
    cpdu.le = 0x00;
    cpdu.le_type = 0x01;
    cpdu.p1 = 0x40;
    cpdu.p2 = 0x02;
    cpdu.pdata = cpdu_data;
    rpdu.pdata = rpdu_data;
#else
//  ISD get status command
    cpdu.cla = 0x80;
    cpdu.cpdu_type = 0x00;
    cpdu.ins = 0xF2;
    cpdu.lc = 0x02;
    cpdu.le = 0x00;
    cpdu.le_type = 0x01;
    cpdu.p1 = 0x80;
    cpdu.p2 = 0x00;
    cpdu.pdata = cpdu_data;
    rpdu.pdata = rpdu_data;
#endif

    secEseOpen(&channelId);
    ret = scp11a_openSession(scp11_aid, scp11_aid_len, channelId, 0x33);
    LOGI("scp11a_openSession ret : %d",ret);
    if(ret != 0){
        goto error;
    }

    ret = scp11_apduTransceive(channelId, &cpdu, &rpdu);
    LOGI("scp11_apduTransceive ret : %d",ret);
    if(ret != 0){
        goto error;
    }
    secEseClose(channelId);

error:
    rsp->ret = ret;
}

void scp11b_test(p_cmd_t cmd, p_rsp_t rsp) {

    //uint8_t scp11_aid[] = {0xA0, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00, 0x00};//ISD
    uint8_t scp11_aid[] = {0xA0,0x00,0x00,0x01,0x51,0x53,0x50,0x41,0x4C,0x43,0x43,0x4D,0x41,0x4D};//LCCM_AMSD
    uint32_t scp11_aid_len = sizeof(scp11_aid);
    uint8_t channelId = 0;
    uint8_t cpdu_data[2] = {0x4F,0x00};
    uint8_t rpdu_data[256] = {0,};
    secEse_7816_cpdu_t cpdu;
    secEse_7816_rpdu_t rpdu;
    uint16_t ret = 0;

    if (cmd==NULL || rsp==NULL) {
        LOGI("Ignore although cmd or rsp is NULL. ");
    }

    //memset(&cpdu,0, sizeof(secEse_7816_cpdu_t));
    //memset(&rpdu,0, sizeof(secEse_7816_rpdu_t));
    cpdu.cla = 0x80;
    cpdu.cpdu_type = 0x00;
    cpdu.ins = 0xF2;
    cpdu.lc = 0x02;
    cpdu.le = 0x00;
    cpdu.le_type = 0x01;
    cpdu.p1 = 0x80;
    cpdu.p2 = 0x00;
    cpdu.pdata = cpdu_data;
    rpdu.pdata = rpdu_data;

    secEseOpen(&channelId);

    ret = scp11b_openSession(scp11_aid, scp11_aid_len, channelId, 0x33);
    if(ret != 0){
        goto error;
    }

    ret = scp11_apduTransceive(channelId, &cpdu, &rpdu);
    if(ret != 0){
        goto error;
    }

    secEseClose(channelId);

error:
    rsp->ret = ret;
}

#endif
#endif

