че та.... не надо грязи!!!!! :nottrue:)
do
{
// we need to allocate an URB to talk
// to usb bus driver
urb = (PURB)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(URB),
USB_FTDI_POOL_TAG
);
if (urb == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
// first let's read device descriptor
deviceDescriptor = (PUSB_DEVICE_DESCRIPTOR)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(USB_DEVICE_DESCRIPTOR),
USB_FTDI_POOL_TAG
);
if (deviceDescriptor == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
UsbBuildGetDescriptorRequest(
urb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
deviceDescriptor,
NULL,
sizeof(USB_DEVICE_DESCRIPTOR),
NULL
);
status = usb_ftdiSubmitUrbSynch(DeviceExtension, urb);
if (!NT_SUCCESS(status))
{
break;
}
// We have to read configuration descriptor twice.
// First time to obtain its full length and second time
// to read full configuration descriptor
configDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(USB_CONFIGURATION_DESCRIPTOR),
USB_FTDI_POOL_TAG
);
if (configDescriptor == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
UsbBuildGetDescriptorRequest(
urb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
USB_CONFIGURATION_DESCRIPTOR_TYPE,
0,
0,
configDescriptor,
NULL,
sizeof(USB_CONFIGURATION_DESCRIPTOR),
NULL
);
status = usb_ftdiSubmitUrbSynch(DeviceExtension, urb);
if (!NT_SUCCESS(status))
{
break;
}
size = configDescriptor->wTotalLength;
ExFreePool(configDescriptor);
configDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ExAllocatePoolWithTag(
NonPagedPool,
size,
USB_FTDI_POOL_TAG
);
if (configDescriptor == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
UsbBuildGetDescriptorRequest(
urb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
USB_CONFIGURATION_DESCRIPTOR_TYPE,
0,
0,
configDescriptor,
NULL,
size,
NULL
);
status = usb_ftdiSubmitUrbSynch(DeviceExtension, urb);
if (!NT_SUCCESS(status))
{
break;
}
// now that we have configuration descriptor lets find our interface
// and enable it
numInterfaces = configDescriptor->bNumInterfaces;
interfaceBuffer = interfaceList =
(PUSBD_INTERFACE_LIST_ENTRY)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(USBD_INTERFACE_LIST_ENTRY) * (numInterfaces + 1),
USB_FTDI_POOL_TAG
);
if (interfaceBuffer == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
for (index = 0; index < numInterfaces; ++index)
{
interfaceDescriptor = USBD_ParseConfigurationDescriptorEx(
configDescriptor,
configDescriptor,
index,
0,
-1,
-1,
-1
);
if (interfaceDescriptor != NULL)
{
interfaceList->InterfaceDescriptor = interfaceDescriptor;
interfaceList->Interface = NULL;
++interfaceList;
}
}
interfaceList->InterfaceDescriptor = NULL;
interfaceList->Interface = NULL;
ExFreePool(urb);
urb = USBD_CreateConfigurationRequestEx(configDescriptor, interfaceBuffer);
if (urb == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
interfaceInfo = &urb->UrbSelectConfiguration.Interface;
// verify configuration
interfaceDescriptor = interfaceBuffer->InterfaceDescriptor;
if (interfaceDescriptor->bNumEndpoints != 2)
{
status = STATUS_DEVICE_CONFIGURATION_ERROR;
break;
}
epDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)interfaceDescriptor;
epDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)USBD_ParseDescriptors(
configDescriptor,
configDescriptor->wTotalLength,
epDescriptor,
USB_ENDPOINT_DESCRIPTOR_TYPE
);
if ((epDescriptor == NULL) ||
(epDescriptor->bEndpointAddress != 0x81) ||
(epDescriptor->bmAttributes != USB_ENDPOINT_TYPE_BULK) ||
(epDescriptor->wMaxPacketSize != 64))
{
status = STATUS_DEVICE_CONFIGURATION_ERROR;
break;
}
else
{
interfaceInfo->Pipes[0].MaximumTransferSize = 4096;
++epDescriptor;
}
epDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)USBD_ParseDescriptors(
configDescriptor,
configDescriptor->wTotalLength,
epDescriptor,
USB_ENDPOINT_DESCRIPTOR_TYPE
);
if ((epDescriptor == NULL) ||
(epDescriptor->bEndpointAddress != 0x2) ||
(epDescriptor->bmAttributes != USB_ENDPOINT_TYPE_BULK) ||
(epDescriptor->wMaxPacketSize != 64))
{
status = STATUS_DEVICE_CONFIGURATION_ERROR;
break;
}
else
{
interfaceInfo->Pipes[1].MaximumTransferSize = 4096;
++epDescriptor;
}
status = usb_ftdiSubmitUrbSynch(DeviceExtension, urb);
if (!NT_SUCCESS(status))
{
break;
}
DeviceExtension->InterfaceInformation =
(PUSBD_INTERFACE_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,
interfaceInfo->Length,
USB_FTDI_POOL_TAG
);
if (DeviceExtension->InterfaceInformation == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
RtlCopyMemory(DeviceExtension->InterfaceInformation, interfaceInfo, interfaceInfo->Length);
DeviceExtension->ConfigHandle = urb->UrbSelectConfiguration.ConfigurationHandle;
DeviceExtension->ConfigDescriptor = configDescriptor;
configDescriptor = NULL;
}
while (FALSE);