* Prepare usb_raw.h for eventually being made public. Prefixed enums values

with B_USB_* and the command union is now usb_raw_command.
* Changed usb_raw and the BUSB* classes accordingly.
* Moved the raw_device struct into usb_raw.cpp as suggested by Francois as it
  was the only thing usb_raw_private.h defined.
* Removed usb_raw_private.h again because of the above.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24861 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2008-04-08 07:53:43 +00:00
parent 5822847842
commit bfbbfedc5f
8 changed files with 176 additions and 210 deletions
+3 -4
View File
@@ -19,13 +19,12 @@ BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD
fInterfaces(NULL),
fConfigurationString(NULL)
{
raw_command command;
usb_raw_command command;
command.config.descriptor = &fDescriptor;
command.config.config_index = fIndex;
if (ioctl(fRawFD, RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command, sizeof(command))
|| command.config.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command,
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
memset(&fDescriptor, 0, sizeof(fDescriptor));
}
fInterfaces = new BUSBInterface *[fDescriptor.number_interfaces];
for (uint32 i = 0; i < fDescriptor.number_interfaces; i++)
+17 -21
View File
@@ -55,16 +55,16 @@ BUSBDevice::SetTo(const char *path)
return B_ERROR;
}
raw_command command;
if (ioctl(fRawFD, RAW_COMMAND_GET_VERSION, &command, sizeof(command))
|| command.version.status != 0x0015) {
usb_raw_command command;
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_VERSION, &command, sizeof(command))
|| command.version.status != B_USB_RAW_PROTOCOL_VERSION) {
Unset();
return B_ERROR;
}
command.device.descriptor = &fDescriptor;
if (ioctl(fRawFD, RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command, sizeof(command))
|| command.device.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command,
sizeof(command)) || command.device.status != B_USB_RAW_STATUS_SUCCESS) {
Unset();
return B_ERROR;
}
@@ -244,15 +244,14 @@ BUSBDevice::GetStringDescriptor(uint32 index,
if (!descriptor)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.string.descriptor = descriptor;
command.string.string_index = index;
command.string.length = length;
if (ioctl(fRawFD, RAW_COMMAND_GET_STRING_DESCRIPTOR, &command, sizeof(command))
|| command.string.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR, &command,
sizeof(command)) || command.string.status != B_USB_RAW_STATUS_SUCCESS)
return 0;
}
return command.string.length;
}
@@ -288,17 +287,16 @@ BUSBDevice::GetDescriptor(uint8 type, uint8 index, uint16 languageID,
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.descriptor.type = type;
command.descriptor.index = index;
command.descriptor.language_id = languageID;
command.descriptor.data = data;
command.descriptor.length = length;
if (ioctl(fRawFD, RAW_COMMAND_GET_DESCRIPTOR, &command, sizeof(command))
|| command.descriptor.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_DESCRIPTOR, &command,
sizeof(command)) || command.descriptor.status != B_USB_RAW_STATUS_SUCCESS)
return 0;
}
return command.descriptor.length;
}
@@ -334,13 +332,12 @@ BUSBDevice::SetConfiguration(const BUSBConfiguration *configuration)
if (!configuration || configuration->Index() >= fDescriptor.num_configurations)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.config.config_index = configuration->Index();
if (ioctl(fRawFD, RAW_COMMAND_SET_CONFIGURATION, &command, sizeof(command))
|| command.config.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_CONFIGURATION, &command,
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
fActiveConfiguration = configuration->Index();
return B_OK;
@@ -354,7 +351,7 @@ BUSBDevice::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.control.request_type = requestType;
command.control.request = request;
command.control.value = value;
@@ -362,10 +359,9 @@ BUSBDevice::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
command.control.length = length;
command.control.data = data;
if (ioctl(fRawFD, RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command))
|| command.control.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command,
sizeof(command)) || command.control.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return command.control.length;
}
+15 -20
View File
@@ -17,15 +17,14 @@ BUSBEndpoint::BUSBEndpoint(BUSBInterface *interface, uint32 index, int rawFD)
fIndex(index),
fRawFD(rawFD)
{
raw_command command;
usb_raw_command command;
command.endpoint.descriptor = &fDescriptor;
command.endpoint.config_index = fInterface->Configuration()->Index();
command.endpoint.interface_index = fInterface->Index();
command.endpoint.endpoint_index = fIndex;
if (ioctl(fRawFD, RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR, &command, sizeof(command))
|| command.config.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR, &command,
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
memset(&fDescriptor, 0, sizeof(fDescriptor));
}
}
@@ -132,7 +131,7 @@ BUSBEndpoint::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.control.request_type = requestType;
command.control.request = request;
command.control.value = value;
@@ -140,10 +139,9 @@ BUSBEndpoint::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
command.control.length = length;
command.control.data = data;
if (ioctl(fRawFD, RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command))
|| command.control.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command,
sizeof(command)) || command.control.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return command.control.length;
}
@@ -155,16 +153,15 @@ BUSBEndpoint::InterruptTransfer(void *data, size_t length) const
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.transfer.interface = fInterface->Index();
command.transfer.endpoint = fIndex;
command.transfer.data = data;
command.transfer.length = length;
if (ioctl(fRawFD, RAW_COMMAND_INTERRUPT_TRANSFER, &command, sizeof(command))
|| command.transfer.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_INTERRUPT_TRANSFER, &command,
sizeof(command)) || command.transfer.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return command.transfer.length;
}
@@ -176,16 +173,15 @@ BUSBEndpoint::BulkTransfer(void *data, size_t length) const
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.transfer.interface = fInterface->Index();
command.transfer.endpoint = fIndex;
command.transfer.data = data;
command.transfer.length = length;
if (ioctl(fRawFD, RAW_COMMAND_BULK_TRANSFER, &command, sizeof(command))
|| command.transfer.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_BULK_TRANSFER, &command,
sizeof(command)) || command.transfer.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return command.transfer.length;
}
@@ -198,7 +194,7 @@ BUSBEndpoint::IsochronousTransfer(void *data, size_t length,
if (length > 0 && data == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.isochronous.interface = fInterface->Index();
command.isochronous.endpoint = fIndex;
command.isochronous.data = data;
@@ -206,10 +202,9 @@ BUSBEndpoint::IsochronousTransfer(void *data, size_t length,
command.isochronous.packet_descriptors = packetDescriptors;
command.isochronous.packet_count = packetCount;
if (ioctl(fRawFD, RAW_COMMAND_ISOCHRONOUS_TRANSFER, &command, sizeof(command))
|| command.isochronous.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER, &command,
sizeof(command)) || command.isochronous.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return command.isochronous.length;
}
+15 -19
View File
@@ -110,16 +110,15 @@ BUSBInterface::OtherDescriptorAt(uint32 index, usb_descriptor *descriptor,
if (length > 0 && descriptor == NULL)
return B_BAD_VALUE;
raw_command command;
usb_raw_command command;
command.generic.descriptor = descriptor;
command.generic.config_index = fConfiguration->Index();
command.generic.interface_index = fIndex;
command.generic.length = length;
command.generic.generic_index = index;
if (ioctl(fRawFD, RAW_COMMAND_GET_GENERIC_DESCRIPTOR, &command, sizeof(command))
|| command.generic.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR, &command,
sizeof(command)) || command.generic.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
return B_OK;
}
@@ -146,14 +145,13 @@ uint32
BUSBInterface::CountAlternates() const
{
uint32 alternateCount;
raw_command command;
usb_raw_command command;
command.alternate.alternate_count = &alternateCount;
command.alternate.config_index = fConfiguration->Index();
command.alternate.interface_index = fIndex;
if (ioctl(fRawFD, RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command))
|| command.alternate.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command,
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS)
return 1;
}
return alternateCount;
}
@@ -167,13 +165,13 @@ BUSBInterface::AlternateAt(uint32 alternateIndex)
if (descriptor == NULL)
return NULL;
raw_command command;
usb_raw_command command;
command.alternate.descriptor = descriptor;
command.alternate.config_index = fConfiguration->Index();
command.alternate.interface_index = fIndex;
command.alternate.alternate_index = alternateIndex;
if (ioctl(fRawFD, RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &command,
sizeof(command)) || command.alternate.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &command,
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS) {
delete descriptor;
return NULL;
}
@@ -185,14 +183,13 @@ BUSBInterface::AlternateAt(uint32 alternateIndex)
status_t
BUSBInterface::SetAlternate(uint32 alternateIndex)
{
raw_command command;
usb_raw_command command;
command.alternate.config_index = fConfiguration->Index();
command.alternate.interface_index = fIndex;
command.alternate.alternate_index = alternateIndex;
if (ioctl(fRawFD, RAW_COMMAND_SET_ALT_INTERFACE, &command, sizeof(command))
|| command.alternate.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_ALT_INTERFACE, &command,
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS)
return B_ERROR;
}
_UpdateDescriptorAndEndpoints();
return B_OK;
@@ -202,14 +199,13 @@ BUSBInterface::SetAlternate(uint32 alternateIndex)
void
BUSBInterface::_UpdateDescriptorAndEndpoints()
{
raw_command command;
usb_raw_command command;
command.interface.descriptor = &fDescriptor;
command.interface.config_index = fConfiguration->Index();
command.interface.interface_index = fIndex;
if (ioctl(fRawFD, RAW_COMMAND_GET_INTERFACE_DESCRIPTOR, &command, sizeof(command))
|| command.interface.status != RAW_STATUS_SUCCESS) {
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR, &command,
sizeof(command)) || command.interface.status != B_USB_RAW_STATUS_SUCCESS)
memset(&fDescriptor, 0, sizeof(fDescriptor));
}
if (fEndpoints) {
// Delete old endpoints
-1
View File
@@ -7,7 +7,6 @@
*/
#include <USBKit.h>
#include <usb_raw.h>
#include <Directory.h>
#include <Entry.h>
#include <Looper.h>