* 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:
@@ -8,14 +8,13 @@
|
|||||||
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
|
#include <lock.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "usb_raw.h"
|
#include "usb_raw.h"
|
||||||
#include "usb_raw_private.h"
|
|
||||||
#include "BeOSCompatibility.h"
|
#include "BeOSCompatibility.h"
|
||||||
|
|
||||||
|
|
||||||
//#define TRACE_USB_RAW
|
//#define TRACE_USB_RAW
|
||||||
#ifdef TRACE_USB_RAW
|
#ifdef TRACE_USB_RAW
|
||||||
#define TRACE(x) dprintf x
|
#define TRACE(x) dprintf x
|
||||||
@@ -23,10 +22,21 @@
|
|||||||
#define TRACE(x) /* nothing */
|
#define TRACE(x) /* nothing */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define DRIVER_NAME "usb_raw"
|
#define DRIVER_NAME "usb_raw"
|
||||||
#define DEVICE_NAME "bus/usb/raw"
|
#define DEVICE_NAME "bus/usb/raw"
|
||||||
#define DRIVER_VERSION 0x0015
|
|
||||||
|
typedef struct {
|
||||||
|
usb_device device;
|
||||||
|
benaphore lock;
|
||||||
|
uint32 reference_count;
|
||||||
|
|
||||||
|
char name[32];
|
||||||
|
void *link;
|
||||||
|
|
||||||
|
sem_id notify;
|
||||||
|
status_t status;
|
||||||
|
size_t actual_length;
|
||||||
|
} raw_device;
|
||||||
|
|
||||||
int32 api_version = B_CUR_DRIVER_API_VERSION;
|
int32 api_version = B_CUR_DRIVER_API_VERSION;
|
||||||
static usb_module_info *gUSBModule = NULL;
|
static usb_module_info *gUSBModule = NULL;
|
||||||
@@ -175,22 +185,22 @@ usb_raw_callback(void *cookie, status_t status, void *data, size_t actualLength)
|
|||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case B_OK:
|
case B_OK:
|
||||||
device->status = RAW_STATUS_SUCCESS;
|
device->status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
case B_TIMED_OUT:
|
case B_TIMED_OUT:
|
||||||
device->status = RAW_STATUS_TIMEOUT;
|
device->status = B_USB_RAW_STATUS_TIMEOUT;
|
||||||
break;
|
break;
|
||||||
case B_CANCELED:
|
case B_CANCELED:
|
||||||
device->status = RAW_STATUS_ABORTED;
|
device->status = B_USB_RAW_STATUS_ABORTED;
|
||||||
break;
|
break;
|
||||||
case B_DEV_CRC_ERROR:
|
case B_DEV_CRC_ERROR:
|
||||||
device->status = RAW_STATUS_CRC_ERROR;
|
device->status = B_USB_RAW_STATUS_CRC_ERROR;
|
||||||
break;
|
break;
|
||||||
case B_DEV_STALLED:
|
case B_DEV_STALLED:
|
||||||
device->status = RAW_STATUS_STALLED;
|
device->status = B_USB_RAW_STATUS_STALLED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
device->status = RAW_STATUS_FAILED;
|
device->status = B_USB_RAW_STATUS_FAILED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,199 +214,199 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
{
|
{
|
||||||
TRACE((DRIVER_NAME": ioctl\n"));
|
TRACE((DRIVER_NAME": ioctl\n"));
|
||||||
raw_device *device = (raw_device *)cookie;
|
raw_device *device = (raw_device *)cookie;
|
||||||
raw_command *command = (raw_command *)buffer;
|
usb_raw_command *command = (usb_raw_command *)buffer;
|
||||||
|
|
||||||
if (device->device == 0)
|
if (device->device == 0)
|
||||||
return B_DEV_NOT_READY;
|
return B_DEV_NOT_READY;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case RAW_COMMAND_GET_VERSION: {
|
case B_USB_RAW_COMMAND_GET_VERSION: {
|
||||||
command->version.status = DRIVER_VERSION;
|
command->version.status = B_USB_RAW_PROTOCOL_VERSION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_DEVICE_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR: {
|
||||||
const usb_device_descriptor *deviceDescriptor =
|
const usb_device_descriptor *deviceDescriptor =
|
||||||
gUSBModule->get_device_descriptor(device->device);
|
gUSBModule->get_device_descriptor(device->device);
|
||||||
if (!deviceDescriptor) {
|
if (!deviceDescriptor) {
|
||||||
command->device.status = RAW_STATUS_ABORTED;
|
command->device.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->device.descriptor, deviceDescriptor,
|
memcpy(command->device.descriptor, deviceDescriptor,
|
||||||
sizeof(usb_device_descriptor));
|
sizeof(usb_device_descriptor));
|
||||||
command->device.status = RAW_STATUS_SUCCESS;
|
command->device.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->config.config_index);
|
command->config.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->config.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->config.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->config.descriptor, configurationInfo->descr,
|
memcpy(command->config.descriptor, configurationInfo->descr,
|
||||||
sizeof(usb_configuration_descriptor));
|
sizeof(usb_configuration_descriptor));
|
||||||
command->config.status = RAW_STATUS_SUCCESS;
|
command->config.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_INTERFACE_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->interface.config_index);
|
command->interface.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->interface.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->interface.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->interface.interface_index >= configurationInfo->interface_count) {
|
if (command->interface.interface_index >= configurationInfo->interface_count) {
|
||||||
command->interface.status = RAW_STATUS_INVALID_INTERFACE;
|
command->interface.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_info *interfaceInfo =
|
const usb_interface_info *interfaceInfo =
|
||||||
configurationInfo->interface[command->interface.interface_index].active;
|
configurationInfo->interface[command->interface.interface_index].active;
|
||||||
if (!interfaceInfo) {
|
if (!interfaceInfo) {
|
||||||
command->interface.status = RAW_STATUS_ABORTED;
|
command->interface.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->interface.descriptor, interfaceInfo->descr,
|
memcpy(command->interface.descriptor, interfaceInfo->descr,
|
||||||
sizeof(usb_interface_descriptor));
|
sizeof(usb_interface_descriptor));
|
||||||
command->interface.status = RAW_STATUS_SUCCESS;
|
command->interface.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_ALT_INTERFACE_COUNT: {
|
case B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->alternate.config_index);
|
command->alternate.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_INTERFACE;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
*command->alternate.alternate_count
|
*command->alternate.alternate_count
|
||||||
= configurationInfo->interface[command->alternate.interface_index].alt_count;
|
= configurationInfo->interface[command->alternate.interface_index].alt_count;
|
||||||
command->alternate.status = RAW_STATUS_SUCCESS;
|
command->alternate.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->alternate.config_index);
|
command->alternate.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_INTERFACE;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_list *interfaceList =
|
const usb_interface_list *interfaceList =
|
||||||
&configurationInfo->interface[command->alternate.interface_index];
|
&configurationInfo->interface[command->alternate.interface_index];
|
||||||
if (command->alternate.alternate_index >= interfaceList->alt_count) {
|
if (command->alternate.alternate_index >= interfaceList->alt_count) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_INTERFACE;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->alternate.descriptor,
|
memcpy(command->alternate.descriptor,
|
||||||
&interfaceList->alt[command->alternate.alternate_index],
|
&interfaceList->alt[command->alternate.alternate_index],
|
||||||
sizeof(usb_interface_descriptor));
|
sizeof(usb_interface_descriptor));
|
||||||
command->alternate.status = RAW_STATUS_SUCCESS;
|
command->alternate.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->endpoint.config_index);
|
command->endpoint.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->endpoint.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->endpoint.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->endpoint.interface_index >= configurationInfo->interface_count) {
|
if (command->endpoint.interface_index >= configurationInfo->interface_count) {
|
||||||
command->endpoint.status = RAW_STATUS_INVALID_INTERFACE;
|
command->endpoint.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_info *interfaceInfo =
|
const usb_interface_info *interfaceInfo =
|
||||||
configurationInfo->interface[command->endpoint.interface_index].active;
|
configurationInfo->interface[command->endpoint.interface_index].active;
|
||||||
if (!interfaceInfo) {
|
if (!interfaceInfo) {
|
||||||
command->endpoint.status = RAW_STATUS_ABORTED;
|
command->endpoint.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->endpoint.endpoint_index >= interfaceInfo->endpoint_count) {
|
if (command->endpoint.endpoint_index >= interfaceInfo->endpoint_count) {
|
||||||
command->endpoint.status = RAW_STATUS_INVALID_ENDPOINT;
|
command->endpoint.status = B_USB_RAW_STATUS_INVALID_ENDPOINT;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->endpoint.descriptor,
|
memcpy(command->endpoint.descriptor,
|
||||||
interfaceInfo->endpoint[command->endpoint.endpoint_index].descr,
|
interfaceInfo->endpoint[command->endpoint.endpoint_index].descr,
|
||||||
sizeof(usb_endpoint_descriptor));
|
sizeof(usb_endpoint_descriptor));
|
||||||
command->endpoint.status = RAW_STATUS_SUCCESS;
|
command->endpoint.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_GENERIC_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->generic.config_index);
|
command->generic.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->generic.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->generic.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->generic.interface_index >= configurationInfo->interface_count) {
|
if (command->generic.interface_index >= configurationInfo->interface_count) {
|
||||||
command->generic.status = RAW_STATUS_INVALID_INTERFACE;
|
command->generic.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_info *interfaceInfo =
|
const usb_interface_info *interfaceInfo =
|
||||||
configurationInfo->interface[command->generic.interface_index].active;
|
configurationInfo->interface[command->generic.interface_index].active;
|
||||||
if (!interfaceInfo) {
|
if (!interfaceInfo) {
|
||||||
command->generic.status = RAW_STATUS_ABORTED;
|
command->generic.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->generic.generic_index >= interfaceInfo->generic_count) {
|
if (command->generic.generic_index >= interfaceInfo->generic_count) {
|
||||||
// ToDo: add RAW_STATUS_INVALID_GENERIC
|
// ToDo: add B_USB_RAW_STATUS_INVALID_GENERIC
|
||||||
command->generic.status = RAW_STATUS_INVALID_ENDPOINT;
|
command->generic.status = B_USB_RAW_STATUS_INVALID_ENDPOINT;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_descriptor *descriptor = interfaceInfo->generic[command->generic.generic_index];
|
usb_descriptor *descriptor = interfaceInfo->generic[command->generic.generic_index];
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
command->generic.status = RAW_STATUS_ABORTED;
|
command->generic.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor->generic.length > command->generic.length) {
|
if (descriptor->generic.length > command->generic.length) {
|
||||||
command->generic.status = RAW_STATUS_NO_MEMORY;
|
command->generic.status = B_USB_RAW_STATUS_NO_MEMORY;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->generic.descriptor, descriptor,
|
memcpy(command->generic.descriptor, descriptor,
|
||||||
descriptor->generic.length);
|
descriptor->generic.length);
|
||||||
command->generic.status = RAW_STATUS_SUCCESS;
|
command->generic.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_STRING_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR: {
|
||||||
size_t actualLength = 0;
|
size_t actualLength = 0;
|
||||||
uint8 firstTwoBytes[2];
|
uint8 firstTwoBytes[2];
|
||||||
|
|
||||||
@@ -405,7 +415,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
firstTwoBytes, 2, &actualLength) < B_OK
|
firstTwoBytes, 2, &actualLength) < B_OK
|
||||||
|| actualLength != 2
|
|| actualLength != 2
|
||||||
|| firstTwoBytes[1] != USB_DESCRIPTOR_STRING) {
|
|| firstTwoBytes[1] != USB_DESCRIPTOR_STRING) {
|
||||||
command->string.status = RAW_STATUS_ABORTED;
|
command->string.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->string.length = 0;
|
command->string.length = 0;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -413,7 +423,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
uint8 stringLength = MIN(firstTwoBytes[0], command->string.length);
|
uint8 stringLength = MIN(firstTwoBytes[0], command->string.length);
|
||||||
char *string = (char *)malloc(stringLength);
|
char *string = (char *)malloc(stringLength);
|
||||||
if (!string) {
|
if (!string) {
|
||||||
command->string.status = RAW_STATUS_ABORTED;
|
command->string.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->string.length = 0;
|
command->string.length = 0;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -422,20 +432,20 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
USB_DESCRIPTOR_STRING, command->string.string_index, 0,
|
USB_DESCRIPTOR_STRING, command->string.string_index, 0,
|
||||||
string, stringLength, &actualLength) < B_OK
|
string, stringLength, &actualLength) < B_OK
|
||||||
|| actualLength != stringLength) {
|
|| actualLength != stringLength) {
|
||||||
command->string.status = RAW_STATUS_ABORTED;
|
command->string.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->string.length = 0;
|
command->string.length = 0;
|
||||||
free(string);
|
free(string);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->string.descriptor, string, stringLength);
|
memcpy(command->string.descriptor, string, stringLength);
|
||||||
command->string.status = RAW_STATUS_SUCCESS;
|
command->string.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
command->string.length = stringLength;
|
command->string.length = stringLength;
|
||||||
free(string);
|
free(string);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_GET_DESCRIPTOR: {
|
case B_USB_RAW_COMMAND_GET_DESCRIPTOR: {
|
||||||
size_t actualLength = 0;
|
size_t actualLength = 0;
|
||||||
uint8 firstTwoBytes[2];
|
uint8 firstTwoBytes[2];
|
||||||
|
|
||||||
@@ -445,7 +455,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
&actualLength) < B_OK
|
&actualLength) < B_OK
|
||||||
|| actualLength != 2
|
|| actualLength != 2
|
||||||
|| firstTwoBytes[1] != command->descriptor.type) {
|
|| firstTwoBytes[1] != command->descriptor.type) {
|
||||||
command->descriptor.status = RAW_STATUS_ABORTED;
|
command->descriptor.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->descriptor.length = 0;
|
command->descriptor.length = 0;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -453,7 +463,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
uint8 length = MIN(firstTwoBytes[0], command->descriptor.length);
|
uint8 length = MIN(firstTwoBytes[0], command->descriptor.length);
|
||||||
uint8 *buffer = (uint8 *)malloc(length);
|
uint8 *buffer = (uint8 *)malloc(length);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
command->descriptor.status = RAW_STATUS_ABORTED;
|
command->descriptor.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->descriptor.length = 0;
|
command->descriptor.length = 0;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
@@ -463,77 +473,77 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
command->descriptor.language_id, buffer, length,
|
command->descriptor.language_id, buffer, length,
|
||||||
&actualLength) < B_OK
|
&actualLength) < B_OK
|
||||||
|| actualLength != length) {
|
|| actualLength != length) {
|
||||||
command->descriptor.status = RAW_STATUS_ABORTED;
|
command->descriptor.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
command->descriptor.length = 0;
|
command->descriptor.length = 0;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(command->descriptor.data, buffer, length);
|
memcpy(command->descriptor.data, buffer, length);
|
||||||
command->descriptor.status = RAW_STATUS_SUCCESS;
|
command->descriptor.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
command->descriptor.length = length;
|
command->descriptor.length = length;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_SET_CONFIGURATION: {
|
case B_USB_RAW_COMMAND_SET_CONFIGURATION: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->config.config_index);
|
command->config.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->config.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->config.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gUSBModule->set_configuration(device->device,
|
if (gUSBModule->set_configuration(device->device,
|
||||||
configurationInfo) < B_OK) {
|
configurationInfo) < B_OK) {
|
||||||
command->config.status = RAW_STATUS_FAILED;
|
command->config.status = B_USB_RAW_STATUS_FAILED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
command->config.status = RAW_STATUS_SUCCESS;
|
command->config.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_SET_ALT_INTERFACE: {
|
case B_USB_RAW_COMMAND_SET_ALT_INTERFACE: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_nth_configuration(device->device,
|
gUSBModule->get_nth_configuration(device->device,
|
||||||
command->alternate.config_index);
|
command->alternate.config_index);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
if (command->alternate.interface_index >= configurationInfo->interface_count) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_INTERFACE;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_list *interfaceList =
|
const usb_interface_list *interfaceList =
|
||||||
&configurationInfo->interface[command->alternate.interface_index];
|
&configurationInfo->interface[command->alternate.interface_index];
|
||||||
if (command->alternate.alternate_index >= interfaceList->alt_count) {
|
if (command->alternate.alternate_index >= interfaceList->alt_count) {
|
||||||
command->alternate.status = RAW_STATUS_INVALID_INTERFACE;
|
command->alternate.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gUSBModule->set_alt_interface(device->device,
|
if (gUSBModule->set_alt_interface(device->device,
|
||||||
&interfaceList->alt[command->alternate.alternate_index]) < B_OK) {
|
&interfaceList->alt[command->alternate.alternate_index]) < B_OK) {
|
||||||
command->alternate.status = RAW_STATUS_FAILED;
|
command->alternate.status = B_USB_RAW_STATUS_FAILED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
command->alternate.status = RAW_STATUS_SUCCESS;
|
command->alternate.status = B_USB_RAW_STATUS_SUCCESS;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_CONTROL_TRANSFER: {
|
case B_USB_RAW_COMMAND_CONTROL_TRANSFER: {
|
||||||
benaphore_lock(&device->lock);
|
benaphore_lock(&device->lock);
|
||||||
if (gUSBModule->queue_request(device->device,
|
if (gUSBModule->queue_request(device->device,
|
||||||
command->control.request_type, command->control.request,
|
command->control.request_type, command->control.request,
|
||||||
command->control.value, command->control.index,
|
command->control.value, command->control.index,
|
||||||
command->control.length, command->control.data,
|
command->control.length, command->control.data,
|
||||||
usb_raw_callback, device) < B_OK) {
|
usb_raw_callback, device) < B_OK) {
|
||||||
command->control.status = RAW_STATUS_FAILED;
|
command->control.status = B_USB_RAW_STATUS_FAILED;
|
||||||
command->control.length = 0;
|
command->control.length = 0;
|
||||||
benaphore_unlock(&device->lock);
|
benaphore_unlock(&device->lock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -546,48 +556,48 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
case RAW_COMMAND_INTERRUPT_TRANSFER:
|
case B_USB_RAW_COMMAND_INTERRUPT_TRANSFER:
|
||||||
case RAW_COMMAND_BULK_TRANSFER:
|
case B_USB_RAW_COMMAND_BULK_TRANSFER:
|
||||||
case RAW_COMMAND_ISOCHRONOUS_TRANSFER: {
|
case B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER: {
|
||||||
const usb_configuration_info *configurationInfo =
|
const usb_configuration_info *configurationInfo =
|
||||||
gUSBModule->get_configuration(device->device);
|
gUSBModule->get_configuration(device->device);
|
||||||
if (!configurationInfo) {
|
if (!configurationInfo) {
|
||||||
command->transfer.status = RAW_STATUS_INVALID_CONFIGURATION;
|
command->transfer.status = B_USB_RAW_STATUS_INVALID_CONFIGURATION;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->transfer.interface >= configurationInfo->interface_count) {
|
if (command->transfer.interface >= configurationInfo->interface_count) {
|
||||||
command->transfer.status = RAW_STATUS_INVALID_INTERFACE;
|
command->transfer.status = B_USB_RAW_STATUS_INVALID_INTERFACE;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_interface_info *interfaceInfo =
|
const usb_interface_info *interfaceInfo =
|
||||||
configurationInfo->interface[command->transfer.interface].active;
|
configurationInfo->interface[command->transfer.interface].active;
|
||||||
if (!interfaceInfo) {
|
if (!interfaceInfo) {
|
||||||
command->transfer.status = RAW_STATUS_ABORTED;
|
command->transfer.status = B_USB_RAW_STATUS_ABORTED;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command->transfer.endpoint >= interfaceInfo->endpoint_count) {
|
if (command->transfer.endpoint >= interfaceInfo->endpoint_count) {
|
||||||
command->transfer.status = RAW_STATUS_INVALID_ENDPOINT;
|
command->transfer.status = B_USB_RAW_STATUS_INVALID_ENDPOINT;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const usb_endpoint_info *endpointInfo =
|
const usb_endpoint_info *endpointInfo =
|
||||||
&interfaceInfo->endpoint[command->transfer.endpoint];
|
&interfaceInfo->endpoint[command->transfer.endpoint];
|
||||||
if (!endpointInfo->handle) {
|
if (!endpointInfo->handle) {
|
||||||
command->transfer.status = RAW_STATUS_INVALID_ENDPOINT;
|
command->transfer.status = B_USB_RAW_STATUS_INVALID_ENDPOINT;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
benaphore_lock(&device->lock);
|
benaphore_lock(&device->lock);
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
if (op == RAW_COMMAND_INTERRUPT_TRANSFER) {
|
if (op == B_USB_RAW_COMMAND_INTERRUPT_TRANSFER) {
|
||||||
status = gUSBModule->queue_interrupt(endpointInfo->handle,
|
status = gUSBModule->queue_interrupt(endpointInfo->handle,
|
||||||
command->transfer.data, command->transfer.length,
|
command->transfer.data, command->transfer.length,
|
||||||
usb_raw_callback, device);
|
usb_raw_callback, device);
|
||||||
} else if (op == RAW_COMMAND_BULK_TRANSFER) {
|
} else if (op == B_USB_RAW_COMMAND_BULK_TRANSFER) {
|
||||||
status = gUSBModule->queue_bulk(endpointInfo->handle,
|
status = gUSBModule->queue_bulk(endpointInfo->handle,
|
||||||
command->transfer.data, command->transfer.length,
|
command->transfer.data, command->transfer.length,
|
||||||
usb_raw_callback, device);
|
usb_raw_callback, device);
|
||||||
@@ -600,7 +610,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
command->transfer.status = RAW_STATUS_FAILED;
|
command->transfer.status = B_USB_RAW_STATUS_FAILED;
|
||||||
command->transfer.length = 0;
|
command->transfer.length = 0;
|
||||||
benaphore_unlock(&device->lock);
|
benaphore_unlock(&device->lock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2008, Haiku Inc. All rights reserved.
|
* Copyright 2006-2008, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Michael Lotz <[email protected]>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _USB_RAW_H_
|
#ifndef _USB_RAW_H_
|
||||||
@@ -11,48 +8,50 @@
|
|||||||
|
|
||||||
#include <USB3.h>
|
#include <USB3.h>
|
||||||
|
|
||||||
|
#define B_USB_RAW_PROTOCOL_VERSION 0x0015
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RAW_COMMAND_GET_VERSION = 0x1000,
|
B_USB_RAW_COMMAND_GET_VERSION = 0x1000,
|
||||||
|
|
||||||
RAW_COMMAND_GET_DEVICE_DESCRIPTOR = 0x2000,
|
B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR = 0x2000,
|
||||||
RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR,
|
||||||
RAW_COMMAND_GET_INTERFACE_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR,
|
||||||
RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR,
|
||||||
RAW_COMMAND_GET_STRING_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR,
|
||||||
RAW_COMMAND_GET_GENERIC_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR,
|
||||||
RAW_COMMAND_GET_ALT_INTERFACE_COUNT,
|
B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT,
|
||||||
RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR,
|
||||||
|
|
||||||
RAW_COMMAND_SET_CONFIGURATION = 0x3000,
|
B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000,
|
||||||
RAW_COMMAND_SET_FEATURE,
|
B_USB_RAW_COMMAND_SET_FEATURE,
|
||||||
RAW_COMMAND_CLEAR_FEATURE,
|
B_USB_RAW_COMMAND_CLEAR_FEATURE,
|
||||||
RAW_COMMAND_GET_STATUS,
|
B_USB_RAW_COMMAND_GET_STATUS,
|
||||||
RAW_COMMAND_GET_DESCRIPTOR,
|
B_USB_RAW_COMMAND_GET_DESCRIPTOR,
|
||||||
RAW_COMMAND_SET_ALT_INTERFACE,
|
B_USB_RAW_COMMAND_SET_ALT_INTERFACE,
|
||||||
|
|
||||||
RAW_COMMAND_CONTROL_TRANSFER = 0x4000,
|
B_USB_RAW_COMMAND_CONTROL_TRANSFER = 0x4000,
|
||||||
RAW_COMMAND_INTERRUPT_TRANSFER,
|
B_USB_RAW_COMMAND_INTERRUPT_TRANSFER,
|
||||||
RAW_COMMAND_BULK_TRANSFER,
|
B_USB_RAW_COMMAND_BULK_TRANSFER,
|
||||||
RAW_COMMAND_ISOCHRONOUS_TRANSFER
|
B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER
|
||||||
} raw_command_id;
|
} usb_raw_command_id;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RAW_STATUS_SUCCESS = 0,
|
B_USB_RAW_STATUS_SUCCESS = 0,
|
||||||
|
|
||||||
RAW_STATUS_FAILED,
|
B_USB_RAW_STATUS_FAILED,
|
||||||
RAW_STATUS_ABORTED,
|
B_USB_RAW_STATUS_ABORTED,
|
||||||
RAW_STATUS_STALLED,
|
B_USB_RAW_STATUS_STALLED,
|
||||||
RAW_STATUS_CRC_ERROR,
|
B_USB_RAW_STATUS_CRC_ERROR,
|
||||||
RAW_STATUS_TIMEOUT,
|
B_USB_RAW_STATUS_TIMEOUT,
|
||||||
|
|
||||||
RAW_STATUS_INVALID_CONFIGURATION,
|
B_USB_RAW_STATUS_INVALID_CONFIGURATION,
|
||||||
RAW_STATUS_INVALID_INTERFACE,
|
B_USB_RAW_STATUS_INVALID_INTERFACE,
|
||||||
RAW_STATUS_INVALID_ENDPOINT,
|
B_USB_RAW_STATUS_INVALID_ENDPOINT,
|
||||||
RAW_STATUS_INVALID_STRING,
|
B_USB_RAW_STATUS_INVALID_STRING,
|
||||||
|
|
||||||
RAW_STATUS_NO_MEMORY
|
B_USB_RAW_STATUS_NO_MEMORY
|
||||||
} raw_command_status;
|
} usb_raw_command_status;
|
||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -147,6 +146,6 @@ typedef union {
|
|||||||
usb_iso_packet_descriptor *packet_descriptors;
|
usb_iso_packet_descriptor *packet_descriptors;
|
||||||
uint32 packet_count;
|
uint32 packet_count;
|
||||||
} isochronous;
|
} isochronous;
|
||||||
} raw_command;
|
} usb_raw_command;
|
||||||
|
|
||||||
#endif // _USB_RAW_H_
|
#endif // _USB_RAW_H_
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2008, Haiku Inc. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Michael Lotz <[email protected]>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _USB_RAW_PRIVATE_H_
|
|
||||||
#define _USB_RAW_PRIVATE_H_
|
|
||||||
|
|
||||||
#include <lock.h>
|
|
||||||
#include <USB3.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
usb_device device;
|
|
||||||
benaphore lock;
|
|
||||||
uint32 reference_count;
|
|
||||||
|
|
||||||
char name[32];
|
|
||||||
void *link;
|
|
||||||
|
|
||||||
sem_id notify;
|
|
||||||
status_t status;
|
|
||||||
size_t actual_length;
|
|
||||||
} raw_device;
|
|
||||||
|
|
||||||
#endif // _USB_RAW_PRIVATE_H_
|
|
||||||
@@ -19,13 +19,12 @@ BUSBConfiguration::BUSBConfiguration(BUSBDevice *device, uint32 index, int rawFD
|
|||||||
fInterfaces(NULL),
|
fInterfaces(NULL),
|
||||||
fConfigurationString(NULL)
|
fConfigurationString(NULL)
|
||||||
{
|
{
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.config.descriptor = &fDescriptor;
|
command.config.descriptor = &fDescriptor;
|
||||||
command.config.config_index = fIndex;
|
command.config.config_index = fIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR, &command,
|
||||||
|| command.config.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
||||||
}
|
|
||||||
|
|
||||||
fInterfaces = new BUSBInterface *[fDescriptor.number_interfaces];
|
fInterfaces = new BUSBInterface *[fDescriptor.number_interfaces];
|
||||||
for (uint32 i = 0; i < fDescriptor.number_interfaces; i++)
|
for (uint32 i = 0; i < fDescriptor.number_interfaces; i++)
|
||||||
|
|||||||
@@ -55,16 +55,16 @@ BUSBDevice::SetTo(const char *path)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_VERSION, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_VERSION, &command, sizeof(command))
|
||||||
|| command.version.status != 0x0015) {
|
|| command.version.status != B_USB_RAW_PROTOCOL_VERSION) {
|
||||||
Unset();
|
Unset();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
command.device.descriptor = &fDescriptor;
|
command.device.descriptor = &fDescriptor;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR, &command,
|
||||||
|| command.device.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.device.status != B_USB_RAW_STATUS_SUCCESS) {
|
||||||
Unset();
|
Unset();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -244,15 +244,14 @@ BUSBDevice::GetStringDescriptor(uint32 index,
|
|||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.string.descriptor = descriptor;
|
command.string.descriptor = descriptor;
|
||||||
command.string.string_index = index;
|
command.string.string_index = index;
|
||||||
command.string.length = length;
|
command.string.length = length;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_STRING_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR, &command,
|
||||||
|| command.string.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.string.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return command.string.length;
|
return command.string.length;
|
||||||
}
|
}
|
||||||
@@ -288,17 +287,16 @@ BUSBDevice::GetDescriptor(uint8 type, uint8 index, uint16 languageID,
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.descriptor.type = type;
|
command.descriptor.type = type;
|
||||||
command.descriptor.index = index;
|
command.descriptor.index = index;
|
||||||
command.descriptor.language_id = languageID;
|
command.descriptor.language_id = languageID;
|
||||||
command.descriptor.data = data;
|
command.descriptor.data = data;
|
||||||
command.descriptor.length = length;
|
command.descriptor.length = length;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_DESCRIPTOR, &command,
|
||||||
|| command.descriptor.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.descriptor.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return command.descriptor.length;
|
return command.descriptor.length;
|
||||||
}
|
}
|
||||||
@@ -334,13 +332,12 @@ BUSBDevice::SetConfiguration(const BUSBConfiguration *configuration)
|
|||||||
if (!configuration || configuration->Index() >= fDescriptor.num_configurations)
|
if (!configuration || configuration->Index() >= fDescriptor.num_configurations)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.config.config_index = configuration->Index();
|
command.config.config_index = configuration->Index();
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_SET_CONFIGURATION, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_CONFIGURATION, &command,
|
||||||
|| command.config.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
fActiveConfiguration = configuration->Index();
|
fActiveConfiguration = configuration->Index();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -354,7 +351,7 @@ BUSBDevice::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.control.request_type = requestType;
|
command.control.request_type = requestType;
|
||||||
command.control.request = request;
|
command.control.request = request;
|
||||||
command.control.value = value;
|
command.control.value = value;
|
||||||
@@ -362,10 +359,9 @@ BUSBDevice::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
|
|||||||
command.control.length = length;
|
command.control.length = length;
|
||||||
command.control.data = data;
|
command.control.data = data;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command,
|
||||||
|| command.control.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.control.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return command.control.length;
|
return command.control.length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ BUSBEndpoint::BUSBEndpoint(BUSBInterface *interface, uint32 index, int rawFD)
|
|||||||
fIndex(index),
|
fIndex(index),
|
||||||
fRawFD(rawFD)
|
fRawFD(rawFD)
|
||||||
{
|
{
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.endpoint.descriptor = &fDescriptor;
|
command.endpoint.descriptor = &fDescriptor;
|
||||||
command.endpoint.config_index = fInterface->Configuration()->Index();
|
command.endpoint.config_index = fInterface->Configuration()->Index();
|
||||||
command.endpoint.interface_index = fInterface->Index();
|
command.endpoint.interface_index = fInterface->Index();
|
||||||
command.endpoint.endpoint_index = fIndex;
|
command.endpoint.endpoint_index = fIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR, &command,
|
||||||
|| command.config.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.config.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +131,7 @@ BUSBEndpoint::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.control.request_type = requestType;
|
command.control.request_type = requestType;
|
||||||
command.control.request = request;
|
command.control.request = request;
|
||||||
command.control.value = value;
|
command.control.value = value;
|
||||||
@@ -140,10 +139,9 @@ BUSBEndpoint::ControlTransfer(uint8 requestType, uint8 request, uint16 value,
|
|||||||
command.control.length = length;
|
command.control.length = length;
|
||||||
command.control.data = data;
|
command.control.data = data;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_CONTROL_TRANSFER, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_CONTROL_TRANSFER, &command,
|
||||||
|| command.control.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.control.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return command.control.length;
|
return command.control.length;
|
||||||
}
|
}
|
||||||
@@ -155,16 +153,15 @@ BUSBEndpoint::InterruptTransfer(void *data, size_t length) const
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.transfer.interface = fInterface->Index();
|
command.transfer.interface = fInterface->Index();
|
||||||
command.transfer.endpoint = fIndex;
|
command.transfer.endpoint = fIndex;
|
||||||
command.transfer.data = data;
|
command.transfer.data = data;
|
||||||
command.transfer.length = length;
|
command.transfer.length = length;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_INTERRUPT_TRANSFER, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_INTERRUPT_TRANSFER, &command,
|
||||||
|| command.transfer.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.transfer.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return command.transfer.length;
|
return command.transfer.length;
|
||||||
}
|
}
|
||||||
@@ -176,16 +173,15 @@ BUSBEndpoint::BulkTransfer(void *data, size_t length) const
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.transfer.interface = fInterface->Index();
|
command.transfer.interface = fInterface->Index();
|
||||||
command.transfer.endpoint = fIndex;
|
command.transfer.endpoint = fIndex;
|
||||||
command.transfer.data = data;
|
command.transfer.data = data;
|
||||||
command.transfer.length = length;
|
command.transfer.length = length;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_BULK_TRANSFER, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_BULK_TRANSFER, &command,
|
||||||
|| command.transfer.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.transfer.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return command.transfer.length;
|
return command.transfer.length;
|
||||||
}
|
}
|
||||||
@@ -198,7 +194,7 @@ BUSBEndpoint::IsochronousTransfer(void *data, size_t length,
|
|||||||
if (length > 0 && data == NULL)
|
if (length > 0 && data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.isochronous.interface = fInterface->Index();
|
command.isochronous.interface = fInterface->Index();
|
||||||
command.isochronous.endpoint = fIndex;
|
command.isochronous.endpoint = fIndex;
|
||||||
command.isochronous.data = data;
|
command.isochronous.data = data;
|
||||||
@@ -206,10 +202,9 @@ BUSBEndpoint::IsochronousTransfer(void *data, size_t length,
|
|||||||
command.isochronous.packet_descriptors = packetDescriptors;
|
command.isochronous.packet_descriptors = packetDescriptors;
|
||||||
command.isochronous.packet_count = packetCount;
|
command.isochronous.packet_count = packetCount;
|
||||||
|
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_ISOCHRONOUS_TRANSFER, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER, &command,
|
||||||
|| command.isochronous.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.isochronous.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return command.isochronous.length;
|
return command.isochronous.length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,16 +110,15 @@ BUSBInterface::OtherDescriptorAt(uint32 index, usb_descriptor *descriptor,
|
|||||||
if (length > 0 && descriptor == NULL)
|
if (length > 0 && descriptor == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.generic.descriptor = descriptor;
|
command.generic.descriptor = descriptor;
|
||||||
command.generic.config_index = fConfiguration->Index();
|
command.generic.config_index = fConfiguration->Index();
|
||||||
command.generic.interface_index = fIndex;
|
command.generic.interface_index = fIndex;
|
||||||
command.generic.length = length;
|
command.generic.length = length;
|
||||||
command.generic.generic_index = index;
|
command.generic.generic_index = index;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_GENERIC_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR, &command,
|
||||||
|| command.generic.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.generic.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -146,14 +145,13 @@ uint32
|
|||||||
BUSBInterface::CountAlternates() const
|
BUSBInterface::CountAlternates() const
|
||||||
{
|
{
|
||||||
uint32 alternateCount;
|
uint32 alternateCount;
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.alternate.alternate_count = &alternateCount;
|
command.alternate.alternate_count = &alternateCount;
|
||||||
command.alternate.config_index = fConfiguration->Index();
|
command.alternate.config_index = fConfiguration->Index();
|
||||||
command.alternate.interface_index = fIndex;
|
command.alternate.interface_index = fIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT, &command,
|
||||||
|| command.alternate.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
return alternateCount;
|
return alternateCount;
|
||||||
}
|
}
|
||||||
@@ -167,13 +165,13 @@ BUSBInterface::AlternateAt(uint32 alternateIndex)
|
|||||||
if (descriptor == NULL)
|
if (descriptor == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.alternate.descriptor = descriptor;
|
command.alternate.descriptor = descriptor;
|
||||||
command.alternate.config_index = fConfiguration->Index();
|
command.alternate.config_index = fConfiguration->Index();
|
||||||
command.alternate.interface_index = fIndex;
|
command.alternate.interface_index = fIndex;
|
||||||
command.alternate.alternate_index = alternateIndex;
|
command.alternate.alternate_index = alternateIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &command,
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_ALT_INTERFACE_DESCRIPTOR, &command,
|
||||||
sizeof(command)) || command.alternate.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS) {
|
||||||
delete descriptor;
|
delete descriptor;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -185,14 +183,13 @@ BUSBInterface::AlternateAt(uint32 alternateIndex)
|
|||||||
status_t
|
status_t
|
||||||
BUSBInterface::SetAlternate(uint32 alternateIndex)
|
BUSBInterface::SetAlternate(uint32 alternateIndex)
|
||||||
{
|
{
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.alternate.config_index = fConfiguration->Index();
|
command.alternate.config_index = fConfiguration->Index();
|
||||||
command.alternate.interface_index = fIndex;
|
command.alternate.interface_index = fIndex;
|
||||||
command.alternate.alternate_index = alternateIndex;
|
command.alternate.alternate_index = alternateIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_SET_ALT_INTERFACE, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_SET_ALT_INTERFACE, &command,
|
||||||
|| command.alternate.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.alternate.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
_UpdateDescriptorAndEndpoints();
|
_UpdateDescriptorAndEndpoints();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -202,14 +199,13 @@ BUSBInterface::SetAlternate(uint32 alternateIndex)
|
|||||||
void
|
void
|
||||||
BUSBInterface::_UpdateDescriptorAndEndpoints()
|
BUSBInterface::_UpdateDescriptorAndEndpoints()
|
||||||
{
|
{
|
||||||
raw_command command;
|
usb_raw_command command;
|
||||||
command.interface.descriptor = &fDescriptor;
|
command.interface.descriptor = &fDescriptor;
|
||||||
command.interface.config_index = fConfiguration->Index();
|
command.interface.config_index = fConfiguration->Index();
|
||||||
command.interface.interface_index = fIndex;
|
command.interface.interface_index = fIndex;
|
||||||
if (ioctl(fRawFD, RAW_COMMAND_GET_INTERFACE_DESCRIPTOR, &command, sizeof(command))
|
if (ioctl(fRawFD, B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR, &command,
|
||||||
|| command.interface.status != RAW_STATUS_SUCCESS) {
|
sizeof(command)) || command.interface.status != B_USB_RAW_STATUS_SUCCESS)
|
||||||
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
memset(&fDescriptor, 0, sizeof(fDescriptor));
|
||||||
}
|
|
||||||
|
|
||||||
if (fEndpoints) {
|
if (fEndpoints) {
|
||||||
// Delete old endpoints
|
// Delete old endpoints
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <USBKit.h>
|
#include <USBKit.h>
|
||||||
#include <usb_raw.h>
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user