# HG changeset patch # User Mychaela Falconia # Date 1694068789 0 # Node ID 80e521d6609cd7b8e51a6617ab1a71ea1e03d7a4 # Parent fe4231326fb2c3ac1a12d99a61529d9ff21bd6b8 libuwrap: implement USB device open and close diff -r fe4231326fb2 -r 80e521d6609c libuwrap/Makefile --- a/libuwrap/Makefile Thu Sep 07 04:58:16 2023 +0000 +++ b/libuwrap/Makefile Thu Sep 07 06:39:49 2023 +0000 @@ -1,6 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= find_busdev.o find_desc_str.o find_matchspec.o prelim_init.o +OBJS= find_busdev.o find_desc_str.o find_matchspec.o open_close.o \ + prelim_init.o LIB= libuwrap.a all: ${LIB} diff -r fe4231326fb2 -r 80e521d6609c libuwrap/open_close.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libuwrap/open_close.c Thu Sep 07 06:39:49 2023 +0000 @@ -0,0 +1,33 @@ +/* + * Here we implement functions for opening and closing the libusb device + * we have located. + */ + +#include +#include +#include +#include "open_close.h" + +usb_dev_handle *usbwrap_open_dev(struct usb_device *dev, int detach) +{ + usb_dev_handle *usbh; + + usbh = usb_open(dev); + if (!usbh) { + fprintf(stderr, "error: usb_open() failed\n"); + exit(1); + } + if (detach) + usb_detach_kernel_driver_np(usbh, 0); + if (usb_claim_interface(usbh, 0) != 0) { + fprintf(stderr, "error: usb_claim_interface() failed\n"); + exit(1); + } + return usbh; +} + +void usbwrap_close_dev(usb_dev_handle *usbh) +{ + usb_release_interface(usbh, 0); + usb_close(usbh); +} diff -r fe4231326fb2 -r 80e521d6609c libuwrap/open_close.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libuwrap/open_close.h Thu Sep 07 06:39:49 2023 +0000 @@ -0,0 +1,2 @@ +extern usb_dev_handle *usbwrap_open_dev(struct usb_device *dev, int detach); +extern void usbwrap_close_dev(usb_dev_handle *usbh);