add CRC check to ISO15693 (Bjoern Riemer)
[librfid] / src / rfid_layer2_iso15693.c
1 /* ISO 15693 anticollision implementation
2  *
3  * (C) 2005-2008 by Harald Welte <laforge@gnumonks.org>
4  * (C) 2007 by Bjoern Riemer <bjoern.riemer@web.de>
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 struct iso15693_request_adressed {
39         struct iso15693_request head;
40         u_int64_t uid;
41 } __attribute__ ((packed));
42
43 #define ISO15693_BLOCK_SIZE_MAX (256/8)
44 #define ISO15693_RESP_SIZE_MAX  (4+ISO15693_BLOCK_SIZE_MAX)
45
46 const unsigned int iso15693_timing[2][5] = {
47         [ISO15693_T_SLOW] = {
48                 [ISO15693_T1]   = 1216, /* max time after VCD EOF before VICC SOF */
49                 [ISO15693_T2]   = 1200, /* min time before VCD EOF after VICC response */
50                 [ISO15693_T3]   = 1502, /* min time after VCD EOF before next EOF if no VICC response */
51                 [ISO15693_T4]   = 1216, /* time after wich VICC transmits after VCD EOF */
52                 [ISO15693_T4_WRITE]=20000,      /* time after wich VICC transmits after VCD EOF */
53         },
54         [ISO15693_T_FAST] = {
55                 [ISO15693_T1]   = 304,  /* max time after VCD EOF before VICC SOF */
56                 [ISO15693_T2]   = 300,  /* min time before VCD EOF after VICC response */
57                 [ISO15693_T3]   = 602,  /* min time after VCD EOF before next EOF if no VICC response */
58                 [ISO15693_T4]   = 304,  /* time after wich VICC transmits after VCD EOF */
59                 [ISO15693_T4_WRITE]=20000,      /* time after wich VICC transmits after VCD EOF */
60         },
61 };
62
63 char *
64 iso15693_get_response_error_name(u_int8_t error){
65         switch (error){
66                 case RFID_15693_ERR_NOTSUPP:
67                         return "ERR_NOTSUPP";
68                 case RFID_15693_ERR_INVALID: /* command not recognized */
69                         return "ERR_INVALID";
70                 case RFID_15693_ERR_UNKNOWN: /* unknown error */
71                         return "ERR_UNKNOWN";
72                 case RFID_15693_ERR_BLOCK_NA: /* block not available */
73                         return "ERR_BLOCK_N";
74                 case RFID_15693_ERR_BLOCK_LOCKED:
75                         return "ERR_BLOCK_LOCKE";
76                 case RFID_15693_ERR_BLOCK_LOCKED_CH:
77                         return "ERR_BLOCK_LOCKED_CH";
78                 case RFID_15693_ERR_BLOCK_NOTPROG:
79                         return "ERR_BLOCK_NOTPROG";
80                 case RFID_15693_ERR_BLOCK_NOTLOCK:
81                         return "ERR_BLOCK_NOTLOCK";
82                 case 0xA0: /* until 0xDF*/
83                         return "Custom Command error Code";
84                 case 0xE0:
85                 default:
86                         return "Undef.";
87         }
88 }
89
90 static int iso15693_transceive(struct rfid_layer2_handle *handle,
91                                enum rfid_frametype frametype,
92                                const unsigned char *tx_buf, unsigned int tx_len,
93                                unsigned char *rx_buf, unsigned int *rx_len,
94                                u_int64_t timeout, unsigned int flags)
95 {
96         return handle->rh->reader->transceive(handle->rh, frametype, tx_buf,
97                                         tx_len, rx_buf, rx_len, timeout, flags);
98 }
99
100 /* Transmit an anticollission frame */
101 static int
102 iso15693_transceive_acf(struct rfid_layer2_handle *handle,
103                         const struct iso15693_anticol_cmd *acf,
104                         unsigned int acf_len,
105                         struct iso15693_anticol_resp *resp,
106                         unsigned int *rx_len, char *bit_of_col)
107 {
108         const struct rfid_reader *rdr = handle->rh->reader;
109         if (!rdr->iso15693.transceive_ac)
110                 return -1;
111         return rdr->iso15693.transceive_ac(handle->rh, acf, acf_len, resp, rx_len, bit_of_col);
112 }
113
114 #if 0
115
116 static int
117 iso15693_read_block(struct rfid_layer2_handle *handle,
118                     u_int8_t blocknr, u_int32_t *data)
119 {
120         int rc;
121         struct iso15693_request_read req;
122         u_int8_t resp[ISO15693_RESP_SIZE_MAX];
123
124         req.req.flags = 0;
125         req.command = ISO15693_CMD_READ_BLOCK_SINGLE;
126         memcpy(&req.uid, handle->..., ISO15693_UID_LEN);
127         req.blocknum = blocknr;
128
129         /* FIXME: fill CRC if required */
130
131         rc = iso15693_transceive(... &req, ...,  );
132
133         if (rc < 0)
134                 return rc;
135
136         memcpy(data, resp+1, rc-1); /* FIXME rc-3 in case of CRC */
137
138         return rc-1;
139 }
140
141 static int
142 iso15693_write_block()
143 {
144         struct iso16593_request_read *rreq;
145         u_int32_t buf[sizeof(req)+ISO15693_BLOCK_SIZE_MAX];
146
147         rreq = (struct iso15693_request_read *) req;
148
149         rreq->req.flags = ;
150         rreq->req.command = ISO15693_CMD_WRITE_BLOCK_SINGLE;
151         memcpy(rreq->uid, handle->, ISO15693_UID_LEN);
152         rreq->blocknum = blocknr;
153         memcpy(rreq->);
154
155 }
156
157 static int
158 iso15693_lock_block()
159 {
160 }
161
162 #endif
163
164 /* Helper function to build an ISO 15693 anti collision frame */
165 static int
166 iso15693_build_acf(u_int8_t *target, u_int8_t flags, u_int8_t afi,
167                    u_int8_t mask_len, u_int8_t *mask)
168 {
169         struct iso15693_request *req = (struct iso15693_request *) target;
170         int i = 0, j, mask_bytes;
171         u_int8_t byte=0;
172         void* mask_p;
173
174         req->flags = flags;
175         req->command = ISO15693_CMD_INVENTORY;
176         if (flags & RFID_15693_F5_AFI_PRES)
177                 req->data[i++] = afi;
178         req->data[i++] = mask_len;
179
180         mask_bytes = mask_len/8 + (mask_len%8)?1:0;
181         mask_p=&req->data[i];
182
183         for (j = 0; j < mask_bytes; j++)
184                 req->data[i++] = mask[j];
185
186         byte = 0xFF >> (8-mask_len%8);
187         req->data[i-1]&=byte;
188
189         DEBUGP("mask_len: %d mask_bytes: %d i: %d return: %d mask:%s\n",
190                 mask_len,mask_bytes,i,i + sizeof(*req),rfid_hexdump(mask_p,mask_bytes));
191         return i + sizeof(*req);
192 }
193
194 static int
195 iso15693_anticol(struct rfid_layer2_handle *handle)
196 {
197         int i, ret, mask_len;
198         int tx_len, rx_len;
199         int num_valid = 0;
200         union {
201                 struct iso15693_anticol_cmd_afi w_afi;
202                 struct iso15693_anticol_cmd no_afi;
203         } acf;
204
205         struct iso15693_anticol_resp resp;
206                 
207         u_int8_t boc;
208 #define MAX_SLOTS 16    
209         int num_slots = MAX_SLOTS;
210
211         u_int8_t uuid_list[MAX_SLOTS][ISO15693_UID_LEN];
212         int uuid_list_valid[MAX_SLOTS];
213
214         u_int8_t flags;
215
216 #define MY_NONE 0
217 #define MY_COLL 1
218 #define MY_UUID 2
219
220         memset(uuid_list_valid, MY_NONE, sizeof(uuid_list_valid));
221         memset(uuid_list, 0, sizeof(uuid_list));
222
223         //memset(&acf, 0, sizeof(acf));
224
225         /* FIXME: we can't use multiple slots at this point, since the RC632
226          * with librfid on the host PC has too much latency between 'EOF pulse
227          * to mark start of next slot' and 'receive data' commands :( */
228
229         flags = RFID_15693_F_INV_TABLE_5;
230         if (handle->priv.iso15693.vicc_fast)
231                 flags |= RFID_15693_F_RATE_HIGH;
232         if (handle->priv.iso15693.vicc_two_subc)
233                 flags |= RFID_15693_F_SUBC_TWO;
234         if (handle->priv.iso15693.single_slot) {
235                 flags |= RFID_15693_F5_NSLOTS_1;
236                 num_slots = 1;
237         }
238         if (handle->priv.iso15693.use_afi)
239                 flags |= RFID_15693_F5_AFI_PRES;
240 #if 1
241         tx_len = iso15693_build_acf((u_int8_t *)&acf, flags,
242                                     handle->priv.iso15693.afi, 0, NULL);
243 #else
244         /*FIXME: testcode*/
245         u_int8_t uid[8]={0x1f, 0x1e, 0x95, 0x01, 0x00, 0x01, 0x04, 0xe0};
246         //u_int8_t uid[8]={0xe3, 0xe8, 0xf1, 0x01, 0x00, 0x00, 0x07, 0xe0};
247         tx_len = iso15693_build_acf((u_int8_t *)&acf, flags,
248                                     handle->priv.iso15693.afi, 2, uid);
249 #endif
250 start_of_ac_loop:
251         for (i = 0; i < num_slots; i++) {
252                 rx_len = sizeof(resp);
253                 memset(&resp, 0, rx_len);
254                 ret = iso15693_transceive_acf(handle, (u_int8_t *) &acf, tx_len, &resp, &rx_len, &boc);
255
256                 if (ret == -ETIMEDOUT) {
257                         //DEBUGP("no answer from vicc in slot %d\n", i);
258                         DEBUGP("slot[%d]: timeout\n",i);
259                         uuid_list_valid[i] = MY_NONE;
260                 } else if (ret < 0) {
261                         DEBUGP("slot[%d]: ERROR ret: %d\n", i, ret);
262                         uuid_list_valid[i] = MY_NONE;
263                 } else {
264                         if (ret)
265                                 DEBUGP("iso15693_transceive_acf() ret: %d\n",ret);
266                         if (boc) {
267                                 DEBUGP("slot[%d]: Collision! bit:%d byte:%d,%d (UID bit:%d byte:%d,%d)\n",
268                                         i, boc,boc/8,boc%8,
269                                         boc-16,(boc-16)/8,(boc-16)%8);
270                                 DEBUGP("Slot[%d]: ret: %d DSFID: %02x UUID: %s\n", i, ret,
271                                         resp.dsfid, rfid_hexdump(resp.uuid, ISO15693_UID_LEN));
272
273                                 uuid_list_valid[i]=-boc;
274                                 memcpy(uuid_list[i], resp.uuid, ISO15693_UID_LEN);
275                         } else {
276                                 DEBUGP("Slot[%d]: ret: %d DSFID: %02x UUID: %s\n", i, ret,
277                                         resp.dsfid, rfid_hexdump(resp.uuid, ISO15693_UID_LEN));
278                                 uuid_list_valid[i] = MY_UUID;
279                                 memcpy(&uuid_list[i][0], resp.uuid, ISO15693_UID_LEN);
280
281                                 memcpy(handle->uid,resp.uuid, ISO15693_UID_LEN);
282                                 /* FIXME: move to init_iso15693 */
283                                 handle->uid_len = ISO15693_UID_LEN;
284                                 return 1;
285                         }
286                 }
287         }
288
289
290         for (i = 0; i < num_slots; i++) {
291                 if (uuid_list_valid[i] < 0) {
292                         boc=uuid_list_valid[i]*-1;
293                         if (boc>16){
294                                 boc=boc-16;
295                         }
296                         else
297                                 DEBUGP("slot[%d]:boc is smaller than 2 bytes (collision before uid)!!!!\n",i);
298
299                         if (boc<65){
300                                 tx_len = iso15693_build_acf((u_int8_t *)&acf, flags,
301                                     handle->priv.iso15693.afi, boc+1,  resp.uuid);
302                                 boc=0;
303                                 // FIXME: dont use goto
304                                 goto start_of_ac_loop;
305                         }else{
306                                 DEBUGP("slot[%d]:boc is bigger than 64 (uid size)(collision after uid)\n",i);
307                                 memcpy(handle->uid,uuid_list[i],ISO15693_UID_LEN);
308
309                                 /* FIXME: move to init_iso15693 */
310                                 handle->uid_len = ISO15693_UID_LEN;
311                                 return 1;
312                         }
313                 }
314         }
315 #if 0
316         for (i = 0; i < num_slots; i++) {
317                 if (uuid_list_valid[i] == MY_NONE) {
318                         DEBUGP("slot[%d]: timeout\n",i);
319                 } else if (uuid_list_valid[i] == MY_UUID) {
320                         DEBUGP("slot[%d]: VALID uuid: %s\n", i,
321                                 rfid_hexdump(uuid_list[i], ISO15693_UID_LEN));
322                         memcpy(handle->uid, uuid_list[i], ISO15693_UID_LEN);
323                         /* FIXME: move to init_iso15693 */
324                         handle->uid_len = ISO15693_UID_LEN;
325                         num_valid++;
326                 } else if (uuid_list_valid[i] < 0) {
327                                 if (boc>16){
328                                         boc=boc-16;
329                                 }
330                                 else
331                                         DEBUGP("boc is smaller than 2 bytes (collision before uid)!!!!\n");
332
333                                 uuid_list_valid[i] = -boc;
334                                 if (boc<65){
335                                         tx_len = iso15693_build_acf((u_int8_t *)&acf, flags,
336                                             handle->priv.iso15693.afi, boc+1,  resp.uuid);
337                                         boc=0;
338                                         // FIXME: dont use goto
339                                         goto start_of_ac_loop;
340                                 }else{
341                                         DEBUGP("boc is bigger than 64 (uid size)\n");
342                                         uuid_list_valid[i] = MY_UUID;
343                                 }
344                 }
345         }
346 #endif
347         if (num_valid == 0)
348                 return -1;
349
350         return num_valid;
351 }
352
353 static int
354 iso15693_select(struct rfid_layer2_handle *l2h)
355 {
356         struct iso15693_request_adressed tx_req;
357         int ret;
358         unsigned int rx_len, tx_len;
359
360         struct {
361                 struct iso15693_response head;
362                 u_int8_t error;
363                 unsigned char crc[2];
364         } rx_buf;
365         rx_len = sizeof(rx_buf);
366
367         tx_req.head.command = ISO15693_CMD_SELECT;
368         tx_req.head.flags = RFID_15693_F4_ADDRESS;
369         if (l2h->priv.iso15693.vicc_fast)
370                 tx_req.head.flags |= RFID_15693_F_RATE_HIGH;
371         if (l2h->priv.iso15693.vicc_two_subc)
372                 tx_req.head.flags |= RFID_15693_F_SUBC_TWO;
373         memcpy(&tx_req.uid, l2h->uid, ISO15693_UID_LEN);
374         tx_len = sizeof(tx_req);
375
376         DEBUGP("tx_len=%u", tx_len); DEBUGPC(" rx_len=%u\n",rx_len);
377
378         DEBUGP("ret: %d%s, error_flag: %d", ret,(ret==-ETIMEDOUT)?"(TIMEOUT)":"",
379                         rx_buf.head.flags&RFID_15693_RF_ERROR);
380         if (rx_buf.head.flags&RFID_15693_RF_ERROR){
381                 DEBUGPC(" -> error: %02x '%s'\n", rx_buf.error,
382                         iso15693_get_response_error_name(rx_buf.error));
383                 l2h->priv.iso15693.state = RFID_15693_STATE_SELECTED;
384                 return 0;
385         }else{
386                 DEBUGPC("\n");
387                 return -1;
388         }
389 }
390
391 static int
392 iso15693_stay_quiet(struct rfid_layer2_handle *l2h)
393 {
394         struct iso15693_request_adressed tx_req;
395         int ret;
396         unsigned int rx_len, tx_len;
397
398         struct {
399                 struct iso15693_response head;
400                 u_int8_t error;
401                 unsigned char crc[2];
402         } rx_buf;
403         rx_len = sizeof(rx_buf);
404
405         tx_req.head.command = ISO15693_CMD_STAY_QUIET;
406
407         tx_req.head.flags = RFID_15693_F4_ADDRESS;
408         if (l2h->priv.iso15693.vicc_fast)
409                 tx_req.head.flags |= RFID_15693_F_RATE_HIGH;
410         if (l2h->priv.iso15693.vicc_two_subc)
411                 tx_req.head.flags |= RFID_15693_F_SUBC_TWO;
412         memcpy(&tx_req.uid, l2h->uid, ISO15693_UID_LEN);
413         tx_len = sizeof(tx_req);
414
415         DEBUGP("tx_len=%u", tx_len); DEBUGPC(" rx_len=%u\n",rx_len);
416
417         ret = iso15693_transceive(l2h, RFID_15693_FRAME, (u_int8_t*)&tx_req,
418                                   tx_len, (u_int8_t*)&rx_buf, &rx_len, 30,0);
419
420         l2h->priv.iso15693.state = RFID_15693_STATE_QUIET;
421
422         DEBUGP("ret: %d%s, error_flag: %d", ret,(ret==-ETIMEDOUT)?"(TIMEOUT)":"",
423                         rx_buf.head.flags&RFID_15693_RF_ERROR);
424         if (rx_buf.head.flags&RFID_15693_RF_ERROR)
425                 DEBUGPC(" -> error: %02x\n", rx_buf.error);
426         else
427                 DEBUGPC("\n");
428
429         return 0;
430 }
431
432 static int
433 iso15693_getopt(struct rfid_layer2_handle *handle,
434                 int optname, void *optval, unsigned int *optlen)
435 {
436         unsigned int *val = optval;
437         u_int8_t *val_u8 = optval;
438
439         if (!optlen || !optval || *optlen < sizeof(unsigned int))
440                 return -EINVAL;
441         
442         *optlen = sizeof(unsigned int);
443
444         switch (optname) {
445         case RFID_OPT_15693_MOD_DEPTH:
446                 if (handle->priv.iso15693.vcd_ask100)
447                         *val = RFID_15693_MOD_100ASK;
448                 else
449                         *val = RFID_15693_MOD_10ASK;
450                 break;
451         case RFID_OPT_15693_VCD_CODING:
452                 if (handle->priv.iso15693.vcd_out256)
453                         *val = RFID_15693_VCD_CODING_1OUT256;
454                 else
455                         *val = RFID_15693_VCD_CODING_1OUT4;
456                 break;
457         case RFID_OPT_15693_VICC_SUBC:
458                 if (handle->priv.iso15693.vicc_two_subc)
459                         *val = RFID_15693_VICC_SUBC_DUAL;
460                 else
461                         *val = RFID_15693_VICC_SUBC_SINGLE;
462                 break;
463         case RFID_OPT_15693_VICC_SPEED:
464                 if (handle->priv.iso15693.vicc_fast)
465                         *val = RFID_15693_VICC_SPEED_FAST;
466                 else
467                         *val = RFID_15693_VICC_SPEED_SLOW;
468                 break;
469         case RFID_OPT_15693_VCD_SLOTS:
470                 if (handle->priv.iso15693.single_slot)
471                         *val = 1;
472                 else
473                         *val = 16;
474                 break;
475         case RFID_OPT_15693_USE_AFI:
476                 if (handle->priv.iso15693.use_afi)
477                         *val = 1;
478                 else
479                         *val = 0;
480                 break;
481         case RFID_OPT_15693_AFI:
482                 *val_u8 = handle->priv.iso15693.afi;
483                 *optlen = sizeof(u_int8_t);
484                 break;
485         default:
486                 return -EINVAL;
487                 break;
488         }
489
490         return 0;
491 }
492
493 static int
494 iso15693_setopt(struct rfid_layer2_handle *handle, int optname,
495                 const void *optval, unsigned int optlen)
496 {
497         unsigned int val;
498         
499         if (optlen < sizeof(u_int8_t) || !optval)
500                 return -EINVAL;
501
502         if (optlen == sizeof(u_int8_t))
503                 val = *((u_int8_t *) optval);
504         if (optlen == sizeof(u_int16_t))
505                 val = *((u_int16_t *) optval);
506         if (optlen == sizeof(unsigned int))
507                 val = *((unsigned int *) optval);
508
509         switch (optname) {
510         case RFID_OPT_15693_MOD_DEPTH:
511                 switch (val) {
512                 case RFID_15693_MOD_10ASK:
513                         handle->priv.iso15693.vcd_ask100 = 0;
514                         break;
515                 case RFID_15693_MOD_100ASK:
516                         handle->priv.iso15693.vcd_ask100 = 1;
517                         break;
518                 default:
519                         return -EINVAL;
520                 }
521                 break;
522         case RFID_OPT_15693_VCD_CODING:
523                 switch (val) {
524                 case RFID_15693_VCD_CODING_1OUT256:
525                         handle->priv.iso15693.vcd_out256 = 1;
526                         break;
527                 case RFID_15693_VCD_CODING_1OUT4:
528                         handle->priv.iso15693.vcd_out256 = 0;
529                         break;
530                 default:
531                         return -EINVAL;
532                 }
533                 break;
534         case RFID_OPT_15693_VICC_SUBC:
535                 switch (val) {
536                 case RFID_15693_VICC_SUBC_SINGLE:
537                         handle->priv.iso15693.vicc_two_subc = 0;
538                         break;
539                 case RFID_15693_VICC_SUBC_DUAL:
540                         handle->priv.iso15693.vicc_two_subc = 1;
541                         break;
542                 default:
543                         return -EINVAL;
544                 }
545                 break;
546         case RFID_OPT_15693_VICC_SPEED:
547                 switch (val) {
548                 case RFID_15693_VICC_SPEED_SLOW:
549                         handle->priv.iso15693.vicc_fast = 0;
550                         break;
551                 case RFID_15693_VICC_SPEED_FAST:
552                         handle->priv.iso15693.vicc_fast = 1;
553                         break;
554                 default:
555                         return -EINVAL;
556                 }
557         case RFID_OPT_15693_VCD_SLOTS:
558                 switch (val) {
559                 case 16:
560                         handle->priv.iso15693.single_slot = 0;
561                         break;
562                 case 1:
563                         handle->priv.iso15693.single_slot = 1;
564                         break;
565                 default:
566                         return -EINVAL;
567                 }
568                 break;
569         case RFID_OPT_15693_USE_AFI:
570                 if (val)
571                         handle->priv.iso15693.use_afi = 1;
572                 else
573                         handle->priv.iso15693.use_afi = 0;
574                 break;
575         case RFID_OPT_15693_AFI:
576                 if (val > 0xff)
577                         return -EINVAL;
578                 handle->priv.iso15693.afi = val;
579                 break;
580         default:
581                 return -EINVAL;
582         }
583         return 0;
584 }
585
586 static int transceive_inventory(struct rfid_layer2_handle *l2h)
587 {
588         return -1;
589 }
590
591 static struct rfid_layer2_handle *
592 iso15693_init(struct rfid_reader_handle *rh)
593 {
594         int ret;
595         struct rfid_layer2_handle *h = malloc_layer2_handle(sizeof(*h));
596         if (!h)
597                 return NULL;
598
599         h->l2 = &rfid_layer2_iso15693;
600         h->rh = rh;
601         h->priv.iso15693.state = ISO15693_STATE_NONE;
602         h->priv.iso15693.vcd_ask100 = 1; /* 100ASK is easier to generate */
603         h->priv.iso15693.vicc_two_subc = 0;
604         h->priv.iso15693.vicc_fast = 1;
605         h->priv.iso15693.single_slot = 1;
606         h->priv.iso15693.vcd_out256 = 0;
607         h->priv.iso15693.use_afi = 0;   /* not all VICC support AFI */
608         h->priv.iso15693.afi = 0;
609
610         ret = h->rh->reader->init(h->rh, RFID_LAYER2_ISO15693);
611         if (ret < 0) {
612                 free_layer2_handle(h);
613                 return NULL;
614         }
615
616         return h;
617 }
618
619 static int
620 iso15693_fini(struct rfid_layer2_handle *handle)
621 {
622         free_layer2_handle(handle);
623         return 0;
624 }
625
626
627 const struct rfid_layer2 rfid_layer2_iso15693 = {
628         .id     = RFID_LAYER2_ISO15693,
629         .name   = "ISO 15693",
630         .fn     = {
631                 .init           = &iso15693_init,
632                 .open           = &iso15693_anticol,
633                 //.open         = &iso15693_select,
634                 //.transceive   = &iso15693_transceive,
635                 .close          = &iso15693_stay_quiet,
636                 .fini           = &iso15693_fini,
637                 .setopt         = &iso15693_setopt,
638                 .getopt         = &iso15693_getopt,
639         },
640 };
641