ReactOS  0.4.15-dev-309-g7c8d563
hidusb.h File Reference
#include <ntddk.h>
#include <hidport.h>
#include <debug.h>
#include <hubbusif.h>
#include <usbbusif.h>
#include <usbioctl.h>
#include <usb.h>
#include <usbdlib.h>
Include dependency graph for hidusb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  HID_USB_DEVICE_EXTENSION
 
struct  HID_USB_RESET_CONTEXT
 

Macros

#define _HIDPI_
 
#define _HIDPI_NO_FUNCTION_MACROS_
 
#define NDEBUG
 
#define USB_SET_IDLE_REQUEST   0xA
 
#define USB_GET_PROTOCOL_REQUEST   0x3
 
#define HIDUSB_TAG   'UdiH'
 
#define HIDUSB_URB_TAG   'rUiH'
 

Typedefs

typedef struct HID_USB_DEVICE_EXTENSIONPHID_USB_DEVICE_EXTENSION
 
typedef struct HID_USB_RESET_CONTEXTPHID_USB_RESET_CONTEXT
 

Functions

NTSTATUS Hid_GetDescriptor (IN PDEVICE_OBJECT DeviceObject, IN USHORT UrbFunction, IN USHORT UrbLength, IN OUT PVOID *UrbBuffer, IN OUT PULONG UrbBufferLength, IN UCHAR DescriptorType, IN UCHAR Index, IN USHORT LanguageIndex)
 
NTSTATUS Hid_DispatchUrb (IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
 

Macro Definition Documentation

◆ _HIDPI_

#define _HIDPI_

Definition at line 3 of file hidusb.h.

◆ _HIDPI_NO_FUNCTION_MACROS_

#define _HIDPI_NO_FUNCTION_MACROS_

Definition at line 4 of file hidusb.h.

◆ HIDUSB_TAG

#define HIDUSB_TAG   'UdiH'

Definition at line 90 of file hidusb.h.

◆ HIDUSB_URB_TAG

#define HIDUSB_URB_TAG   'rUiH'

Definition at line 91 of file hidusb.h.

◆ NDEBUG

#define NDEBUG

Definition at line 5 of file hidusb.h.

◆ USB_GET_PROTOCOL_REQUEST

#define USB_GET_PROTOCOL_REQUEST   0x3

Definition at line 88 of file hidusb.h.

◆ USB_SET_IDLE_REQUEST

#define USB_SET_IDLE_REQUEST   0xA

Definition at line 87 of file hidusb.h.

Typedef Documentation

◆ PHID_USB_DEVICE_EXTENSION

◆ PHID_USB_RESET_CONTEXT

Function Documentation

◆ Hid_DispatchUrb()

NTSTATUS Hid_DispatchUrb ( IN PDEVICE_OBJECT  DeviceObject,
IN PURB  Urb 
)

Definition at line 960 of file hidusb.c.

963 {
964  PIRP Irp;
965  KEVENT Event;
966  PHID_DEVICE_EXTENSION DeviceExtension;
968  PIO_STACK_LOCATION IoStack;
970 
971  //
972  // init event
973  //
975 
976  //
977  // get device extension
978  //
979  DeviceExtension = DeviceObject->DeviceExtension;
980 
981  //
982  // build irp
983  //
985  DeviceExtension->NextDeviceObject,
986  NULL,
987  0,
988  NULL,
989  0,
990  TRUE,
991  &Event,
992  &IoStatus);
993  if (!Irp)
994  {
995  //
996  // no memory
997  //
999  }
1000 
1001  //
1002  // get next stack location
1003  //
1004  IoStack = IoGetNextIrpStackLocation(Irp);
1005 
1006  //
1007  // store urb
1008  //
1009  IoStack->Parameters.Others.Argument1 = Urb;
1010 
1011  //
1012  // set completion routine
1013  //
1015 
1016  //
1017  // call driver
1018  //
1019  Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
1020 
1021  //
1022  // wait for the request to finish
1023  //
1024  if (Status == STATUS_PENDING)
1025  {
1027  }
1028 
1029  //
1030  // complete request
1031  //
1033 
1034  if (Status == STATUS_PENDING)
1035  {
1036  //
1037  // get final status
1038  //
1039  Status = IoStatus.Status;
1040  }
1041 
1042  DPRINT("[HIDUSB] DispatchUrb %x\n", Status);
1043 
1044 
1045  //
1046  // done
1047  //
1048  return Status;
1049 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
NTSTATUS NTAPI Hid_PnpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: hidusb.c:943
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT NextDeviceObject
Definition: hidport.h:18
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by Hid_DisableConfiguration(), Hid_GetDescriptor(), Hid_GetProtocol(), Hid_SelectConfiguration(), Hid_SetIdle(), HidUsb_AbortPipe(), and HidUsb_ResetInterruptPipe().

◆ Hid_GetDescriptor()

NTSTATUS Hid_GetDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN USHORT  UrbFunction,
IN USHORT  UrbLength,
IN OUT PVOID UrbBuffer,
IN OUT PULONG  UrbBufferLength,
IN UCHAR  DescriptorType,
IN UCHAR  Index,
IN USHORT  LanguageIndex 
)

Definition at line 1052 of file hidusb.c.

1061 {
1062  PURB Urb;
1063  NTSTATUS Status;
1064  UCHAR Allocated = FALSE;
1065 
1066  //
1067  // allocate urb
1068  //
1070  if (!Urb)
1071  {
1072  //
1073  // no memory
1074  //
1076  }
1077 
1078  //
1079  // is there an urb buffer
1080  //
1081  if (!*UrbBuffer)
1082  {
1083  //
1084  // allocate buffer
1085  //
1086  *UrbBuffer = ExAllocatePoolWithTag(NonPagedPool, *UrbBufferLength, HIDUSB_TAG);
1087  if (!*UrbBuffer)
1088  {
1089  //
1090  // no memory
1091  //
1094  }
1095 
1096  //
1097  // zero buffer
1098  //
1099  RtlZeroMemory(*UrbBuffer, *UrbBufferLength);
1100  Allocated = TRUE;
1101  }
1102 
1103  //
1104  // zero urb
1105  //
1106  RtlZeroMemory(Urb, UrbLength);
1107 
1108  //
1109  // build descriptor request
1110  //
1111  UsbBuildGetDescriptorRequest(Urb, UrbLength, DescriptorType, Index, LanguageIndex, *UrbBuffer, NULL, *UrbBufferLength, NULL);
1112 
1113  //
1114  // set urb function
1115  //
1116  Urb->UrbHeader.Function = UrbFunction;
1117 
1118  //
1119  // dispatch urb
1120  //
1122 
1123  //
1124  // did the request fail
1125  //
1126  if (!NT_SUCCESS(Status))
1127  {
1128  if (Allocated)
1129  {
1130  //
1131  // free allocated buffer
1132  //
1133  ExFreePoolWithTag(*UrbBuffer, HIDUSB_TAG);
1134  *UrbBuffer = NULL;
1135  }
1136 
1137  //
1138  // free urb
1139  //
1141  *UrbBufferLength = 0;
1142  return Status;
1143  }
1144 
1145  //
1146  // did urb request fail
1147  //
1148  if (!NT_SUCCESS(Urb->UrbHeader.Status))
1149  {
1150  if (Allocated)
1151  {
1152  //
1153  // free allocated buffer
1154  //
1155  ExFreePoolWithTag(*UrbBuffer, HIDUSB_TAG);
1156  *UrbBuffer = NULL;
1157  }
1158 
1159  //
1160  // free urb
1161  //
1163  *UrbBufferLength = 0;
1164  return STATUS_UNSUCCESSFUL;
1165  }
1166 
1167  //
1168  // store result length
1169  //
1170  *UrbBufferLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
1171 
1172  //
1173  // free urb
1174  //
1176 
1177  //
1178  // completed successfully
1179  //
1180  return STATUS_SUCCESS;
1181 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
IN PFCB IN VBO OUT PLBO OUT PULONG OUT PBOOLEAN Allocated
Definition: fatprocs.h:297
smooth NULL
Definition: ftsmooth.c:416
struct _URB_HEADER UrbHeader
Definition: usb.h:531
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
#define HIDUSB_TAG
Definition: hidusb.h:90
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: usb.h:529
#define HIDUSB_URB_TAG
Definition: hidusb.h:91
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
NTSTATUS Hid_DispatchUrb(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
Definition: hidusb.c:960
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
return STATUS_SUCCESS
Definition: btrfs.c:3014
_In_ ULONG _In_ PVOID _In_ LONG DescriptorType
Definition: usbdlib.h:145

Referenced by Hid_PnpStart(), and HidUsb_GetReportDescriptor().