阅读:2496回复:2
usb驱动只能写不能读
读代码如下:
void UC_ReadWriteEndpoints( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN ULONG Length, IN WDF_REQUEST_TYPE RequestType) { size_t totalLength = Length; size_t stageLength = 0; NTSTATUS status; PVOID virtualAddress = 0; PREQUEST_CONTEXT pRequestContext = NULL; WDFUSBPIPE pipe; WDFMEMORY memory; WDFMEMORY_OFFSET offset; WDF_OBJECT_ATTRIBUTES objectAttributes; PDEVICE_CONTEXT pDeviceContext; UC_DbgPrint(3, ("UC_ReadWriteEndpoints - begin, Length:%x\n", Length)); // First validate input parameters. pDeviceContext = GetDeviceContext(WdfIoQueueGetDevice(Queue)); if (totalLength > pDeviceContext->MaxTransferSize) { UC_DbgPrint(1, ("Transfer length > circular buffer\n")); status = STATUS_INVALID_PARAMETER; goto Exit; } if ((RequestType != WdfRequestTypeRead) && (RequestType != WdfRequestTypeWrite)) { UC_DbgPrint(1, ("RequestType has to be either read or write\n")); status = STATUS_INVALID_PARAMETER; goto Exit; } // Get the pipe associate with this request. pRequestContext = GetRequestContext(Request); if (RequestType == WdfRequestTypeRead) { status = WdfRequestRetrieveOutputBuffer(Request, Length, &virtualAddress, &totalLength); pipe = pDeviceContext->interruptReadPipe; pRequestContext->Read = TRUE; } else { status = WdfRequestRetrieveInputBuffer(Request, Length, &virtualAddress, &totalLength); pipe = pDeviceContext->interruptWritePipe; pRequestContext->Read = FALSE; } if (!NT_SUCCESS(status)) { UC_DbgPrint(1, ("WdfRequestRetrieveInputBuffer failed\n")); goto Exit; } // If the totalLength exceeds MAX_TRANSFER_SIZE, we will break // that into multiple transfer of size no more than MAX_TRANSFER_SIZE // in each stage. if (totalLength > MAX_TRANSFER_SIZE) { stageLength = MAX_TRANSFER_SIZE; } else { stageLength = totalLength; } WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes); objectAttributes.ParentObject = Request; status = WdfMemoryCreatePreallocated( &objectAttributes, virtualAddress, totalLength, &memory); if (!NT_SUCCESS(status)) { UC_DbgPrint(1, ("WdfMemoryCreatePreallocated failed\n")); goto Exit; } offset.BufferOffset = 0; offset.BufferLength = stageLength; // The framework format call validates to make sure that you are reading or // writing to the right pipe type, set the appropriate transfer flags, creates an // URB and initailzes the request. if (RequestType == WdfRequestTypeRead) { status = WdfUsbTargetPipeFormatRequestForRead( pipe, Request, memory, &offset); } else { status = WdfUsbTargetPipeFormatRequestForWrite( pipe, Request, memory, &offset); } if (!NT_SUCCESS(status)) { UC_DbgPrint(1, ("WdfUsbTargetPipeFormatRequest failed 0x%x\n", status)); goto Exit; } WdfRequestSetCompletionRoutine( Request, UC_ReadWriteCompletion, NULL); // Set REQUEST_CONTEXT parameters. pRequestContext->Length = totalLength - stageLength; pRequestContext->Numxfer = 0; // Send the request asynchronously if (!WdfRequestSend(Request, WdfUsbTargetPipeGetIoTarget(pipe), WDF_NO_SEND_OPTIONS)) { UC_DbgPrint(1, ("WdfRequestSend failed\n")); status = WdfRequestGetStatus(Request); goto Exit; } Exit: if (!NT_SUCCESS(status)) { WdfRequestCompleteWithInformation(Request, status, 0); } UC_DbgPrint(3, ("UC_ReadWriteEndpoints - ends\n")); return; } 使用usb hound read 看不到任何irp urb |
|
|
沙发#
发布于:2013-01-26 21:37
pDeviceContext->BulkReadPipe = WdfUsbInterfaceGetConfiguredPipe(
pDeviceContext->UsbInterface, BULK_IN_ENDPOINT_INDEX, NULL); 你还是先找一下这一句里面的BULK_IN_ENDPOINT_INDEX的定义吧 |
|
|
板凳#
发布于:2014-01-09 15:18
问题已解决,读buffer必须是pipe最大值得整数倍
|
|
|