ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

pdo.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Serial enumerator driver
00004  * FILE:            drivers/bus/serenum/pdo.c
00005  * PURPOSE:         IRP_MJ_PNP operations for PDOs
00006  *
00007  * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
00008  */
00009 
00010 #include "serenum.h"
00011 
00012 static NTSTATUS
00013 SerenumPdoStartDevice(
00014     IN PDEVICE_OBJECT DeviceObject)
00015 {
00016     PPDO_DEVICE_EXTENSION DeviceExtension;
00017 
00018     DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
00019 
00020     ASSERT(DeviceExtension->Common.PnpState == dsStopped);
00021 
00022     DeviceExtension->Common.PnpState = dsStarted;
00023     return STATUS_SUCCESS;
00024 }
00025 
00026 static NTSTATUS
00027 SerenumPdoQueryId(
00028     IN PDEVICE_OBJECT DeviceObject,
00029     IN PIRP Irp,
00030     OUT ULONG_PTR* Information)
00031 {
00032     PPDO_DEVICE_EXTENSION DeviceExtension;
00033     ULONG IdType;
00034     PUNICODE_STRING SourceString;
00035     UNICODE_STRING String;
00036     NTSTATUS Status;
00037 
00038     IdType = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryId.IdType;
00039     DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
00040     RtlInitUnicodeString(&String, NULL);
00041 
00042     switch (IdType)
00043     {
00044         case BusQueryDeviceID:
00045         {
00046             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
00047             SourceString = &DeviceExtension->DeviceId;
00048             break;
00049         }
00050         case BusQueryHardwareIDs:
00051         {
00052             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
00053             SourceString = &DeviceExtension->HardwareIds;
00054             break;
00055         }
00056         case BusQueryCompatibleIDs:
00057             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryCompatibleIDs\n");
00058             SourceString = &DeviceExtension->CompatibleIds;
00059             break;
00060         case BusQueryInstanceID:
00061         {
00062             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
00063             SourceString = &DeviceExtension->InstanceId;
00064             break;
00065         }
00066         default:
00067             WARN_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n", IdType);
00068             ASSERT(FALSE);
00069             return STATUS_NOT_SUPPORTED;
00070     }
00071 
00072     Status = DuplicateUnicodeString(
00073         RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
00074         SourceString,
00075         &String);
00076     *Information = (ULONG_PTR)String.Buffer;
00077     return Status;
00078 }
00079 
00080 static NTSTATUS
00081 SerenumPdoQueryDeviceRelations(
00082     IN PDEVICE_OBJECT DeviceObject,
00083     OUT PDEVICE_RELATIONS* pDeviceRelations)
00084 {
00085     PFDO_DEVICE_EXTENSION DeviceExtension;
00086     PDEVICE_RELATIONS DeviceRelations;
00087 
00088     DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
00089     ASSERT(DeviceExtension->Common.IsFDO);
00090 
00091     DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePoolWithTag(
00092         PagedPool,
00093         sizeof(DEVICE_RELATIONS),
00094         SERENUM_TAG);
00095     if (!DeviceRelations)
00096         return STATUS_INSUFFICIENT_RESOURCES;
00097 
00098     ObReferenceObject(DeviceObject);
00099     DeviceRelations->Count = 1;
00100     DeviceRelations->Objects[0] = DeviceObject;
00101 
00102     *pDeviceRelations = DeviceRelations;
00103     return STATUS_SUCCESS;
00104 }
00105 
00106 NTSTATUS
00107 SerenumPdoPnp(
00108     IN PDEVICE_OBJECT DeviceObject,
00109     IN PIRP Irp)
00110 {
00111     ULONG MinorFunction;
00112     PIO_STACK_LOCATION Stack;
00113     ULONG_PTR Information = 0;
00114     NTSTATUS Status;
00115 
00116     Stack = IoGetCurrentIrpStackLocation(Irp);
00117     MinorFunction = Stack->MinorFunction;
00118 
00119     switch (MinorFunction)
00120     {
00121         /* FIXME: do all these minor functions
00122         IRP_MN_QUERY_REMOVE_DEVICE 0x1
00123         IRP_MN_REMOVE_DEVICE 0x2
00124         IRP_MN_CANCEL_REMOVE_DEVICE 0x3
00125         IRP_MN_STOP_DEVICE 0x4
00126         IRP_MN_QUERY_STOP_DEVICE 0x5
00127         IRP_MN_CANCEL_STOP_DEVICE 0x6
00128         IRP_MN_QUERY_DEVICE_RELATIONS / EjectionRelations (optional) 0x7
00129         IRP_MN_QUERY_INTERFACE (required or optional) 0x8
00130         IRP_MN_READ_CONFIG (required or optional) 0xf
00131         IRP_MN_WRITE_CONFIG (required or optional) 0x10
00132         IRP_MN_EJECT (required or optional) 0x11
00133         IRP_MN_SET_LOCK (required or optional) 0x12
00134         IRP_MN_QUERY_ID / BusQueryDeviceID 0x13
00135         IRP_MN_QUERY_ID / BusQueryCompatibleIDs (optional) 0x13
00136         IRP_MN_QUERY_ID / BusQueryInstanceID (optional) 0x13
00137         IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
00138         IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
00139         IRP_MN_SURPRISE_REMOVAL 0x17
00140         */
00141         case IRP_MN_START_DEVICE: /* 0x0 */
00142         {
00143             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
00144             Status = SerenumPdoStartDevice(DeviceObject);
00145             break;
00146         }
00147         case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
00148         {
00149             switch (Stack->Parameters.QueryDeviceRelations.Type)
00150             {
00151                 case RemovalRelations:
00152                 {
00153                     return ForwardIrpToAttachedFdoAndForget(DeviceObject, Irp);
00154                 }
00155                 case TargetDeviceRelation:
00156                 {
00157                     PDEVICE_RELATIONS DeviceRelations = NULL;
00158                     TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n");
00159                     Status = SerenumPdoQueryDeviceRelations(DeviceObject, &DeviceRelations);
00160                     Information = (ULONG_PTR)DeviceRelations;
00161                     break;
00162                 }
00163                 default:
00164                 {
00165                     WARN_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
00166                         Stack->Parameters.QueryDeviceRelations.Type);
00167                     ASSERT(FALSE);
00168                     Status = STATUS_NOT_IMPLEMENTED;
00169                     break;
00170                 }
00171             }
00172             break;
00173         }
00174         case IRP_MN_QUERY_CAPABILITIES: /* 0x9 */
00175         {
00176             PDEVICE_CAPABILITIES DeviceCapabilities;
00177             ULONG i;
00178             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n");
00179 
00180             DeviceCapabilities = (PDEVICE_CAPABILITIES)Stack->Parameters.DeviceCapabilities.Capabilities;
00181             /* FIXME: capabilities can change with connected device */
00182             DeviceCapabilities->LockSupported = FALSE;
00183             DeviceCapabilities->EjectSupported = FALSE;
00184             DeviceCapabilities->Removable = TRUE;
00185             DeviceCapabilities->DockDevice = FALSE;
00186             DeviceCapabilities->UniqueID = FALSE;
00187             DeviceCapabilities->SilentInstall = FALSE;
00188             DeviceCapabilities->RawDeviceOK = TRUE;
00189             DeviceCapabilities->SurpriseRemovalOK = TRUE;
00190             DeviceCapabilities->HardwareDisabled = FALSE; /* FIXME */
00191             //DeviceCapabilities->NoDisplayInUI = FALSE; /* FIXME */
00192             DeviceCapabilities->DeviceState[0] = PowerDeviceD0; /* FIXME */
00193             for (i = 0; i < PowerSystemMaximum; i++)
00194                 DeviceCapabilities->DeviceState[i] = PowerDeviceD3; /* FIXME */
00195             //DeviceCapabilities->DeviceWake = PowerDeviceUndefined; /* FIXME */
00196             DeviceCapabilities->D1Latency = 0; /* FIXME */
00197             DeviceCapabilities->D2Latency = 0; /* FIXME */
00198             DeviceCapabilities->D3Latency = 0; /* FIXME */
00199             Status = STATUS_SUCCESS;
00200             break;
00201         }
00202         case IRP_MN_QUERY_RESOURCES: /* 0xa */
00203         {
00204             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n");
00205             /* Serial devices don't need resources, except the ones of
00206              * the serial port. This PDO is the serial device PDO, so
00207              * report no resource by not changing Information and
00208              * Status
00209              */
00210             Information = Irp->IoStatus.Information;
00211             Status = Irp->IoStatus.Status;
00212             break;
00213         }
00214         case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: /* 0xb */
00215         {
00216             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
00217             /* Serial devices don't need resources, except the ones of
00218              * the serial port. This PDO is the serial device PDO, so
00219              * report no resource by not changing Information and
00220              * Status
00221              */
00222             Information = Irp->IoStatus.Information;
00223             Status = Irp->IoStatus.Status;
00224             break;
00225         }
00226         case IRP_MN_QUERY_DEVICE_TEXT: /* 0xc */
00227         {
00228             switch (Stack->Parameters.QueryDeviceText.DeviceTextType)
00229             {
00230                 case DeviceTextDescription:
00231                 {
00232                     PUNICODE_STRING Source;
00233                     PWSTR Description;
00234                     TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextDescription\n");
00235 
00236                     Source = &((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceDescription;
00237                     Description = ExAllocatePoolWithTag(PagedPool, Source->Length + sizeof(WCHAR), SERENUM_TAG);
00238                     if (!Description)
00239                         Status = STATUS_INSUFFICIENT_RESOURCES;
00240                     else
00241                     {
00242                         RtlCopyMemory(Description, Source->Buffer, Source->Length);
00243                         Description[Source->Length / sizeof(WCHAR)] = L'\0';
00244                         Information = (ULONG_PTR)Description;
00245                         Status = STATUS_SUCCESS;
00246                     }
00247                     break;
00248                 }
00249                 case DeviceTextLocationInformation:
00250                 {
00251                     /* We don't have any text location to report,
00252                      * and this query is optional, so ignore it.
00253                      */
00254                     Information = Irp->IoStatus.Information;
00255                     Status = Irp->IoStatus.Status;
00256                     break;
00257                 }
00258                 default:
00259                 {
00260                     WARN_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / unknown type 0x%lx\n",
00261                         Stack->Parameters.QueryDeviceText.DeviceTextType);
00262                     ASSERT(FALSE);
00263                     Status = STATUS_NOT_SUPPORTED;
00264                 }
00265             }
00266             break;
00267         }
00268         case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* 0xd */
00269         {
00270             return ForwardIrpToAttachedFdoAndForget(DeviceObject, Irp);
00271         }
00272         case IRP_MN_QUERY_ID: /* 0x13 */
00273         {
00274             Status = SerenumPdoQueryId(DeviceObject, Irp, &Information);
00275             break;
00276         }
00277         case IRP_MN_QUERY_BUS_INFORMATION: /* 0x15 */
00278         {
00279             PPNP_BUS_INFORMATION BusInfo;
00280             TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_BUS_INFORMATION\n");
00281 
00282             BusInfo = (PPNP_BUS_INFORMATION)ExAllocatePoolWithTag(PagedPool, sizeof(PNP_BUS_INFORMATION), SERENUM_TAG);
00283             if (!BusInfo)
00284                 Status = STATUS_INSUFFICIENT_RESOURCES;
00285             else
00286             {
00287                 memcpy(
00288                     &BusInfo->BusTypeGuid,
00289                     &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
00290                     sizeof(BusInfo->BusTypeGuid));
00291                 BusInfo->LegacyBusType = PNPBus;
00292                 /* We're the only serial bus enumerator on the computer */
00293                 BusInfo->BusNumber = 0;
00294                 Information = (ULONG_PTR)BusInfo;
00295                 Status = STATUS_SUCCESS;
00296             }
00297             break;
00298         }
00299         default:
00300         {
00301             /* We can't forward request to the lower driver, because
00302              * we are a Pdo, so we don't have lower driver... */
00303             WARN_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
00304             ASSERT(FALSE);
00305             Information = Irp->IoStatus.Information;
00306             Status = Irp->IoStatus.Status;
00307         }
00308     }
00309 
00310     Irp->IoStatus.Information = Information;
00311     Irp->IoStatus.Status = Status;
00312     IoCompleteRequest(Irp, IO_NO_INCREMENT);
00313     return Status;
00314 }

Generated on Thu May 24 2012 04:28:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.