[Aranym-dev] [PATCH] USB NF. Inform guest OS about device disconnected when getting new list

David Gálvez dgalvez75 at gmail.com
Thu Feb 5 21:05:53 CET 2015


Please commit this patch for Aranym's USB Native Feature.

Thanks!

Commit message:

When a new USB device list is requested libusb disconnects all devices.
We need to inform the guest OS about it.
Use the function usbhost_release_device() to do it.
-------------- next part --------------
diff --git a/src/natfeat/usbhost.cpp b/src/natfeat/usbhost.cpp
index 53ecf9e..2a9e507 100644
--- a/src/natfeat/usbhost.cpp
+++ b/src/natfeat/usbhost.cpp
@@ -283,13 +283,43 @@ try_another:
 }
 
 
+int usbhost_release_device(int virtdev_index)
+{
+	D(bug("USBHost: release_device() %d", virtdev_index));
+
+	int r;
+	int dev_index, int_index;
+	int port_number;
+
+	dev_index = virtual_device[virtdev_index].idx_dev;
+	int_index = virtual_device[virtdev_index].idx_interface;
+
+	r = libusb_release_interface(devh[dev_index], int_index);
+	if (r < 0) {
+		D(bug("USBHost: Releasing interface failed"));
+		return -1;
+ 	}
+
+	virtual_device[virtdev_index].connected = false;
+	port_number = virtual_device[virtdev_index].port_number;
+
+	roothub.port[port_number].busy = false;
+	fill_port_status(port_number, virtual_device[virtdev_index].connected);
+
+	if ((--number_ports_used < NUMBER_OF_PORTS))
+		enable_buttons();
+
+	return r;
+}
+
+
 void usbhost_free_usb_devices(void)
 {
 	int i = 0;
 
 	while (devs[i] != NULL) {
 		if (virtual_device[i].connected)
-			libusb_release_interface(devh[i], virtual_device[i].idx_interface);
+			usbhost_release_device(i);
 
 		libusb_close(devh[i]);
 		devh[i] = NULL;
@@ -354,36 +384,6 @@ claim:	r = libusb_claim_interface(devh[dev_index], int_index);
 }
 
 
-int usbhost_release_device(int virtdev_index)
-{
-	D(bug("USBHost: release_device() %d", virtdev_index));
-
-	int r;
-	int dev_index, int_index;
-	int port_number;
-
-	dev_index = virtual_device[virtdev_index].idx_dev;
-	int_index = virtual_device[virtdev_index].idx_interface;
-
-	r = libusb_release_interface(devh[dev_index], int_index);
-	if (r < 0) {
-		D(bug("USBHost: Releasing interface failed"));
-		return -1;
- 	}
-
-	virtual_device[virtdev_index].connected = false;
-	port_number = virtual_device[virtdev_index].port_number;
-
-	roothub.port[port_number].busy = false;
-	fill_port_status(port_number, virtual_device[virtdev_index].connected);
-
-	if ((--number_ports_used < NUMBER_OF_PORTS))
-		enable_buttons();
-
-	return r;
-}
-
-
 void print_devs(libusb_device **devs)
 {
 	libusb_device *dev;


More information about the cz-bobek-lists-aranym mailing list