fix more compiler warnings, based on a patch by Rainer Keller
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <errno.h>
26
27 #include <librfid/rfid.h>
28 #include <librfid/rfid_layer2.h>
29 #include <librfid/rfid_reader.h>
30 #include <librfid/rfid_layer2_iso15693.h>
31
32 struct iso15693_request_read {
33         struct iso15693_request req;
34         u_int64_t uid;
35         u_int8_t blocknum;
36 } __attribute__ ((packed));
37
38 #define ISO15693_BLOCK_SIZE_MAX (256/8)
39 #define ISO15693_RESP_SIZE_MAX  (4+ISO15693_BLOCK_SIZE_MAX)
40
41 #if 0
42 static int
43 iso15693_read_block(struct rfid_layer2_handle *handle,
44                     u_int8_t blocknr, u_int32_t *data)
45 {
46         int rc;
47         struct iso15693_request_read req;
48         u_int8_t resp[ISO15693_RESP_SIZE_MAX];
49
50         req.req.flags = 0;
51         req.command = ISO15693_CMD_READ_BLOCK_SINGLE;
52         memcpy(&req.uid, handle->..., ISO15693_UID_LEN);
53         req.blocknum = blocknr;
54
55         /* FIXME: fill CRC if required */
56
57         rc = iso15693_transceive(... &req, ...,  );
58
59         if (rc < 0)
60                 return rc;
61
62         memcpy(data, resp+1, rc-1); /* FIXME rc-3 in case of CRC */
63
64         return rc-1;
65 }
66
67 static int
68 iso15693_write_block()
69 {
70         struct iso16593_request_read *rreq;
71         u_int32_t buf[sizeof(req)+ISO15693_BLOCK_SIZE_MAX];
72
73         rreq = (struct iso15693_request_read *) req;
74
75         rreq->req.flags = ;
76         rreq->req.command = ISO15693_CMD_WRITE_BLOCK_SINGLE;
77         memcpy(rreq->uid, handle->, ISO15693_UID_LEN);
78         rreq->blocknum = blocknr;
79         memcpy(rreq->);
80
81 }
82
83 static int
84 iso15693_lock_block()
85 {
86 }
87
88 #endif
89
90 static int
91 iso15693_anticol(struct rfid_layer2_handle *handle)
92 {
93         return -1;
94 }
95
96 static int
97 iso15693_getopt(struct rfid_layer2_handle *handle,
98                 int optname, void *optval, unsigned int *optlen)
99 {
100         switch (optname) {
101         case RFID_OPT_15693_MOD_DEPTH:
102         case RFID_OPT_15693_VCD_CODING:
103         case RFID_OPT_15693_VICC_SUBC:
104         case RFID_OPT_15693_VICC_SPEED:
105         default:
106                 return -EINVAL;
107                 break;
108         }
109         return 0;
110 }
111
112 static int
113 iso15693_setopt(struct rfid_layer2_handle *handle, int optname,
114                 const void *optval, unsigned int optlen)
115 {
116         switch (optname) {
117         case RFID_OPT_15693_MOD_DEPTH:
118         case RFID_OPT_15693_VCD_CODING:
119         case RFID_OPT_15693_VICC_SUBC:
120         case RFID_OPT_15693_VICC_SPEED:
121         default:
122                 return -EINVAL;
123                 break;
124         }
125         return 0;
126 }
127
128 static int transceive_inventory(struct rfid_layer2_handle *l2h)
129 {
130 }
131
132 static struct rfid_layer2_handle *
133 iso15693_init(struct rfid_reader_handle *rh)
134 {
135         int ret;
136         struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
137         if (!h)
138                 return NULL;
139
140         h->l2 = &rfid_layer2_iso15693;
141         h->rh = rh;
142         h->priv.iso15693.state = ISO15693_STATE_NONE;
143         ret = h->rh->reader->iso15693.init(h->rh);
144         if (ret < 0) {
145                 free_layer2_handle(h);
146                 return NULL;
147         }
148
149         return h;
150 }
151
152 static int
153 iso15693_fini(struct rfid_layer2_handle *handle)
154 {
155         free_layer2_handle(handle);
156         return 0;
157 }
158
159
160 const struct rfid_layer2 rfid_layer2_iso15693 = {
161         .id     = RFID_LAYER2_ISO15693,
162         .name   = "ISO 15693",
163         .fn     = {
164                 .init           = &iso15693_init,
165                 .open           = &iso15693_anticol,
166                 //.transceive   = &iso15693_transceive,
167                 //.close                = &iso14443a_hlta,
168                 .fini           = &iso15693_fini,
169                 .setopt         = &iso15693_setopt,
170                 .getopt         = &iso15693_getopt,
171         },
172 };
173