summaryrefslogtreecommitdiff
path: root/rfid_reader_cm5121_openct.c
blob: 9d9663846d08799cab67f3d7e2a8d47c63df49bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* CM5121 backend for OpenCT virtual slot */

#include <stdio.h>

#include <rfid/rfid_asic.h>
#include <openct/openct.h>

/* FIXME: get rid of this global crap.  In fact this needs to become part of
 * struct rfid_reader_handle  */
static ct_lock_handle lock;
static int slot = 1;

/* this is the sole function required by rfid_reader_cm5121.c */
int 
PC_to_RDR_Escape(void *handle, 
		 const unsigned char *tx_buf, unsigned int tx_len,
		 unsigned char *rx_buf, unsigned int *rx_len)
{
	int rc;
	ct_handle *h = (ct_handle *) handle;

	rc = ct_card_transact(h, 1, tx_buf, tx_len, rx_buf, *rx_len);
	if (rc >= 0) {
		*rx_len = rc;
		return 0;
	}

	return rc;
}


int cm5121_source_init(struct rfid_asic_transport_handle *rath)
{
	struct ct_handle *h;
	int rc;
	unsigned char atr[64];

	h = ct_reader_connect(0);
	if (!h)
		return -1;

	printf("acquiring card lock\n");
	rc = ct_card_lock(h, slot, IFD_LOCK_EXCLUSIVE, &lock);
	if (rc < 0) {
		fprintf(stderr, "error, no card lock\n");
		return -1;
	}

	rc = ct_card_reset(h, slot, atr, sizeof(atr));
	if (rc < 0) {
		fprintf(stderr, "error, can't reset virtual card\n");
		return -1;
	}

	rath->data = h;

	return 0;
}

personal git repositories of Harald Welte. Your mileage may vary