diff libuwrap/claim_if.c @ 40:f5847be43d35

fc-duart28-conf: bump off both ttyUSB devices on set operation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 10 Sep 2023 21:13:58 +0000
parents libuwrap/open_close.c@80e521d6609c
children 5160f6717903
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libuwrap/claim_if.c	Sun Sep 10 21:13:58 2023 +0000
@@ -0,0 +1,23 @@
+/*
+ * When we are reprogramming the EEPROM on DUART28 or possibly other devices
+ * in the future where we know that we are operating on a multichannel FTDI
+ * chip (or perhaps a multichannel chip from some other vendor), it is most
+ * philosophically correct to bump off ftdi_sio from both interfaces,
+ * removing both ttyUSB devices.  Here we implement a function for claiming
+ * one interface, easily callable for multiple interfaces in a row.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <usb.h>
+#include "open_close.h"
+
+void usbwrap_claim_interface(usb_dev_handle *usbh, int ifnum, int detach)
+{
+	if (detach)
+		usb_detach_kernel_driver_np(usbh, ifnum);
+	if (usb_claim_interface(usbh, ifnum) != 0) {
+		fprintf(stderr, "error: usb_claim_interface() failed\n");
+		exit(1);
+	}
+}