FreeCalypso > hg > fc-usbser-tools
annotate libuwrap/open_close.c @ 105:1e820ed0904e
Installed-binaries: list of binaries installed by this package
I am establishing a new convention for all FreeCalypso tools, across
different packages and source repositories: each FC tools package
will have a file name Installed-binaries listing all user-invokable
binaries that package installs in /opt/freecalypso/bin. These files
are to serve as an aid to users and distro package maintainers who
prefer to not add /opt/freecalypso/bin to their PATH. The alternative
to adding this directory to PATH is to create a symlink for every
installed binary in some standard location such as /usr/bin or
/usr/local/bin, pointing to the actual binary in /opt/freecalypso/bin;
having a list of all FC-installed binaries in a standardized format
will allow this process to be automated.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 29 Sep 2023 19:42:53 +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 } |