view libuwrap/claim_if.c @ 48:9cfe3223fbf8

doc/FTDI-EEPROM-tools: document -d options
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Sep 2023 03:58:41 +0000
parents 5160f6717903
children 5cbde3c80c24
line wrap: on
line source

/*
 * The operation of programming an FTDI EEPROM *can* be done without ever
 * claiming any of the chip's interfaces and without unbinding ttyUSB from
 * any channel, even if we are doing the special magic sequence for FT232R.
 * However, given the identity-altering nature of EEPROM programming it is
 * generally a good idea to claim all interfaces and unbind all ttyUSB
 * devices, and in the case of FT232R the magic sequence breaks normal
 * UART operation.
 *
 * This library module provides building block functions: a function for
 * claiming one interface and a higher-level function claiming all interfaces
 * of a multichannel device.
 */

#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);
	}
}

void usbwrap_claim_all_ifs(usb_dev_handle *usbh, unsigned nchannels)
{
	unsigned n;

	for (n = 0; n < nchannels; n++)
		usbwrap_claim_interface(usbh, n, 1);
}