ReactOS 0.4.16-dev-1040-g85afe48
fdo.c File Reference
#include "usbccgp.h"
#include <debug.h>
Include dependency graph for fdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI FDO_QueryCapabilitiesCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS FDO_QueryCapabilities (IN PDEVICE_OBJECT DeviceObject, IN OUT PDEVICE_CAPABILITIES Capabilities)
 
NTSTATUS FDO_DeviceRelations (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_CreateChildPdo (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS FDO_StartDevice (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_CloseConfiguration (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS FDO_HandlePnp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_HandleResetCyclePort (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_HandleInternalDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_HandleSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FDO_Dispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file fdo.c.

Function Documentation

◆ FDO_CloseConfiguration()

NTSTATUS FDO_CloseConfiguration ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 345 of file fdo.c.

347{
349 PURB Urb;
350 PFDO_DEVICE_EXTENSION FDODeviceExtension;
351
352 /* Get device extension */
353 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
354 ASSERT(FDODeviceExtension->Common.IsFDO);
355
356 /* Nothing to do if we're not configured */
357 if (FDODeviceExtension->ConfigurationDescriptor == NULL ||
358 FDODeviceExtension->InterfaceList == NULL)
359 {
360 return STATUS_SUCCESS;
361 }
362
363 /* Now allocate the urb */
364 Urb = USBD_CreateConfigurationRequestEx(FDODeviceExtension->ConfigurationDescriptor,
365 FDODeviceExtension->InterfaceList);
366 if (!Urb)
367 {
368 /* No memory */
370 }
371
372 /* Clear configuration descriptor to make it an unconfigure request */
373 Urb->UrbSelectConfiguration.ConfigurationDescriptor = NULL;
374
375 /* Submit urb */
376 Status = USBCCGP_SyncUrbRequest(FDODeviceExtension->NextDeviceObject, Urb);
377 if (!NT_SUCCESS(Status))
378 {
379 /* Failed to set configuration */
380 DPRINT1("USBCCGP_SyncUrbRequest failed to unconfigure device\n", Status);
381 }
382
383 ExFreePool(Urb);
384 return Status;
385}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:35
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
Definition: usb.h:529
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by FDO_HandlePnp().

◆ FDO_CreateChildPdo()

NTSTATUS FDO_CreateChildPdo ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 169 of file fdo.c.

171{
173 PDEVICE_OBJECT PDODeviceObject;
174 PPDO_DEVICE_EXTENSION PDODeviceExtension;
175 PFDO_DEVICE_EXTENSION FDODeviceExtension;
176 ULONG Index;
177
178 /* Get device extension */
179 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
180 ASSERT(FDODeviceExtension->Common.IsFDO);
181
182 /* Lets create array for the child PDO */
183 FDODeviceExtension->ChildPDO = AllocateItem(NonPagedPool,
184 sizeof(PDEVICE_OBJECT) * FDODeviceExtension->FunctionDescriptorCount);
185 if (!FDODeviceExtension->ChildPDO)
186 {
187 /* No memory */
189 }
190
191 /* Create pdo for each function */
192 for (Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
193 {
194 if (FDODeviceExtension->FunctionDescriptor[Index].NumberOfInterfaces == 0)
195 {
196 // Ignore invalid devices
197 DPRINT1("[USBCCGP] Found descriptor with 0 interfaces\n");
198 continue;
199 }
200
201 /* Create the PDO */
202 Status = IoCreateDevice(FDODeviceExtension->DriverObject,
203 sizeof(PDO_DEVICE_EXTENSION),
204 NULL,
207 FALSE,
208 &PDODeviceObject);
209 if (!NT_SUCCESS(Status))
210 {
211 /* Failed to create device object */
212 DPRINT1("IoCreateDevice failed with %x\n", Status);
213 return Status;
214 }
215
216 /* Store in array */
217 FDODeviceExtension->ChildPDO[Index] = PDODeviceObject;
218
219 /* Get device extension */
220 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
221 RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
222
223 /* Init device extension */
224 PDODeviceExtension->Common.IsFDO = FALSE;
225 PDODeviceExtension->FunctionDescriptor = &FDODeviceExtension->FunctionDescriptor[Index];
226 PDODeviceExtension->NextDeviceObject = DeviceObject;
227 PDODeviceExtension->FunctionIndex = Index;
228 PDODeviceExtension->FDODeviceExtension = FDODeviceExtension;
229 PDODeviceExtension->InterfaceList = FDODeviceExtension->InterfaceList;
230 PDODeviceExtension->InterfaceListCount = FDODeviceExtension->InterfaceListCount;
231 PDODeviceExtension->ConfigurationHandle = FDODeviceExtension->ConfigurationHandle;
232 PDODeviceExtension->ConfigurationDescriptor = FDODeviceExtension->ConfigurationDescriptor;
233 RtlCopyMemory(&PDODeviceExtension->Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES));
234 RtlCopyMemory(&PDODeviceExtension->DeviceDescriptor, FDODeviceExtension->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR));
235
236 /* Patch the stack size */
237 PDODeviceObject->StackSize = DeviceObject->StackSize + 1;
238
239 /* Set device flags */
240 PDODeviceObject->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER;
241
242 /* Device is initialized */
243 PDODeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
244 }
245
246 /* Done */
247 return STATUS_SUCCESS;
248}
#define FALSE
Definition: types.h:117
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DO_MAP_IO_BUFFER
Definition: env_spec_w32.h:397
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDRIVER_OBJECT DriverObject
Definition: pciidex.h:88
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define FILE_DEVICE_USB
Definition: usbiodef.h:71
_In_ WDFCOLLECTION _In_ ULONG Index
DEVICE_CAPABILITIES
Definition: iotypes.h:965

Referenced by FDO_StartDevice().

◆ FDO_DeviceRelations()

NTSTATUS FDO_DeviceRelations ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 102 of file fdo.c.

105{
106 ULONG DeviceCount = 0;
107 ULONG Index;
108 PDEVICE_RELATIONS DeviceRelations;
109 PIO_STACK_LOCATION IoStack;
110 PFDO_DEVICE_EXTENSION FDODeviceExtension;
111
112 /* Get device extension */
113 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
114
115 /* Get current irp stack location */
117
118 /* Check if relation type is BusRelations */
119 if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations)
120 {
121 /* FDO always only handles bus relations */
122 return STATUS_SUCCESS;
123 }
124
125 /* Go through array and count device objects */
126 for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
127 {
128 if (FDODeviceExtension->ChildPDO[Index])
129 {
130 /* Child pdo */
131 DeviceCount++;
132 }
133 }
134
135 /* Allocate device relations */
136 DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool,
137 sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
138 if (!DeviceRelations)
139 {
140 /* No memory */
142 }
143
144 /* Add device objects */
145 for(Index = 0; Index < FDODeviceExtension->FunctionDescriptorCount; Index++)
146 {
147 if (FDODeviceExtension->ChildPDO[Index])
148 {
149 /* Store child pdo */
150 DeviceRelations->Objects[DeviceRelations->Count] = FDODeviceExtension->ChildPDO[Index];
151
152 /* Add reference */
153 ObReferenceObject(FDODeviceExtension->ChildPDO[Index]);
154
155 /* Increment count */
156 DeviceRelations->Count++;
157 }
158 }
159
160 /* Store result */
161 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
162 Irp->IoStatus.Status = STATUS_SUCCESS;
163
164 /* Request completed successfully */
165 return STATUS_SUCCESS;
166}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define ULONG_PTR
Definition: config.h:101
#define PagedPool
Definition: env_spec_w32.h:308
ULONG DeviceCount
Definition: mpu401.c:26
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
struct _IO_STACK_LOCATION::@4104::@4129 QueryDeviceRelations
union _IO_STACK_LOCATION::@1619 Parameters
@ BusRelations
Definition: iotypes.h:2152
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by FDO_HandlePnp().

◆ FDO_Dispatch()

NTSTATUS FDO_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 640 of file fdo.c.

643{
644 PIO_STACK_LOCATION IoStack;
646 PFDO_DEVICE_EXTENSION FDODeviceExtension;
647
648 /* Get device extension */
649 FDODeviceExtension = DeviceObject->DeviceExtension;
650 ASSERT(FDODeviceExtension->Common.IsFDO);
651
652 /* Get stack location */
654
655 switch(IoStack->MajorFunction)
656 {
657 case IRP_MJ_PNP:
661 case IRP_MJ_POWER:
664 return PoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
667 default:
668 DPRINT1("FDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
669 ASSERT(FALSE);
670 Status = Irp->IoStatus.Status;
672 return Status;
673 }
674
675}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
NTSTATUS FDO_HandleSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:624
NTSTATUS FDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:588
NTSTATUS FDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:389
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER

Referenced by USBCCGP_Dispatch().

◆ FDO_HandleInternalDeviceControl()

NTSTATUS FDO_HandleInternalDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 588 of file fdo.c.

591{
592 PIO_STACK_LOCATION IoStack;
594 PFDO_DEVICE_EXTENSION FDODeviceExtension;
595
596 /* Get device extension */
597 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
598 ASSERT(FDODeviceExtension->Common.IsFDO);
599
600 /* Get stack location */
602
603 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT ||
605 {
606 /* Handle reset / cycle ports */
608 DPRINT("FDO_HandleResetCyclePort Status %x\n", Status);
609 if (Status != STATUS_PENDING)
610 {
611 /* Complete request */
612 Irp->IoStatus.Status = Status;
614 }
615 return Status;
616 }
617
618 /* Forward and forget request */
620 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
621}
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define IoCallDriver
Definition: irp.c:1225
#define DPRINT
Definition: sndvol32.h:73
struct _IO_STACK_LOCATION::@1619::@1620 DeviceIoControl
NTSTATUS FDO_HandleResetCyclePort(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:490
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53

Referenced by FDO_Dispatch().

◆ FDO_HandlePnp()

NTSTATUS FDO_HandlePnp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 389 of file fdo.c.

392{
393 PIO_STACK_LOCATION IoStack;
395 PFDO_DEVICE_EXTENSION FDODeviceExtension;
396
397 /* Get device extension */
398 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
399 ASSERT(FDODeviceExtension->Common.IsFDO);
400
401
402 /* Get stack location */
404 DPRINT("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction);
405 switch(IoStack->MinorFunction)
406 {
408 {
409 // Unconfigure device */
410 DPRINT1("[USBCCGP] FDO IRP_MN_REMOVE\n");
412
413 /* Send the IRP down the stack */
414 Irp->IoStatus.Status = STATUS_SUCCESS;
416 Status = IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
417
418 /* Detach from the device stack */
419 IoDetachDevice(FDODeviceExtension->NextDeviceObject);
420
421 /* Delete the device object */
423
424 /* Request completed */
425 break;
426 }
428 {
429 /* Start the device */
431 break;
432 }
434 {
435 /* Handle device relations */
437 if (!NT_SUCCESS(Status))
438 {
439 break;
440 }
441
442 /* Forward irp to next device object */
444 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
445 }
447 {
448 /* Copy capabilities */
449 RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities,
450 &FDODeviceExtension->Capabilities,
451 sizeof(DEVICE_CAPABILITIES));
453
454 if (IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp))
455 {
456 Status = Irp->IoStatus.Status;
457 if (NT_SUCCESS(Status))
458 {
459 IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
460 }
461 }
462 break;
463 }
466 {
467 /* Sure */
468 Irp->IoStatus.Status = STATUS_SUCCESS;
469
470 /* Forward irp to next device object */
472 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
473 }
474 default:
475 {
476 /* Forward irp to next device object */
478 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
479 }
480
481 }
482
483 /* Complete request */
484 Irp->IoStatus.Status = Status;
486 return Status;
487}
#define TRUE
Definition: types.h:120
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
struct _IO_STACK_LOCATION::@4104::@4131 DeviceCapabilities
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS FDO_StartDevice(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:251
NTSTATUS FDO_DeviceRelations(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:102
NTSTATUS FDO_CloseConfiguration(IN PDEVICE_OBJECT DeviceObject)
Definition: fdo.c:345
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_QUERY_REMOVE_DEVICE

Referenced by FDO_Dispatch().

◆ FDO_HandleResetCyclePort()

NTSTATUS FDO_HandleResetCyclePort ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 490 of file fdo.c.

493{
494 PIO_STACK_LOCATION IoStack;
496 PFDO_DEVICE_EXTENSION FDODeviceExtension;
497 PLIST_ENTRY ListHead, Entry;
498 LIST_ENTRY TempList;
499 PUCHAR ResetActive;
500 PIRP ListIrp;
501 KIRQL OldLevel;
502
503 /* Get device extension */
504 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
505 ASSERT(FDODeviceExtension->Common.IsFDO);
506
507 /* Get stack location */
509 DPRINT("FDO_HandleResetCyclePort IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
510
511 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT)
512 {
513 /* Use reset port list */
514 ListHead = &FDODeviceExtension->ResetPortListHead;
515 ResetActive = &FDODeviceExtension->ResetPortActive;
516 }
517 else
518 {
519 /* Use cycle port list */
520 ListHead = &FDODeviceExtension->CyclePortListHead;
521 ResetActive = &FDODeviceExtension->CyclePortActive;
522 }
523
524 /* Acquire lock */
525 KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
526
527 if (*ResetActive)
528 {
529 /* Insert into pending list */
530 InsertTailList(ListHead, &Irp->Tail.Overlay.ListEntry);
531
532 /* Mark irp pending */
535
536 /* Release lock */
537 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
538 }
539 else
540 {
541 /* Mark reset active */
542 *ResetActive = TRUE;
543
544 /* Release lock */
545 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
546
547 /* Forward request synchronized */
548 NT_VERIFY(IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp));
549
550 /* Reacquire lock */
551 KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
552
553 /* Mark reset as completed */
554 *ResetActive = FALSE;
555
556 /* Move all requests into temporary list */
557 InitializeListHead(&TempList);
558 while(!IsListEmpty(ListHead))
559 {
560 Entry = RemoveHeadList(ListHead);
561 InsertTailList(&TempList, Entry);
562 }
563
564 /* Release lock */
565 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
566
567 /* Complete pending irps */
568 while(!IsListEmpty(&TempList))
569 {
570 Entry = RemoveHeadList(&TempList);
571 ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
572
573 /* Complete request with status success */
574 ListIrp->IoStatus.Status = STATUS_SUCCESS;
576 }
577
578 /* Status success */
580 }
581
582 return Status;
583}
struct _IRP * PIRP
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
IoMarkIrpPending(Irp)
base of all file and directory entries
Definition: entries.h:83
IO_STATUS_BLOCK IoStatus
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3304

Referenced by FDO_HandleInternalDeviceControl().

◆ FDO_HandleSystemControl()

NTSTATUS FDO_HandleSystemControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 624 of file fdo.c.

627{
628 PFDO_DEVICE_EXTENSION FDODeviceExtension;
629
630 /* Get device extension */
631 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
632 ASSERT(FDODeviceExtension->Common.IsFDO);
633
634 /* Forward and forget request */
636 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
637}

Referenced by FDO_Dispatch().

◆ FDO_QueryCapabilities()

NTSTATUS FDO_QueryCapabilities ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PDEVICE_CAPABILITIES  Capabilities 
)

Definition at line 32 of file fdo.c.

35{
36 PIRP Irp;
39 PIO_STACK_LOCATION IoStack;
40 PFDO_DEVICE_EXTENSION FDODeviceExtension;
41
42 /* Get device extension */
43 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
44 ASSERT(FDODeviceExtension->Common.IsFDO);
45
46 /* Init event */
48
49 /* Now allocate the irp */
50 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
51 if (!Irp)
52 {
53 /* No memory */
55 }
56
57 /* Get next stack location */
59
60 /* Init stack location */
61 IoStack->MajorFunction = IRP_MJ_PNP;
63 IoStack->Parameters.DeviceCapabilities.Capabilities = Capabilities;
64
65 /* Set completion routine */
68 (PVOID)&Event,
69 TRUE,
70 TRUE,
71 TRUE);
72
73 /* Init capabilities */
75 Capabilities->Size = sizeof(DEVICE_CAPABILITIES);
76 Capabilities->Version = 1; // FIXME hardcoded constant
77 Capabilities->Address = MAXULONG;
78 Capabilities->UINumber = MAXULONG;
79
80 /* Pnp irps have default completion code */
81 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
82
83 /* Call lower device */
84 Status = IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
86 {
87 /* Wait for completion */
89 }
90
91 /* Get status */
92 Status = Irp->IoStatus.Status;
93
94 /* Complete request */
96
97 /* Done */
98 return Status;
99}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define KernelMode
Definition: asm.h:38
@ NotificationEvent
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define MAXULONG
Definition: typedefs.h:251
NTSTATUS NTAPI FDO_QueryCapabilitiesCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: fdo.c:19
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
@ Executive
Definition: ketypes.h:415

Referenced by FDO_StartDevice().

◆ FDO_QueryCapabilitiesCompletionRoutine()

NTSTATUS NTAPI FDO_QueryCapabilitiesCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 19 of file fdo.c.

23{
24 /* Set event */
26
27 /* Completion is done in the HidClassFDO_QueryCapabilities routine */
29}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68

Referenced by FDO_QueryCapabilities().

◆ FDO_StartDevice()

NTSTATUS FDO_StartDevice ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 251 of file fdo.c.

254{
256 PFDO_DEVICE_EXTENSION FDODeviceExtension;
257
258 /* Get device extension */
259 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
260 ASSERT(FDODeviceExtension->Common.IsFDO);
261
262 /* First start lower device */
263 if (IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp))
264 {
265 Status = Irp->IoStatus.Status;
266 }
267 else
268 {
270 }
271
272 if (!NT_SUCCESS(Status))
273 {
274 /* Failed to start lower device */
275 DPRINT1("FDO_StartDevice lower device failed to start with %x\n", Status);
276 return Status;
277 }
278
279 /* Get descriptors */
281 if (!NT_SUCCESS(Status))
282 {
283 /* Failed to start lower device */
284 DPRINT1("FDO_StartDevice failed to get descriptors with %x\n", Status);
285 return Status;
286 }
287
288 /* Get capabilities */
290 &FDODeviceExtension->Capabilities);
291 if (!NT_SUCCESS(Status))
292 {
293 /* Failed to start lower device */
294 DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
295 return Status;
296 }
297
298 /* Now select the configuration */
299 Status = USBCCGP_SelectConfiguration(DeviceObject, FDODeviceExtension);
300 if (!NT_SUCCESS(Status))
301 {
302 /* Failed to select interface */
303 DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
304 return Status;
305 }
306
307 /* Query bus interface */
308 USBCCGP_QueryInterface(FDODeviceExtension->NextDeviceObject,
309 &FDODeviceExtension->BusInterface);
310
311 /* Now enumerate the functions */
313 if (!NT_SUCCESS(Status))
314 {
315 /* Failed to enumerate functions */
316 DPRINT1("Failed to enumerate functions with %x\n", Status);
317 return Status;
318 }
319
320 /* Sanity checks */
321 ASSERT(FDODeviceExtension->FunctionDescriptorCount);
322 ASSERT(FDODeviceExtension->FunctionDescriptor);
323 DumpFunctionDescriptor(FDODeviceExtension->FunctionDescriptor,
324 FDODeviceExtension->FunctionDescriptorCount);
325
326 /* Now create the pdo */
328 if (!NT_SUCCESS(Status))
329 {
330 /* Failed */
331 DPRINT1("FDO_CreateChildPdo failed with %x\n", Status);
332 return Status;
333 }
334
335 /* Inform pnp manager of new device objects */
336 IoInvalidateDeviceRelations(FDODeviceExtension->PhysicalDeviceObject,
338
339 /* Done */
340 DPRINT("[USBCCGP] FDO initialized successfully\n");
341 return Status;
342}
NTSTATUS USBCCGP_SelectConfiguration(IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
Definition: descriptor.c:467
NTSTATUS USBCCGP_GetDescriptors(IN PDEVICE_OBJECT DeviceObject)
Definition: descriptor.c:160
NTSTATUS USBCCGP_EnumerateFunctions(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:870
NTSTATUS USBCCGP_QueryInterface(IN PDEVICE_OBJECT DeviceObject, OUT PUSBC_DEVICE_CONFIGURATION_INTERFACE_V1 BusInterface)
Definition: function.c:18
VOID DumpFunctionDescriptor(IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor, IN ULONG FunctionDescriptorCount)
Definition: misc.c:111
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:1772
BUS_INTERFACE_STANDARD BusInterface
Definition: pciidex.h:92
NTSTATUS FDO_CreateChildPdo(IN PDEVICE_OBJECT DeviceObject)
Definition: fdo.c:169
NTSTATUS FDO_QueryCapabilities(IN PDEVICE_OBJECT DeviceObject, IN OUT PDEVICE_CAPABILITIES Capabilities)
Definition: fdo.c:32

Referenced by FDO_HandlePnp().