remove autogenerated file
[librfid] / src / rfid_proto_tagit.c
1
2 /* UNFINISHED TI Tag-it implementation, PCD side.
3  *
4  * (C) 2005-2008 by Harald Welte <laforge@gnumonks.org>
5  *
6  */
7
8 /*
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 2
11  *  as published by the Free Software Foundation
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <errno.h>
27
28 #include <librfid/rfid.h>
29 #include <librfid/rfid_protocol.h>
30 #include <librfid/rfid_layer2.h>
31 #include <librfid/rfid_layer2_iso15693.h>
32 #include <librfid/rfid_protocol_tagit.h>
33
34 struct tagit_version {
35         u_int8_t version;       /* bit 47..40 (last bit masked) of uid */
36         const char *name;
37 };
38
39 const struct tagit_version tagit_versions[] = {
40         {
41                 .version = 0x00,
42                 .name = "HF-I Plus Inlay",
43         }, {
44                 .version = 0x80,
45                 .name = "HF-I Plus Chip",
46         }, {
47                 .version = 0xc0,
48                 .name = "HF-I Standard Chip / Inlay",
49         }, {
50                 .version = 0xc4,
51                 .name = "HF-I Pro Chip / Inlay",
52         },
53 };
54
55 static int
56 tagit_read(struct rfid_protocol_handle *ph, unsigned int page,
57            unsigned char *rx_data, unsigned int *rx_len)
58 {
59         unsigned char rx_buf[16];
60         unsigned int real_rx_len = sizeof(rx_buf);
61         unsigned char tx[2];
62         int ret;
63
64         /* FIXME */
65         return -EINVAL;
66 }
67
68 static int
69 tagit_write(struct rfid_protocol_handle *ph, unsigned int page,
70             unsigned char *tx_data, unsigned int tx_len)
71 {
72         unsigned int i;
73         unsigned char tx[6];
74         unsigned char rx[10];
75         unsigned int rx_len = sizeof(rx);
76         int ret;
77
78         return -EINVAL;
79 }
80
81 static int
82 tagit_getopt(struct rfid_protocol_handle *ph, int optname, void *optval,
83             unsigned int *optlen)
84 {
85         int ret = -EINVAL;
86         unsigned int *size = optval;
87
88         switch (optname) {
89         case RFID_OPT_PROTO_SIZE:
90                 ret = 0;
91                 /* we have to return the size in bytes, not bits */
92                 /* FIXME: implement this */
93                 *size = 12345;
94                 break;
95         }
96
97         return ret;
98 }
99
100
101 static struct rfid_protocol_handle *
102 tagit_init(struct rfid_layer2_handle *l2h)
103 {
104         struct rfid_protocol_handle *ph;
105         u_int8_t uid[6];
106         unsigned int uid_len = sizeof(uid);
107
108         if (l2h->l2->id != RFID_LAYER2_ISO15693)
109                 return NULL;
110
111         /* According to "SCBU002 - November 2005 */
112         rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID,
113                            uid, &uid_len);
114         if (uid[5] != 0xe0 || uid[4] != 0x07)
115                 return NULL;
116         if (l2h->uid_len != 6)
117                 return NULL;
118
119         ph = malloc_protocol_handle(sizeof(struct rfid_protocol_handle));
120         return ph;
121 }
122
123 static int tagit_fini(struct rfid_protocol_handle *ph)
124 {
125         free_protocol_handle(ph);
126         return 0;
127 }
128
129 const struct rfid_protocol rfid_protocol_tagit = {
130         .id     = RFID_PROTOCOL_TAGIT,
131         .name   = "TI Tag-it HF",
132         .fn     = {
133                 .init           = &tagit_init,
134                 .read           = &tagit_read,
135                 .write          = &tagit_write,
136                 .fini           = &tagit_fini,
137                 .getopt         = &tagit_getopt,
138         },
139 };
140
141 /* Functions below are not (yet? covered in the generic librfid api */