ReactOS 0.4.15-dev-7842-g558ab78
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 338 of file fdo.c.

340{
342 PURB Urb;
343 PFDO_DEVICE_EXTENSION FDODeviceExtension;
344
345 /* Get device extension */
346 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
347 ASSERT(FDODeviceExtension->Common.IsFDO);
348
349 /* Nothing to do if we're not configured */
350 if (FDODeviceExtension->ConfigurationDescriptor == NULL ||
351 FDODeviceExtension->InterfaceList == NULL)
352 {
353 return STATUS_SUCCESS;
354 }
355
356 /* Now allocate the urb */
357 Urb = USBD_CreateConfigurationRequestEx(FDODeviceExtension->ConfigurationDescriptor,
358 FDODeviceExtension->InterfaceList);
359 if (!Urb)
360 {
361 /* No memory */
363 }
364
365 /* Clear configuration descriptor to make it an unconfigure request */
366 Urb->UrbSelectConfiguration.ConfigurationDescriptor = NULL;
367
368 /* Submit urb */
369 Status = USBCCGP_SyncUrbRequest(FDODeviceExtension->NextDeviceObject, Urb);
370 if (!NT_SUCCESS(Status))
371 {
372 /* Failed to set configuration */
373 DPRINT1("USBCCGP_SyncUrbRequest failed to unconfigure device\n", Status);
374 }
375
376 ExFreePool(Urb);
377 return Status;
378}
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:32
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 /* Create the PDO */
195 Status = IoCreateDevice(FDODeviceExtension->DriverObject,
196 sizeof(PDO_DEVICE_EXTENSION),
197 NULL,
200 FALSE,
201 &PDODeviceObject);
202 if (!NT_SUCCESS(Status))
203 {
204 /* Failed to create device object */
205 DPRINT1("IoCreateDevice failed with %x\n", Status);
206 return Status;
207 }
208
209 /* Store in array */
210 FDODeviceExtension->ChildPDO[Index] = PDODeviceObject;
211
212 /* Get device extension */
213 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
214 RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
215
216 /* Init device extension */
217 PDODeviceExtension->Common.IsFDO = FALSE;
218 PDODeviceExtension->FunctionDescriptor = &FDODeviceExtension->FunctionDescriptor[Index];
219 PDODeviceExtension->NextDeviceObject = DeviceObject;
220 PDODeviceExtension->FunctionIndex = Index;
221 PDODeviceExtension->FDODeviceExtension = FDODeviceExtension;
222 PDODeviceExtension->InterfaceList = FDODeviceExtension->InterfaceList;
223 PDODeviceExtension->InterfaceListCount = FDODeviceExtension->InterfaceListCount;
224 PDODeviceExtension->ConfigurationHandle = FDODeviceExtension->ConfigurationHandle;
225 PDODeviceExtension->ConfigurationDescriptor = FDODeviceExtension->ConfigurationDescriptor;
226 RtlCopyMemory(&PDODeviceExtension->Capabilities, &FDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES));
227 RtlCopyMemory(&PDODeviceExtension->DeviceDescriptor, FDODeviceExtension->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR));
228
229 /* Patch the stack size */
230 PDODeviceObject->StackSize = DeviceObject->StackSize + 1;
231
232 /* Set device flags */
233 PDODeviceObject->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER;
234
235 /* Device is initialized */
236 PDODeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
237 }
238
239 /* Done */
240 return STATUS_SUCCESS;
241}
#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}
_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 _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
@ 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 633 of file fdo.c.

636{
637 PIO_STACK_LOCATION IoStack;
639 PFDO_DEVICE_EXTENSION FDODeviceExtension;
640
641 /* Get device extension */
642 FDODeviceExtension = DeviceObject->DeviceExtension;
643 ASSERT(FDODeviceExtension->Common.IsFDO);
644
645 /* Get stack location */
647
648 switch(IoStack->MajorFunction)
649 {
650 case IRP_MJ_PNP:
654 case IRP_MJ_POWER:
657 return PoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
660 default:
661 DPRINT1("FDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
662 ASSERT(FALSE);
663 Status = Irp->IoStatus.Status;
665 return Status;
666 }
667
668}
#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:617
NTSTATUS FDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:581
NTSTATUS FDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:382
#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 581 of file fdo.c.

584{
585 PIO_STACK_LOCATION IoStack;
587 PFDO_DEVICE_EXTENSION FDODeviceExtension;
588
589 /* Get device extension */
590 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
591 ASSERT(FDODeviceExtension->Common.IsFDO);
592
593 /* Get stack location */
595
596 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT ||
597 IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_CYCLE_PORT)
598 {
599 /* Handle reset / cycle ports */
601 DPRINT("FDO_HandleResetCyclePort Status %x\n", Status);
602 if (Status != STATUS_PENDING)
603 {
604 /* Complete request */
605 Irp->IoStatus.Status = Status;
607 }
608 return Status;
609 }
610
611 /* Forward and forget request */
613 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
614}
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS FDO_HandleResetCyclePort(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:483
#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 382 of file fdo.c.

385{
386 PIO_STACK_LOCATION IoStack;
388 PFDO_DEVICE_EXTENSION FDODeviceExtension;
389
390 /* Get device extension */
391 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
392 ASSERT(FDODeviceExtension->Common.IsFDO);
393
394
395 /* Get stack location */
397 DPRINT("[USBCCGP] PnP Minor %x\n", IoStack->MinorFunction);
398 switch(IoStack->MinorFunction)
399 {
401 {
402 // Unconfigure device */
403 DPRINT1("[USBCCGP] FDO IRP_MN_REMOVE\n");
405
406 /* Send the IRP down the stack */
407 Irp->IoStatus.Status = STATUS_SUCCESS;
409 Status = IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
410
411 /* Detach from the device stack */
412 IoDetachDevice(FDODeviceExtension->NextDeviceObject);
413
414 /* Delete the device object */
416
417 /* Request completed */
418 break;
419 }
421 {
422 /* Start the device */
424 break;
425 }
427 {
428 /* Handle device relations */
430 if (!NT_SUCCESS(Status))
431 {
432 break;
433 }
434
435 /* Forward irp to next device object */
437 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
438 }
440 {
441 /* Copy capabilities */
442 RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities,
443 &FDODeviceExtension->Capabilities,
444 sizeof(DEVICE_CAPABILITIES));
446
447 if (IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp))
448 {
449 Status = Irp->IoStatus.Status;
450 if (NT_SUCCESS(Status))
451 {
452 IoStack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;
453 }
454 }
455 break;
456 }
459 {
460 /* Sure */
461 Irp->IoStatus.Status = STATUS_SUCCESS;
462
463 /* Forward irp to next device object */
465 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
466 }
467 default:
468 {
469 /* Forward irp to next device object */
471 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
472 }
473
474 }
475
476 /* Complete request */
477 Irp->IoStatus.Status = Status;
479 return Status;
480}
#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
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS FDO_StartDevice(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:244
NTSTATUS FDO_DeviceRelations(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:102
NTSTATUS FDO_CloseConfiguration(IN PDEVICE_OBJECT DeviceObject)
Definition: fdo.c:338
#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 483 of file fdo.c.

486{
487 PIO_STACK_LOCATION IoStack;
489 PFDO_DEVICE_EXTENSION FDODeviceExtension;
490 PLIST_ENTRY ListHead, Entry;
491 LIST_ENTRY TempList;
492 PUCHAR ResetActive;
493 PIRP ListIrp;
494 KIRQL OldLevel;
495
496 /* Get device extension */
497 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
498 ASSERT(FDODeviceExtension->Common.IsFDO);
499
500 /* Get stack location */
502 DPRINT("FDO_HandleResetCyclePort IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
503
504 if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT)
505 {
506 /* Use reset port list */
507 ListHead = &FDODeviceExtension->ResetPortListHead;
508 ResetActive = &FDODeviceExtension->ResetPortActive;
509 }
510 else
511 {
512 /* Use cycle port list */
513 ListHead = &FDODeviceExtension->CyclePortListHead;
514 ResetActive = &FDODeviceExtension->CyclePortActive;
515 }
516
517 /* Acquire lock */
518 KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
519
520 if (*ResetActive)
521 {
522 /* Insert into pending list */
523 InsertTailList(ListHead, &Irp->Tail.Overlay.ListEntry);
524
525 /* Mark irp pending */
528
529 /* Release lock */
530 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
531 }
532 else
533 {
534 /* Mark reset active */
535 *ResetActive = TRUE;
536
537 /* Release lock */
538 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
539
540 /* Forward request synchronized */
541 NT_VERIFY(IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp));
542
543 /* Reacquire lock */
544 KeAcquireSpinLock(&FDODeviceExtension->Lock, &OldLevel);
545
546 /* Mark reset as completed */
547 *ResetActive = FALSE;
548
549 /* Move all requests into temporary list */
550 InitializeListHead(&TempList);
551 while(!IsListEmpty(ListHead))
552 {
553 Entry = RemoveHeadList(ListHead);
554 InsertTailList(&TempList, Entry);
555 }
556
557 /* Release lock */
558 KeReleaseSpinLock(&FDODeviceExtension->Lock, OldLevel);
559
560 /* Complete pending irps */
561 while(!IsListEmpty(&TempList))
562 {
563 Entry = RemoveHeadList(&TempList);
564 ListIrp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
565
566 /* Complete request with status success */
567 ListIrp->IoStatus.Status = STATUS_SUCCESS;
569 }
570
571 /* Status success */
573 }
574
575 return Status;
576}
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:3287

Referenced by FDO_HandleInternalDeviceControl().

◆ FDO_HandleSystemControl()

NTSTATUS FDO_HandleSystemControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 617 of file fdo.c.

620{
621 PFDO_DEVICE_EXTENSION FDODeviceExtension;
622
623 /* Get device extension */
624 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
625 ASSERT(FDODeviceExtension->Common.IsFDO);
626
627 /* Forward and forget request */
629 return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
630}

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 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:34
@ 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 STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#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 244 of file fdo.c.

247{
249 PFDO_DEVICE_EXTENSION FDODeviceExtension;
250
251 /* Get device extension */
252 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
253 ASSERT(FDODeviceExtension->Common.IsFDO);
254
255 /* First start lower device */
256 if (IoForwardIrpSynchronously(FDODeviceExtension->NextDeviceObject, Irp))
257 {
258 Status = Irp->IoStatus.Status;
259 }
260 else
261 {
263 }
264
265 if (!NT_SUCCESS(Status))
266 {
267 /* Failed to start lower device */
268 DPRINT1("FDO_StartDevice lower device failed to start with %x\n", Status);
269 return Status;
270 }
271
272 /* Get descriptors */
274 if (!NT_SUCCESS(Status))
275 {
276 /* Failed to start lower device */
277 DPRINT1("FDO_StartDevice failed to get descriptors with %x\n", Status);
278 return Status;
279 }
280
281 /* Get capabilities */
283 &FDODeviceExtension->Capabilities);
284 if (!NT_SUCCESS(Status))
285 {
286 /* Failed to start lower device */
287 DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
288 return Status;
289 }
290
291 /* Now select the configuration */
292 Status = USBCCGP_SelectConfiguration(DeviceObject, FDODeviceExtension);
293 if (!NT_SUCCESS(Status))
294 {
295 /* Failed to select interface */
296 DPRINT1("FDO_StartDevice failed to get capabilities with %x\n", Status);
297 return Status;
298 }
299
300 /* Query bus interface */
301 USBCCGP_QueryInterface(FDODeviceExtension->NextDeviceObject,
302 &FDODeviceExtension->BusInterface);
303
304 /* Now enumerate the functions */
306 if (!NT_SUCCESS(Status))
307 {
308 /* Failed to enumerate functions */
309 DPRINT1("Failed to enumerate functions with %x\n", Status);
310 return Status;
311 }
312
313 /* Sanity checks */
314 ASSERT(FDODeviceExtension->FunctionDescriptorCount);
315 ASSERT(FDODeviceExtension->FunctionDescriptor);
316 DumpFunctionDescriptor(FDODeviceExtension->FunctionDescriptor,
317 FDODeviceExtension->FunctionDescriptorCount);
318
319 /* Now create the pdo */
321 if (!NT_SUCCESS(Status))
322 {
323 /* Failed */
324 DPRINT1("FDO_CreateChildPdo failed with %x\n", Status);
325 return Status;
326 }
327
328 /* Inform pnp manager of new device objects */
329 IoInvalidateDeviceRelations(FDODeviceExtension->PhysicalDeviceObject,
331
332 /* Done */
333 DPRINT("[USBCCGP] FDO initialized successfully\n");
334 return Status;
335}
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:829
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().