Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmisc.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Universal Serial Bus Hub Driver 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: drivers/usb/usbhub/fdo.c 00005 * PURPOSE: Misc helper functions 00006 * PROGRAMMERS: 00007 * Michael Martin (michael.martin@reactos.org) 00008 * Johannes Anderwald (johannes.anderwald@reactos.org) 00009 */ 00010 #include "usbhub.h" 00011 #include <stdarg.h> 00012 00013 VOID 00014 DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor) 00015 { 00016 DPRINT1("Dumping Device Descriptor %x\n", DeviceDescriptor); 00017 DPRINT1("bLength %x\n", DeviceDescriptor->bLength); 00018 DPRINT1("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType); 00019 DPRINT1("bcdUSB %x\n", DeviceDescriptor->bcdUSB); 00020 DPRINT1("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass); 00021 DPRINT1("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass); 00022 DPRINT1("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol); 00023 DPRINT1("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0); 00024 DPRINT1("idVendor %x\n", DeviceDescriptor->idVendor); 00025 DPRINT1("idProduct %x\n", DeviceDescriptor->idProduct); 00026 DPRINT1("bcdDevice %x\n", DeviceDescriptor->bcdDevice); 00027 DPRINT1("iManufacturer %x\n", DeviceDescriptor->iManufacturer); 00028 DPRINT1("iProduct %x\n", DeviceDescriptor->iProduct); 00029 DPRINT1("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber); 00030 DPRINT1("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations); 00031 } 00032 00033 //---------------------------------------------------------------------------------------- 00034 VOID 00035 DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor) 00036 { 00037 DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor); 00038 DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength); 00039 DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType); 00040 DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength); 00041 DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces); 00042 DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue); 00043 DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration); 00044 DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes); 00045 DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower); 00046 } 00047 00048 VOID 00049 DumpFullConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor) 00050 { 00051 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; 00052 PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor; 00053 LONG i, j; 00054 00055 DPRINT1("Dumping ConfigurationDescriptor %x\n", ConfigurationDescriptor); 00056 DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength); 00057 DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType); 00058 DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength); 00059 DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces); 00060 DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue); 00061 DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration); 00062 DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes); 00063 DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower); 00064 00065 InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) ((ULONG_PTR)ConfigurationDescriptor + sizeof(USB_CONFIGURATION_DESCRIPTOR)); 00066 00067 for (i=0; i < ConfigurationDescriptor->bNumInterfaces; i++) 00068 { 00069 DPRINT1("- Dumping InterfaceDescriptor %x\n", InterfaceDescriptor); 00070 DPRINT1(" bLength %x\n", InterfaceDescriptor->bLength); 00071 DPRINT1(" bDescriptorType %x\n", InterfaceDescriptor->bDescriptorType); 00072 DPRINT1(" bInterfaceNumber %x\n", InterfaceDescriptor->bInterfaceNumber); 00073 DPRINT1(" bAlternateSetting %x\n", InterfaceDescriptor->bAlternateSetting); 00074 DPRINT1(" bNumEndpoints %x\n", InterfaceDescriptor->bNumEndpoints); 00075 DPRINT1(" bInterfaceClass %x\n", InterfaceDescriptor->bInterfaceClass); 00076 DPRINT1(" bInterfaceSubClass %x\n", InterfaceDescriptor->bInterfaceSubClass); 00077 DPRINT1(" bInterfaceProtocol %x\n", InterfaceDescriptor->bInterfaceProtocol); 00078 DPRINT1(" iInterface %x\n", InterfaceDescriptor->iInterface); 00079 00080 EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)InterfaceDescriptor + sizeof(USB_INTERFACE_DESCRIPTOR)); 00081 00082 for (j=0; j < InterfaceDescriptor->bNumEndpoints; j++) 00083 { 00084 DPRINT1(" bLength %x\n", EndpointDescriptor->bLength); 00085 DPRINT1(" bDescriptorType %x\n", EndpointDescriptor->bDescriptorType); 00086 DPRINT1(" bEndpointAddress %x\n", EndpointDescriptor->bEndpointAddress); 00087 DPRINT1(" bmAttributes %x\n", EndpointDescriptor->bmAttributes); 00088 DPRINT1(" wMaxPacketSize %x\n", EndpointDescriptor->wMaxPacketSize); 00089 DPRINT1(" bInterval %x\n", EndpointDescriptor->bInterval); 00090 EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) ((ULONG_PTR)EndpointDescriptor + sizeof(USB_ENDPOINT_DESCRIPTOR)); 00091 } 00092 InterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR)(ULONG_PTR)EndpointDescriptor; 00093 } 00094 } 00095 00096 NTSTATUS 00097 NTAPI 00098 ForwardIrpAndWaitCompletion( 00099 IN PDEVICE_OBJECT DeviceObject, 00100 IN PIRP Irp, 00101 IN PVOID Context) 00102 { 00103 if (Irp->PendingReturned) 00104 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE); 00105 00106 return STATUS_MORE_PROCESSING_REQUIRED; 00107 } 00108 00109 NTSTATUS 00110 ForwardIrpAndWait( 00111 IN PDEVICE_OBJECT DeviceObject, 00112 IN PIRP Irp) 00113 { 00114 KEVENT Event; 00115 NTSTATUS Status; 00116 00117 KeInitializeEvent(&Event, NotificationEvent, FALSE); 00118 IoCopyCurrentIrpStackLocationToNext(Irp); 00119 00120 IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE); 00121 00122 Status = IoCallDriver(DeviceObject, Irp); 00123 if (Status == STATUS_PENDING) 00124 { 00125 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL); 00126 if (NT_SUCCESS(Status)) 00127 Status = Irp->IoStatus.Status; 00128 } 00129 00130 return Status; 00131 } 00132 00133 NTSTATUS 00134 ForwardIrpAndForget( 00135 IN PDEVICE_OBJECT DeviceObject, 00136 IN PIRP Irp) 00137 { 00138 PDEVICE_OBJECT LowerDevice = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDeviceObject; 00139 00140 ASSERT(LowerDevice); 00141 00142 IoSkipCurrentIrpStackLocation(Irp); 00143 return IoCallDriver(LowerDevice, Irp); 00144 } 00145 00146 NTSTATUS 00147 SubmitRequestToRootHub( 00148 IN PDEVICE_OBJECT RootHubDeviceObject, 00149 IN ULONG IoControlCode, 00150 OUT PVOID OutParameter1, 00151 OUT PVOID OutParameter2) 00152 { 00153 KEVENT Event; 00154 PIRP Irp; 00155 IO_STATUS_BLOCK IoStatus; 00156 NTSTATUS Status; 00157 PIO_STACK_LOCATION Stack = NULL; 00158 00159 KeInitializeEvent(&Event, NotificationEvent, FALSE); 00160 00161 // 00162 // Build Control Request 00163 // 00164 Irp = IoBuildDeviceIoControlRequest(IoControlCode, 00165 RootHubDeviceObject, 00166 NULL, 0, 00167 NULL, 0, 00168 TRUE, 00169 &Event, 00170 &IoStatus); 00171 00172 if (Irp == NULL) 00173 { 00174 DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n"); 00175 return STATUS_INSUFFICIENT_RESOURCES; 00176 } 00177 00178 // 00179 // Initialize the status block before sending the IRP 00180 // 00181 IoStatus.Status = STATUS_NOT_SUPPORTED; 00182 IoStatus.Information = 0; 00183 00184 // 00185 // Get Next Stack Location and Initialize it 00186 // 00187 Stack = IoGetNextIrpStackLocation(Irp); 00188 Stack->Parameters.Others.Argument1 = OutParameter1; 00189 Stack->Parameters.Others.Argument2 = OutParameter2; 00190 00191 // 00192 // Call RootHub 00193 // 00194 Status = IoCallDriver(RootHubDeviceObject, Irp); 00195 00196 // 00197 // Its ok to block here as this function is called in an nonarbitrary thread 00198 // 00199 if (Status == STATUS_PENDING) 00200 { 00201 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL); 00202 Status = IoStatus.Status; 00203 } 00204 00205 // 00206 // The IO Manager will free the IRP 00207 // 00208 00209 return Status; 00210 } 00211 00212 NTSTATUS 00213 NTAPI 00214 FDO_QueryInterfaceCompletionRoutine( 00215 IN PDEVICE_OBJECT DeviceObject, 00216 IN PIRP Irp, 00217 IN PVOID Context) 00218 { 00219 /* Set event */ 00220 KeSetEvent((PRKEVENT)Context, 0, FALSE); 00221 00222 /* Completion is done in the HidClassFDO_QueryCapabilities routine */ 00223 return STATUS_MORE_PROCESSING_REQUIRED; 00224 } 00225 00226 NTSTATUS 00227 FDO_QueryInterface( 00228 IN PDEVICE_OBJECT DeviceObject, 00229 IN OUT PUSB_BUS_INTERFACE_USBDI_V2 Interface) 00230 { 00231 PIRP Irp; 00232 KEVENT Event; 00233 NTSTATUS Status; 00234 PIO_STACK_LOCATION IoStack; 00235 PHUB_DEVICE_EXTENSION HubDeviceExtension; 00236 00237 /* Get device extension */ 00238 HubDeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension; 00239 ASSERT(HubDeviceExtension->Common.IsFDO); 00240 00241 /* Init event */ 00242 KeInitializeEvent(&Event, NotificationEvent, FALSE); 00243 00244 /* Now allocte the irp */ 00245 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); 00246 if (!Irp) 00247 { 00248 /* No memory */ 00249 return STATUS_INSUFFICIENT_RESOURCES; 00250 } 00251 00252 /* Get next stack location */ 00253 IoStack = IoGetNextIrpStackLocation(Irp); 00254 00255 /* Init stack location */ 00256 IoStack->MajorFunction = IRP_MJ_PNP; 00257 IoStack->MinorFunction = IRP_MN_QUERY_INTERFACE; 00258 IoStack->Parameters.QueryInterface.Interface = (PINTERFACE)Interface; 00259 IoStack->Parameters.QueryInterface.InterfaceType = &USB_BUS_INTERFACE_USBDI_GUID; 00260 IoStack->Parameters.QueryInterface.Version = USB_BUSIF_USBDI_VERSION_2; 00261 IoStack->Parameters.QueryInterface.Size = sizeof(USB_BUS_INTERFACE_USBDI_V2); 00262 00263 00264 /* Set completion routine */ 00265 IoSetCompletionRoutine(Irp, 00266 FDO_QueryInterfaceCompletionRoutine, 00267 (PVOID)&Event, 00268 TRUE, 00269 TRUE, 00270 TRUE); 00271 00272 /* Pnp irps have default completion code */ 00273 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; 00274 00275 /* Call lower device */ 00276 Status = IoCallDriver(HubDeviceExtension->LowerDeviceObject, Irp); 00277 if (Status == STATUS_PENDING) 00278 { 00279 /* Wait for completion */ 00280 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); 00281 } 00282 00283 /* Get status */ 00284 Status = Irp->IoStatus.Status; 00285 00286 /* Complete request */ 00287 IoFreeIrp(Irp); 00288 00289 /* Done */ 00290 return Status; 00291 } Generated on Sat May 26 2012 04:15:48 for ReactOS by
1.7.6.1
|