summaryrefslogtreecommitdiff
path: root/src/rfid_proto_tagit.c
blob: 0388baabcb360deedda681a36718f0e7c91d9f16 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

/* UNFINISHED TI Tag-it implementation, PCD side.
 *
 * (C) 2005-2008 by Harald Welte <laforge@gnumonks.org>
 *
 */

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <librfid/rfid.h>
#include <librfid/rfid_protocol.h>
#include <librfid/rfid_layer2.h>
#include <librfid/rfid_layer2_iso15693.h>
#include <librfid/rfid_protocol_tagit.h>

struct tagit_version {
	u_int8_t version;	/* bit 47..40 (last bit masked) of uid */
	const char *name;
};

const struct tagit_version tagit_versions[] = {
	{
		.version = 0x00,
		.name = "HF-I Plus Inlay",
	}, {
		.version = 0x80,
		.name = "HF-I Plus Chip",
	}, {
		.version = 0xc0,
		.name = "HF-I Standard Chip / Inlay",
	}, {
		.version = 0xc4,
		.name = "HF-I Pro Chip / Inlay",
	},
};

static int
tagit_read(struct rfid_protocol_handle *ph, unsigned int page,
	   unsigned char *rx_data, unsigned int *rx_len)
{
	unsigned char rx_buf[16];
	unsigned int real_rx_len = sizeof(rx_buf);
	unsigned char tx[2];
	int ret;

	/* FIXME */
	return -EINVAL;
}

static int
tagit_write(struct rfid_protocol_handle *ph, unsigned int page,
	    unsigned char *tx_data, unsigned int tx_len)
{
	unsigned int i;
	unsigned char tx[6];
	unsigned char rx[10];
	unsigned int rx_len = sizeof(rx);
	int ret;

	return -EINVAL;
}

static int
tagit_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
	    unsigned int *optlen)
{
	int ret = -EINVAL;
	unsigned int *size = optval;

	switch (optname) {
	case RFID_OPT_PROTO_SIZE:
		ret = 0;
		/* we have to return the size in bytes, not bits */
		/* FIXME: implement this */
		*size = 12345;
		break;
	}

	return ret;
}


static struct rfid_protocol_handle *
tagit_init(struct rfid_layer2_handle *l2h)
{
	struct rfid_protocol_handle *ph;
	u_int8_t uid[6];
	unsigned int uid_len = sizeof(uid);

	if (l2h->l2->id != RFID_LAYER2_ISO15693)
		return NULL;

	/* According to "SCBU002 - November 2005 */
	rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID,
			   uid, &uid_len);
	if (uid[5] != 0xe0 || uid[4] != 0x07)
		return NULL;
	if (l2h->uid_len != 6)
		return NULL;

	ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
	return ph;
}

static int tagit_fini(struct rfid_protocol_handle *ph)
{
	free_protocol_handle(ph);
	return 0;
}

const struct rfid_protocol rfid_protocol_tagit = {
	.id	= RFID_PROTOCOL_TAGIT,
	.name	= "TI Tag-it HF",
	.fn	= {
		.init 		= &tagit_init,
		.read		= &tagit_read,
		.write 		= &tagit_write,
		.fini		= &tagit_fini,
		.getopt		= &tagit_getopt,
	},
};

/* Functions below are not (yet? covered in the generic librfid api */
personal git repositories of Harald Welte. Your mileage may vary