FreeCalypso > hg > fc-usbser-tools
comparison libuwrap/open_close.c @ 12:80e521d6609c
libuwrap: implement USB device open and close
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Sep 2023 06:39:49 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:fe4231326fb2 | 12:80e521d6609c |
---|---|
1 /* | |
2 * Here we implement functions for opening and closing the libusb device | |
3 * we have located. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <usb.h> | |
9 #include "open_close.h" | |
10 | |
11 usb_dev_handle *usbwrap_open_dev(struct usb_device *dev, int detach) | |
12 { | |
13 usb_dev_handle *usbh; | |
14 | |
15 usbh = usb_open(dev); | |
16 if (!usbh) { | |
17 fprintf(stderr, "error: usb_open() failed\n"); | |
18 exit(1); | |
19 } | |
20 if (detach) | |
21 usb_detach_kernel_driver_np(usbh, 0); | |
22 if (usb_claim_interface(usbh, 0) != 0) { | |
23 fprintf(stderr, "error: usb_claim_interface() failed\n"); | |
24 exit(1); | |
25 } | |
26 return usbh; | |
27 } | |
28 | |
29 void usbwrap_close_dev(usb_dev_handle *usbh) | |
30 { | |
31 usb_release_interface(usbh, 0); | |
32 usb_close(usbh); | |
33 } |