nfc test on MQX4.1
[nfc-test.git] / ccid_picc.c
blobd69ae22f5c0957cbf50cabb600ba9eab1283f8f2
2 #include "ccid.h"
4 static uint8_t ccid_get_picc_status(void)
6 if(BITISCLEAR(common->picc.status, PRESENT))
7 return PICC_ICCSTATUS_NOICC;
8 else if(BITISCLEAR(common->picc.status, ACTIVATED))
9 return PICC_ICCSTATUS_INACTIVE;
10 else
11 return PICC_ICCSTATUS_ACTIVE;
14 static void ccid_picc_power_on(struct ccid_msg_data *picc_data)
16 int ret = 0;
18 ret = picc_power_on(&common->picc, picc_data->rBuf, &picc_data->rLen);
20 picc_data->errCode = ret;
21 picc_data->cardStatus = ccid_get_picc_status();
24 static void ccid_picc_power_off(struct ccid_msg_data *picc_data)
26 picc_power_off(&common->picc);
28 picc_data->errCode = PICC_ERRORCODE_NONE;
29 picc_data->param = 0;
31 picc_data->cardStatus = ccid_get_picc_status();
34 static void ccid_picc_get_slot_status(struct ccid_msg_data *picc_data)
36 picc_data->errCode = PICC_ERRORCODE_NONE;
37 picc_data->param = 0;
39 picc_data->cardStatus = ccid_get_picc_status();
42 static void ccid_picc_xfr_block(struct ccid_msg_data *picc_data)
44 uint8_t level = (uint8_t)picc_data->param;
45 int ret = 0;
47 // pr_debug("slen = %08X, rlen = %08X\n", picc_data->sLen, picc_data->rLen);
48 ret = picc_command_exchange(&common->picc, picc_data->sBuf, picc_data->sLen,
49 picc_data->rBuf, &picc_data->rLen,
50 &level);
51 // pr_debug("slen = %08X, rlen = %08X\n", picc_data->sLen, picc_data->rLen);
52 picc_data->errCode = ret;
53 picc_data->param = 0;
55 picc_data->cardStatus = ccid_get_picc_status();
58 static void ccid_picc_get_parameters(struct ccid_msg_data *picc_data)
60 // bmFindexDindex
61 picc_data->rBuf[0] = 0x11;
62 // bmTCCKST1
63 picc_data->rBuf[1] = 0x10;
64 // bGuardTimeT1
65 picc_data->rBuf[2] = 0x01;
66 // bmWaitingIntegersT1
67 picc_data->rBuf[3] = 0x4D;
68 // bClockStop
69 picc_data->rBuf[4] = 0x00;
71 // bIFSC
72 if(fsdi_to_fsd[common->picc.FSCI] > (uint16_t)0xFE)
73 picc_data->rBuf[5] = 0xFE;
74 else
75 picc_data->rBuf[5] = (uint8_t)fsdi_to_fsd[common->picc.FSCI];
76 // bNadValue
77 picc_data->rBuf[6] = 0x00;
78 // bProtocolNum
79 picc_data->param = 0x01;
80 picc_data->rLen = 0x07;
81 picc_data->errCode = PICC_ERRORCODE_NONE;
82 picc_data->cardStatus = ccid_get_picc_status();
85 static void ccid_picc_set_parameters(struct ccid_msg_data *picc_data)
87 ccid_picc_get_parameters(picc_data);
90 static void ccid_picc_reset_parameters(struct ccid_msg_data *picc_data)
92 ccid_picc_get_parameters(picc_data);
95 static void ccid_picc_escape(struct ccid_msg_data *picc_data)
100 static struct ccid_operations ccid_picc_ops =
102 .card_power_on = ccid_picc_power_on,
103 .card_power_off = ccid_picc_power_off,
104 .get_slot_status = ccid_picc_get_slot_status,
105 .xfr_block = ccid_picc_xfr_block,
106 .get_parameters = ccid_picc_get_parameters,
107 .set_parameters = ccid_picc_set_parameters,
108 .reset_parameters = ccid_picc_reset_parameters,
109 .escape = ccid_picc_escape,
112 int picc_interrput_in(uint8_t slot_status)
114 if(!common->slot_changed_notify)
115 return(-ENXIO);
116 return(common->slot_changed_notify(common->private_data, slot_status));
119 void ccid_picc_init(struct ccid_operations **ops,
120 uint32_t max_IFSD,
121 int (*picc_intr_in)(void *, uint8_t),
122 void *pri_data)
124 picc_param_init(common, max_IFSD);
126 common->slot_changed_notify = picc_intr_in;
128 common->private_data = pri_data;
130 *ops = &ccid_picc_ops;
133 void ccid_picc_uninit(void)
135 picc_param_init(common, 256);
137 common->slot_changed_notify = NULL;
139 common->private_data = NULL;