libnfc  1.4.2
pn533_usb.c
Go to the documentation of this file.
1 /*-
2  * Public platform independent Near Field Communication (NFC) library
3  *
4  * Copyright (C) 2009, Roel Verdult
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>
18  */
19 
25 /*
26 Thanks to d18c7db and Okko for example code
27 */
28 
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif // HAVE_CONFIG_H
32 
33 #include <stdlib.h>
34 
35 #include "../drivers.h"
36 #include <nfc/nfc-messages.h>
37 
39 pn533_usb_pick_device (void)
40 {
41  nfc_device_desc_t *pndd;
42 
43  if ((pndd = malloc (sizeof (*pndd)))) {
44  size_t szN;
45 
46  if (!pn533_usb_list_devices (pndd, 1, &szN)) {
47  DBG ("%s", "pn533_usb_list_devices failed");
48  free (pndd);
49  return NULL;
50  }
51 
52  if (szN == 0) {
53  DBG ("%s", "No device found");
54  free (pndd);
55  return NULL;
56  }
57  }
58 
59  return pndd;
60 }
61 
62 bool
63 pn533_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound)
64 {
65  // array of {vendor,product} pairs for USB devices
66  usb_candidate_t candidates[] = {
67  { 0x04CC, 0x2533 }, // NXP - PN533
68  { 0x04E6, 0x5591 }, // SCM Micro - SCL3711-NFC&RW
69  { 0x1FD3, 0x0608 } // ASK - LoGO
70  };
71 
72  return pn53x_usb_list_devices (&pnddDevices[0], szDevices, pszDeviceFound, &candidates[0],
73  sizeof (candidates) / sizeof (usb_candidate_t), PN533_USB_DRIVER_NAME);
74 }
75 
77 pn533_usb_connect (const nfc_device_desc_t * pndd)
78 {
79  return pn53x_usb_connect (pndd, pndd->acDevice, NC_PN533);
80 }
81 
82 void
83 pn533_usb_init (nfc_device_t * pnd)
84 {
85  usb_spec_t* pus = (usb_spec_t*) pnd->nds;
86  DBG ("pus->uc.idVendor == 0x%04x, pus->uc.idProduct == 0x%04x", pus->uc.idVendor, pus->uc.idProduct);
87  if ((pus->uc.idVendor == 0x1FD3) && (pus->uc.idProduct == 0x0608)) { // ASK - LoGO
88  DBG ("ASK LoGO initialization.");
89  pn53x_set_reg (pnd, 0x6106, 0xFF, 0x1B);
90  pn53x_set_reg (pnd, 0x6306, 0xFF, 0x14);
91  pn53x_set_reg (pnd, 0xFFFD, 0xFF, 0x37);
92  pn53x_set_reg (pnd, 0xFFB0, 0xFF, 0x3B);
93  }
94 }
95