in this thread is discussed a similar problem: Error message 'Interface not claimed' from libusb
here follows a copy
Just had the same problem with libusb-1.0; I originally had this sequence:
libusb_init
libusb_open_device_with_vid_pid
libusb_reset_device
libusb_get_device
libusb_reset_device
libusb_set_configuration
libusb_claim_interface
libusb_set_interface_alt_setting
libusb_get_device_descriptor
libusb_get_bus_number
libusb_get_device_address
libusb_get_string_descriptor_ascii
if(libusb_kernel_driver_active.. )
if(libusb_detach_kernel_driver.. )
libusb_bulk_transfer
...
... and for it, the "interface not claimed" was generated when the first libusb_bulk_transfer executed (but not subsequent ones, not shown above), which I confirmed by stepping in gdb. (btw, that error message comes from /linux/drivers/usb/core/devio.c)
This page: USB Hid Issue · Yubico/yubikey-personalization Wiki · GitHub refers to a fix for libusb-0.1 which called the corresponding "detach_driver" function; so I started moving the "detach_driver" part around in my code too - and finally this sequence seems to get rid of the "interface not claimed" message:
libusb_init
libusb_open_device_with_vid_pid
if(libusb_kernel_driver_active.. )
if(libusb_detach_kernel_driver.. )
libusb_reset_device
libusb_get_device
libusb_set_configuration
libusb_claim_interface
libusb_set_interface_alt_setting
libusb_get_device_descriptor
libusb_get_bus_number
libusb_get_device_address
libusb_get_string_descriptor_ascii
libusb_bulk_transfer
...
Apparently, if the driver is first detached, and then interface is claimed - then no errors are generated. But that is also what you have in OP there - so I think, the trick for OP would be to have detach, then set configuration, and after that claim interface...