FreeCalypso > hg > fc-usbser-tools
annotate libuwrap/open_close.c @ 106:de3b299561b3
udev: add rules file that works on my system
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Oct 2023 01:08:28 +0000 |
parents | 80e521d6609c |
children |
rev | line source |
---|---|
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement functions for opening and closing the libusb device |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * we have located. |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <usb.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "open_close.h" |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 usb_dev_handle *usbwrap_open_dev(struct usb_device *dev, int detach) |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 usb_dev_handle *usbh; |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 usbh = usb_open(dev); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (!usbh) { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fprintf(stderr, "error: usb_open() failed\n"); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 exit(1); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (detach) |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 usb_detach_kernel_driver_np(usbh, 0); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (usb_claim_interface(usbh, 0) != 0) { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fprintf(stderr, "error: usb_claim_interface() failed\n"); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return usbh; |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 void usbwrap_close_dev(usb_dev_handle *usbh) |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 usb_release_interface(usbh, 0); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 usb_close(usbh); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |