FreeCalypso > hg > fc-usbser-tools
annotate libuwrap/claim_if.c @ 65:225dc1d9f2f1
ftee-decode program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 12 Sep 2023 22:23:30 +0000 |
parents | 5160f6717903 |
children | 5cbde3c80c24 |
rev | line source |
---|---|
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
2 * The operation of programming an FTDI EEPROM *can* be done without ever |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
3 * claiming any of the chip's interfaces and without unbinding ttyUSB from |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
4 * any channel, even if we are doing the special magic sequence for FT232R. |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
5 * However, given the identity-altering nature of EEPROM programming it is |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
6 * generally a good idea to claim all interfaces and unbind all ttyUSB |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
7 * devices, and in the case of FT232R the magic sequence breaks normal |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
8 * UART operation. |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
9 * |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
10 * This library module provides building block functions: a function for |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
11 * claiming one interface and a higher-level function claiming all interfaces |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
12 * of a multichannel device. |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 */ |
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 #include <stdio.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <stdlib.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <usb.h> |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "open_close.h" |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
40
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
20 void usbwrap_claim_interface(usb_dev_handle *usbh, int ifnum, int detach) |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (detach) |
40
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
23 usb_detach_kernel_driver_np(usbh, ifnum); |
f5847be43d35
fc-duart28-conf: bump off both ttyUSB devices on set operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
24 if (usb_claim_interface(usbh, ifnum) != 0) { |
12
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fprintf(stderr, "error: usb_claim_interface() failed\n"); |
80e521d6609c
libuwrap: implement USB device open and close
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
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 } |
44
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
29 |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
30 void usbwrap_claim_all_ifs(usb_dev_handle *usbh, unsigned nchannels) |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
31 { |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
32 unsigned n; |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
33 |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
34 for (n = 0; n < nchannels; n++) |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
35 usbwrap_claim_interface(usbh, n, 1); |
5160f6717903
libuwrap: implement function to claim/unbind all interfaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
36 } |