Re: [nfc-tools] r1072 committed - ifdnfc> Allow PCSC to directly call ifdnfc for all usb readers support...

28 views
Skip to first unread message

Ludovic Rousseau

unread,
Jun 6, 2012, 3:58:39 AM6/6/12
to nfc-...@googlegroups.com
2012/6/6 <nfc-...@googlecode.com>:
> Revision: 1072
> Author:   yobibe
> Date:     Tue Jun  5 18:37:02 2012
> Log:      ifdnfc> Allow PCSC to directly call ifdnfc for all usb readers
> supported by libnfc

That was the missing patch.


> =======================================
> --- /trunk/ifdnfc/src/ifd-nfc.c Tue Jun  5 15:24:32 2012
> +++ /trunk/ifdnfc/src/ifd-nfc.c Tue Jun  5 18:37:02 2012
> @@ -223,7 +223,39 @@
>   ifdnfc.slot.present = false;
>   nfc_init(NULL);
>
> -  Log2(PCSC_LOG_DEBUG, "\"DEVICENAME    %s\" is not used.", DeviceName);
> +  // USB DeviceNames can be immediately handled, e.g.:
> +  // usb:1fd3/0608:libudev:0:/dev/bus/usb/002/079
> +  // => connstring usb:002:079
> +  int n = strlen(DeviceName) + 1;
> +  char *vidpid      = malloc(n);
> +  char *hpdriver    = malloc(n);
> +  char *ifn         = malloc(n);
> +  char *devpath     = malloc(n);
> +  char *dirname     = malloc(n);
> +  char *filename    = malloc(n);
> +
> +  int res = sscanf(DeviceName, "usb:%[^:]:%[^:]:%[^:]:%[^:]", vidpid,
> hpdriver, ifn, devpath);
> +  if (res == 4) {
> +    int res = sscanf(devpath, "/dev/bus/usb/%[^/]/%[^/]", dirname,
> filename);
> +    if (res == 2) {
> +      strcpy(ifd_connstring, "usb:xxx:xxx");
> +      memcpy(ifd_connstring + 4, dirname, 3);
> +      memcpy(ifd_connstring + 8, filename, 3);

I would suggest to replace the 3 above lines with:
snprintf(ifd_connstring, sizeof ifd_connstring, "usb:%s:%s", dirname, filename);

No more magic index numbers.

Bye

--
 Dr. Ludovic Rousseau
Reply all
Reply to author
Forward
0 new messages