libnfc  1.4.2
pn531_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 pn531_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 (!pn531_usb_list_devices (pndd, 1, &szN)) {
47  DBG ("%s", "pn531_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  return pndd;
59 }
60 
61 bool
62 pn531_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound)
63 {
64  // array of {vendor,product} pairs for USB devices
65  usb_candidate_t candidates[] = { {0x04CC, 0x0531}
66  , {0x054c, 0x0193}
67  };
68 
69  return pn53x_usb_list_devices (&pnddDevices[0], szDevices, pszDeviceFound, &candidates[0],
70  sizeof (candidates) / sizeof (usb_candidate_t), PN531_USB_DRIVER_NAME);
71 }
72 
74 pn531_usb_connect (const nfc_device_desc_t * pndd)
75 {
76  return pn53x_usb_connect (pndd, pndd->acDevice, NC_PN531);
77 }