some preliminary work to get 15693 working (actual implementation still missing)
[librfid] / src / rfid_layer2_iso15693.c
1 /* ISO 15693 anticollision implementation
2  *
3  * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
4  *
5  */
6
7 /*
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License version 2 
10  *  as published by the Free Software Foundation
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25
26 #include <librfid/rfid.h>
27 #include <librfid/rfid_layer2.h>
28 #include <librfid/rfid_reader.h>
29 #include <librfid/rfid_layer2_iso15693.h>
30
31 struct iso15693_request_read {
32         struct iso15693_request req;
33         u_int64_t uid;
34         u_int8_t blocknum;
35 } __attribute__ ((packed));
36
37 #define ISO15693_BLOCK_SIZE_MAX (256/8)
38 #define ISO15693_RESP_SIZE_MAX  (4+ISO15693_BLOCK_SIZE_MAX)
39
40 #if 0
41 static int
42 iso15693_read_block(struct rfid_layer2_handle *handle,
43                     u_int8_t blocknr, u_int32_t *data)
44 {
45         int rc;
46         struct iso15693_request_read req;
47         u_int8_t resp[ISO15693_RESP_SIZE_MAX];
48
49         req.req.flags = 0;
50         req.command = ISO15693_CMD_READ_BLOCK_SINGLE;
51         memcpy(&req.uid, handle->..., ISO15693_UID_LEN);
52         req.blocknum = blocknr;
53
54         /* FIXME: fill CRC if required */
55
56         rc = iso15693_transceive(... &req, ...,  );
57
58         if (rc < 0)
59                 return rc;
60
61         memcpy(data, resp+1, rc-1); /* FIXME rc-3 in case of CRC */
62
63         return rc-1;
64 }
65
66 static int
67 iso15693_write_block()
68 {
69         struct iso16593_request_read *rreq;
70         u_int32_t buf[sizeof(req)+ISO15693_BLOCK_SIZE_MAX];
71
72         rreq = (struct iso15693_request_read *) req;
73
74         rreq->req.flags = ;
75         rreq->req.command = ISO15693_CMD_WRITE_BLOCK_SINGLE;
76         memcpy(rreq->uid, handle->, ISO15693_UID_LEN);
77         rreq->blocknum = blocknr;
78         memcpy(rreq->);
79
80 }
81
82 static int
83 iso15693_lock_block()
84 {
85 }
86
87 #endif
88
89 static int
90 iso15693_anticol(struct rfid_layer2_handle *handle)
91 {
92         return -1;
93 }
94
95 static struct rfid_layer2_handle *
96 iso15693_init(struct rfid_reader_handle *rh)
97 {
98         int ret;
99         struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
100         if (!h)
101                 return NULL;
102
103         h->l2 = &rfid_layer2_iso15693;
104         h->rh = rh;
105         h->priv.iso15693.state = ISO15693_STATE_NONE;
106         ret = h->rh->reader->iso15693.init(h->rh);
107         if (ret < 0) {
108                 free_layer2_handle(h);
109                 return NULL;
110         }
111
112         return h;
113 }
114
115 static int
116 iso15693_fini(struct rfid_layer2_handle *handle)
117 {
118         free_layer2_handle(handle);
119         return 0;
120 }
121
122
123 const struct rfid_layer2 rfid_layer2_iso15693 = {
124         .id     = RFID_LAYER2_ISO15693,
125         .name   = "ISO 15693",
126         .fn     = {
127                 .init           = &iso15693_init,
128                 .open           = &iso15693_anticol,
129                 //.transceive   = &iso15693_transceive,
130                 //.close                = &iso14443a_hlta,
131                 .fini           = &iso15693_fini,
132         },
133 };
134