Haiku: Fix some issues in the backend
Since commit 8cfcc63f4f ("haiku_usb_raw: Add missing wrap_sys_device
field to usbi_os_backend"), compilation of the Haiku backend has been
broken. Since the code is C++, named initializers are not supported. Fix
this by going back to the original style of initializing
usbi_os_backend.
Additionally, commit db99ef3451 ("Various fixes for the Haiku port")
further broken some things. The ClearHalt() function was defined as a
member of the USBDevice class but is declared and needed as a member of
the USBDeviceHandle class. The ioctl command code also contained a typo.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
diff --git a/libusb/os/haiku_pollfs.cpp b/libusb/os/haiku_pollfs.cpp
index 90c795a..cb28c51 100644
--- a/libusb/os/haiku_pollfs.cpp
+++ b/libusb/os/haiku_pollfs.cpp
@@ -125,7 +125,7 @@
addr += tmp + 1;
parent_path.GetParent(&parent_path);
}
- sscanf(path.Path(), "/dev/bus/usb/%d", &dev->bus_number);
+ sscanf(path.Path(), "/dev/bus/usb/%hhu", &dev->bus_number);
dev->device_address = addr - (dev->bus_number + 1);
if (usbi_sanitize_device(dev) < 0) {
diff --git a/libusb/os/haiku_usb.h b/libusb/os/haiku_usb.h
index f15e58e..9a87859 100644
--- a/libusb/os/haiku_usb.h
+++ b/libusb/os/haiku_usb.h
@@ -38,22 +38,22 @@
const char* Location() const;
uint8 CountConfigurations() const;
const usb_device_descriptor* Descriptor() const;
- const usb_configuration_descriptor* ConfigurationDescriptor(uint32) const;
+ const usb_configuration_descriptor* ConfigurationDescriptor(uint8) const;
const usb_configuration_descriptor* ActiveConfiguration() const;
uint8 EndpointToIndex(uint8) const;
uint8 EndpointToInterface(uint8) const;
int ClaimInterface(int);
int ReleaseInterface(int);
- int CheckInterfacesFree(int);
- int SetActiveConfiguration(int);
- int ActiveConfigurationIndex() const;
+ int CheckInterfacesFree(uint8);
+ void SetActiveConfiguration(uint8);
+ uint8 ActiveConfigurationIndex() const;
bool InitCheck();
private:
int Initialise();
unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
usb_device_descriptor fDeviceDescriptor;
unsigned char** fConfigurationDescriptors;
- int fActiveConfiguration;
+ uint8 fActiveConfiguration;
char* fPath;
map<uint8,uint8> fConfigToIndex;
map<uint8,uint8>* fEndpointToIndex;
@@ -67,9 +67,9 @@
virtual ~USBDeviceHandle();
int ClaimInterface(int);
int ReleaseInterface(int);
- int SetConfiguration(int);
+ int SetConfiguration(uint8);
int SetAltSetting(int, int);
- int ClearHalt(int);
+ int ClearHalt(uint8);
status_t SubmitTransfer(struct usbi_transfer *);
status_t CancelTransfer(USBTransfer *);
bool InitCheck();
diff --git a/libusb/os/haiku_usb_backend.cpp b/libusb/os/haiku_usb_backend.cpp
index 6e59ded..9eda263 100644
--- a/libusb/os/haiku_usb_backend.cpp
+++ b/libusb/os/haiku_usb_backend.cpp
@@ -215,7 +215,7 @@
fTransfersLock.Lock();
bool removed = fTransfers.RemoveItem(transfer);
fTransfersLock.Unlock();
- if(removed)
+ if (removed)
usbi_signal_transfer_completion(transfer->UsbiTransfer());
return LIBUSB_SUCCESS;
}
@@ -242,7 +242,7 @@
{
if (fRawFD > 0)
close(fRawFD);
- for(int i = 0; i < 32; i++) {
+ for (int i = 0; i < 32; i++) {
if (fClaimedInterfaces & (1U << i))
ReleaseInterface(i);
}
@@ -269,10 +269,10 @@
}
int
-USBDeviceHandle::SetConfiguration(int config)
+USBDeviceHandle::SetConfiguration(uint8 config)
{
int config_index = fUSBDevice->CheckInterfacesFree(config);
- if(config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
+ if (config_index == LIBUSB_ERROR_BUSY || config_index == LIBUSB_ERROR_NOT_FOUND)
return config_index;
usb_raw_command command;
command.config.config_index = config_index;
@@ -280,7 +280,7 @@
command.config.status != B_USB_RAW_STATUS_SUCCESS) {
return _errno_to_libusb(command.config.status);
}
- fUSBDevice->SetActiveConfiguration(config_index);
+ fUSBDevice->SetActiveConfiguration((uint8)config_index);
return LIBUSB_SUCCESS;
}
@@ -309,9 +309,8 @@
return LIBUSB_SUCCESS;
}
-
int
-USBDevice::ClearHalt(int endpoint)
+USBDeviceHandle::ClearHalt(uint8 endpoint)
{
usb_raw_command command;
command.control.request_type = USB_REQTYPE_ENDPOINT_OUT;
@@ -324,6 +323,7 @@
command.control.status != B_USB_RAW_STATUS_SUCCESS) {
return _errno_to_libusb(command.control.status);
}
+ return LIBUSB_SUCCESS;
}
@@ -345,7 +345,7 @@
{
free(fPath);
if (fConfigurationDescriptors) {
- for(int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
+ for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
if (fConfigurationDescriptors[i])
delete fConfigurationDescriptors[i];
}
@@ -382,7 +382,7 @@
}
const usb_configuration_descriptor *
-USBDevice::ConfigurationDescriptor(uint32 index) const
+USBDevice::ConfigurationDescriptor(uint8 index) const
{
if (index > CountConfigurations())
return NULL;
@@ -395,7 +395,7 @@
return (usb_configuration_descriptor *) fConfigurationDescriptors[fActiveConfiguration];
}
-int
+uint8
USBDevice::ActiveConfigurationIndex() const
{
return fActiveConfiguration;
@@ -418,20 +418,19 @@
}
int
-USBDevice::CheckInterfacesFree(int config)
+USBDevice::CheckInterfacesFree(uint8 config)
{
if (fConfigToIndex.count(config) == 0)
return LIBUSB_ERROR_NOT_FOUND;
if (fClaimedInterfaces == 0)
- return fConfigToIndex[(uint8)config];
+ return fConfigToIndex[config];
return LIBUSB_ERROR_BUSY;
}
-int
-USBDevice::SetActiveConfiguration(int config_index)
+void
+USBDevice::SetActiveConfiguration(uint8 config_index)
{
fActiveConfiguration = config_index;
- return LIBUSB_SUCCESS;
}
uint8
@@ -463,7 +462,7 @@
fConfigurationDescriptors = new(std::nothrow) unsigned char *[fDeviceDescriptor.num_configurations];
fEndpointToIndex = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
fEndpointToInterface = new(std::nothrow) map<uint8,uint8> [fDeviceDescriptor.num_configurations];
- for (int i = 0; i < fDeviceDescriptor.num_configurations; i++) {
+ for (uint8 i = 0; i < fDeviceDescriptor.num_configurations; i++) {
usb_configuration_descriptor tmp_config;
command.config.descriptor = &tmp_config;
command.config.config_index = i;
@@ -479,14 +478,14 @@
command.config_etc.descriptor = (usb_configuration_descriptor*)fConfigurationDescriptors[i];
command.config_etc.length = tmp_config.total_length;
command.config_etc.config_index = i;
- if (ioctl(fRawFD, B_USB_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
+ if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC, &command, sizeof(command)) ||
command.config_etc.status != B_USB_RAW_STATUS_SUCCESS) {
usbi_err(NULL, "failed retrieving full configuration descriptor");
close(fRawFD);
return B_ERROR;
}
- for (int j = 0; j < tmp_config.number_interfaces; j++) {
+ for (uint8 j = 0; j < tmp_config.number_interfaces; j++) {
command.alternate.config_index = i;
command.alternate.interface_index = j;
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command)) ||
@@ -495,8 +494,8 @@
close(fRawFD);
return B_ERROR;
}
- int num_alternate = command.alternate.alternate_info;
- for (int k = 0; k < num_alternate; k++) {
+ uint8 num_alternate = (uint8)command.alternate.alternate_info;
+ for (uint8 k = 0; k < num_alternate; k++) {
usb_interface_descriptor tmp_interface;
command.interface_etc.config_index = i;
command.interface_etc.interface_index = j;
@@ -508,7 +507,7 @@
close(fRawFD);
return B_ERROR;
}
- for (int l = 0; l < tmp_interface.num_endpoints; l++) {
+ for (uint8 l = 0; l < tmp_interface.num_endpoints; l++) {
usb_endpoint_descriptor tmp_endpoint;
command.endpoint_etc.config_index = i;
command.endpoint_etc.interface_index = j;
diff --git a/libusb/os/haiku_usb_raw.cpp b/libusb/os/haiku_usb_raw.cpp
index 7c0c4db..af28c0b 100644
--- a/libusb/os/haiku_usb_raw.cpp
+++ b/libusb/os/haiku_usb_raw.cpp
@@ -111,7 +111,9 @@
haiku_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
USBDeviceHandle *handle= *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
- return handle->SetConfiguration(config);
+ if (config <= 0)
+ return LIBUSB_ERROR_NOT_SUPPORTED; // cannot unconfigure
+ return handle->SetConfiguration((uint8)config);
}
static int
@@ -187,31 +189,53 @@
}
const struct usbi_os_backend usbi_backend = {
- .name = "Haiku usbfs",
- .caps = 0,
- .init = haiku_init,
- .exit = haiku_exit,
- .open = haiku_open,
- .close = haiku_close,
+ /*.name =*/ "Haiku usbfs",
+ /*.caps =*/ 0,
+ /*.init =*/ haiku_init,
+ /*.exit =*/ haiku_exit,
+ /*.set_option =*/ NULL,
+ /*.get_device_list =*/ NULL,
+ /*.hotplug_poll =*/ NULL,
+ /*.wrap_sys_device =*/ NULL,
+ /*.open =*/ haiku_open,
+ /*.close =*/ haiku_close,
- .get_device_descriptor = haiku_get_device_descriptor,
- .get_active_config_descriptor = haiku_get_active_config_descriptor,
- .get_config_descriptor = haiku_get_config_descriptor,
+ /*.get_device_descriptor =*/ haiku_get_device_descriptor,
+ /*.get_active_config_descriptor =*/ haiku_get_active_config_descriptor,
+ /*.get_config_descriptor =*/ haiku_get_config_descriptor,
+ /*.get_config_descriptor_by_value =*/ NULL,
- .set_configuration = haiku_set_configuration,
+ /*.get_configuration =*/ NULL,
+ /*.set_configuration =*/ haiku_set_configuration,
- .claim_interface = haiku_claim_interface,
- .release_interface = haiku_release_interface,
+ /*.claim_interface =*/ haiku_claim_interface,
+ /*.release_interface =*/ haiku_release_interface,
+ /*.set_interface_altsetting =*/ haiku_set_altsetting,
- .set_interface_altsetting = haiku_set_altsetting,
- .clear_halt = haiku_clear_halt,
+ /*.clear_halt =*/ haiku_clear_halt,
+ /*.reset_device =*/ NULL,
- .submit_transfer = haiku_submit_transfer,
- .cancel_transfer = haiku_cancel_transfer,
+ /*.alloc_streams =*/ NULL,
+ /*.free_streams =*/ NULL,
- .handle_transfer_completion = haiku_handle_transfer_completion,
+ /*.dev_mem_alloc =*/ NULL,
+ /*.dev_mem_free =*/ NULL,
- .device_priv_size = sizeof(USBDevice *),
- .device_handle_priv_size = sizeof(USBDeviceHandle *),
- .transfer_priv_size = sizeof(USBTransfer *),
+ /*.kernel_driver_active =*/ NULL,
+ /*.detach_kernel_driver =*/ NULL,
+ /*.attach_kernel_driver =*/ NULL,
+
+ /*.destroy_device =*/ NULL,
+
+ /*.submit_transfer =*/ haiku_submit_transfer,
+ /*.cancel_transfer =*/ haiku_cancel_transfer,
+ /*.clear_transfer_priv =*/ NULL,
+
+ /*.handle_events =*/ NULL,
+ /*.handle_transfer_completion =*/ haiku_handle_transfer_completion,
+
+ /*.context_priv_size =*/ 0,
+ /*.device_priv_size =*/ sizeof(USBDevice *),
+ /*.device_handle_priv_size =*/ sizeof(USBDeviceHandle *),
+ /*.transfer_priv_size =*/ sizeof(USBTransfer *),
};
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 4528bbf..2d66b79 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11467
+#define LIBUSB_NANO 11468