Op Vr, 16 mei, 2008 23:37, schreef Alon Bar-Lev: > I guess this for OpenCT, right? > Can you please send all the needed patches to make it work? > Also, please don't use asprintf, as it is gnu specific and is not used > in other parts of the sources.
Thank you for your reply. The patch is indeed for OpenCT. I merged both patches and replaced the asprintf() with a snprintf(). I also fixed the evil sprintf() at line 66. I tested it with OpenBSD 4.3 and FreeBSD 7.0 and a OmniKey CardMan 3121 CCID device. Best regards, David diff -urN ../openct-0.6.14.orig/src/ifd/sys-bsd.c ./src/ifd/sys-bsd.c --- ../openct-0.6.14.orig/src/ifd/sys-bsd.c 2008-05-19 14:42:57.000000000 +0000 +++ ./src/ifd/sys-bsd.c 2008-05-19 16:05:47.000000000 +0000 @@ -13,7 +13,11 @@ #include "internal.h" #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #include <sys/types.h> +#if defined(__DragonFly__) +#include <bus/usb/usb.h> +#else #include <dev/usb/usb.h> +#endif #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/poll.h> @@ -63,7 +67,11 @@ return 0; } - sprintf((char *)&filename, "%s.%d", name, endpoint); +#ifdef __OpenBSD__ + snprintf(filename, sizeof(filename), "%s.%.2d", name, endpoint); +#else + snprintf(filename, sizeof(filename), "%s.%d", name, endpoint); +#endif /* __OpenBSD__ */ if ((interfaces[interface][endpoint].ep_fd = open(filename, flags)) < 0) { ifd_debug(6, "open_ep: error opening \"%s\": %s", filename, @@ -91,14 +99,22 @@ int direction = (ep & IFD_USB_ENDPOINT_DIR_MASK) == IFD_USB_ENDPOINT_IN ? 1 : 0; int endpoint = (ep & ~IFD_USB_ENDPOINT_DIR_MASK); + int one = 1; ct_debug("ifd_sysdep_usb_bulk: endpoint=%d direction=%d", endpoint, direction); - if (open_ep(dev->name, 0, endpoint, O_RDWR | O_NONBLOCK)) { - ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); - return -1; - } if (direction) { + if (open_ep(dev->name, 0, endpoint, O_RDONLY | O_NONBLOCK)) { + ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); + return -1; + } + + if (ioctl(interfaces[0][endpoint].ep_fd, USB_SET_SHORT_XFER, + &one) < 0) { + ifd_debug(6, "ifd_sysdep_usb_bulk: USB_SET_SHORT_XFER" + " failed: %s", strerror(errno)); + ct_error("usb_bulk read failed: %s", strerror(errno)); + } if ((bytes_to_process = read(interfaces[0][endpoint].ep_fd, buffer, len)) < 0) { ifd_debug(6, "ifd_sysdep_usb_bulk: read failed: %s", @@ -110,6 +126,11 @@ bytes_to_process); return bytes_to_process; } else { + if (open_ep(dev->name, 0, endpoint, O_WRONLY | O_NONBLOCK)) { + ct_debug("ifd_sysdep_usb_bulk: opening endpoint failed"); + return -1; + } + bytes_to_process = len; if ((bytes_processed = write(interfaces[0][endpoint].ep_fd, buffer, @@ -314,7 +335,15 @@ int ifd_sysdep_usb_open(const char *device) { +#ifdef __OpenBSD__ + char path[256]; + + if (snprintf(&path, sizeof(path), "%s.00", device) < 0) + return -1; + return open(path, O_RDWR); +#else return open(device, O_RDWR); +#endif /* __OpenBSD__ */ } int ifd_sysdep_usb_reset(ifd_device_t * dev) @@ -384,13 +413,8 @@ if (!(driver = ifd_driver_for_id(&id))) continue; -#ifdef __OpenBSD__ - snprintf(typedev, sizeof(typedev), - "usb:/dev/%s.00", device_info.udi_devnames[0]); -#else snprintf(typedev, sizeof(typedev), "usb:/dev/%s", device_info.udi_devnames[0]); -#endif /* __OpenBSD__ */ ifd_spawn_handler(driver, typedev, -1); } _______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel