pn533_usb.c

Go to the documentation of this file.
00001 /*-
00002  * Public platform independent Near Field Communication (NFC) library
00003  * 
00004  * Copyright (C) 2009, Roel Verdult
00005  * 
00006  * This program is free software: you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation, either version 3 of the License, or (at your
00009  * option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014  * more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00025 /*
00026 Thanks to d18c7db and Okko for example code
00027 */
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include "config.h"
00031 #endif // HAVE_CONFIG_H
00032 
00033 #include <stdlib.h>
00034 
00035 #include "../drivers.h"
00036 #include <nfc/nfc-messages.h>
00037 
00038 nfc_device_desc_t *
00039 pn533_usb_pick_device (void)
00040 {
00041   nfc_device_desc_t *pndd;
00042 
00043   if ((pndd = malloc (sizeof (*pndd)))) {
00044     size_t  szN;
00045 
00046     if (!pn533_usb_list_devices (pndd, 1, &szN)) {
00047       DBG ("%s", "pn533_usb_list_devices failed");
00048       return NULL;
00049     }
00050 
00051     if (szN == 0) {
00052       DBG ("%s", "No device found");
00053       return NULL;
00054     }
00055   }
00056 
00057   return pndd;
00058 }
00059 
00060 bool
00061 pn533_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound)
00062 {
00063   // array of {vendor,product} pairs for USB devices
00064   usb_candidate_t candidates[] = { {0x04CC, 0x2533}
00065   , {0x04E6, 0x5591}
00066   };
00067 
00068   return pn53x_usb_list_devices (&pnddDevices[0], szDevices, pszDeviceFound, &candidates[0],
00069                                  sizeof (candidates) / sizeof (usb_candidate_t), PN533_USB_DRIVER_NAME);
00070 }
00071 
00072 nfc_device_t *
00073 pn533_usb_connect (const nfc_device_desc_t * pndd)
00074 {
00075   return pn53x_usb_connect (pndd, pndd->acDevice, NC_PN533);
00076 }