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

fbtwmi.c
Go to the documentation of this file.
00001 // Copyright (c) 2004, Antony C. Roberts
00002 
00003 // Use of this file is subject to the terms
00004 // described in the LICENSE.TXT file that
00005 // accompanies this file.
00006 //
00007 // Your use of this file indicates your
00008 // acceptance of the terms described in
00009 // LICENSE.TXT.
00010 //
00011 // http://www.freebt.net
00012 
00013 #include "fbtusb.h"
00014 #include "fbtpwr.h"
00015 #include "fbtpnp.h"
00016 #include "fbtdev.h"
00017 #include "fbtrwr.h"
00018 #include "fbtwmi.h"
00019 
00020 #include "fbtusr.h"
00021 
00022 #define MOFRESOURCENAME L"MofResourceName"
00023 
00024 #define WMI_FREEBT_DRIVER_INFORMATION 0
00025 
00026 DEFINE_GUID (FREEBT_WMI_STD_DATA_GUID, 0x871B1A60, 0xD3EA, 0x4f2f, 0x81, 0x7b, 0x46, 0x5e, 0x44, 0x86, 0x7b, 0xf5);
00027 
00028 WMIGUIDREGINFO FreeBTWmiGuidList[1] =
00029 {
00030     {
00031         &FREEBT_WMI_STD_DATA_GUID, 1, 0 // driver information
00032 
00033     }
00034 
00035 };
00036 
00037 NTSTATUS FreeBT_WmiRegistration(IN OUT PDEVICE_EXTENSION DeviceExtension)
00038 {
00039     NTSTATUS ntStatus;
00040 
00041     PAGED_CODE();
00042 
00043     DeviceExtension->WmiLibInfo.GuidCount = sizeof (FreeBTWmiGuidList) / sizeof (WMIGUIDREGINFO);
00044     DeviceExtension->WmiLibInfo.GuidList           = FreeBTWmiGuidList;
00045     DeviceExtension->WmiLibInfo.QueryWmiRegInfo    = FreeBT_QueryWmiRegInfo;
00046     DeviceExtension->WmiLibInfo.QueryWmiDataBlock  = FreeBT_QueryWmiDataBlock;
00047     DeviceExtension->WmiLibInfo.SetWmiDataBlock    = FreeBT_SetWmiDataBlock;
00048     DeviceExtension->WmiLibInfo.SetWmiDataItem     = FreeBT_SetWmiDataItem;
00049     DeviceExtension->WmiLibInfo.ExecuteWmiMethod   = NULL;
00050     DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
00051 
00052     // Register with WMI
00053     ntStatus = IoWMIRegistrationControl(DeviceExtension->FunctionalDeviceObject, WMIREG_ACTION_REGISTER);
00054 
00055     return ntStatus;
00056 
00057 }
00058 
00059 NTSTATUS FreeBT_WmiDeRegistration(IN OUT PDEVICE_EXTENSION DeviceExtension)
00060 {
00061     PAGED_CODE();
00062     return IoWMIRegistrationControl(DeviceExtension->FunctionalDeviceObject, WMIREG_ACTION_DEREGISTER);
00063 
00064 }
00065 
00066 NTSTATUS FreeBT_DispatchSysCtrl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
00067 {
00068     PDEVICE_EXTENSION       deviceExtension;
00069     SYSCTL_IRP_DISPOSITION  disposition;
00070     NTSTATUS                ntStatus;
00071     PIO_STACK_LOCATION      irpStack;
00072 
00073     PAGED_CODE();
00074 
00075     irpStack = IoGetCurrentIrpStackLocation (Irp);
00076     deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
00077 
00078     FreeBT_DbgPrint(3, ("FBTUSB: "));
00079     FreeBT_DbgPrint(3, (WMIMinorFunctionString(irpStack->MinorFunction)));
00080     if (Removed == deviceExtension->DeviceState)
00081     {
00082         ntStatus = STATUS_DELETE_PENDING;
00083 
00084         Irp->IoStatus.Status = ntStatus;
00085         Irp->IoStatus.Information = 0;
00086         IoCompleteRequest(Irp, IO_NO_INCREMENT);
00087 
00088         return ntStatus;
00089 
00090     }
00091 
00092     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchSysCtrl::"));
00093     FreeBT_IoIncrement(deviceExtension);
00094 
00095     ntStatus = WmiSystemControl(&deviceExtension->WmiLibInfo,
00096                                 DeviceObject,
00097                                 Irp,
00098                                 &disposition);
00099 
00100     switch(disposition)
00101     {
00102         case IrpProcessed:
00103         {
00104             // This irp has been processed and may be completed or pending.
00105             break;
00106 
00107         }
00108 
00109         case IrpNotCompleted:
00110         {
00111             // This irp has not been completed, but has been fully processed.
00112             // we will complete it now
00113             IoCompleteRequest(Irp, IO_NO_INCREMENT);
00114             break;
00115 
00116         }
00117 
00118         case IrpForward:
00119         case IrpNotWmi:
00120         {
00121             // This irp is either not a WMI irp or is a WMI irp targeted
00122             // at a device lower in the stack.
00123             IoSkipCurrentIrpStackLocation (Irp);
00124             ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
00125             break;
00126         }
00127 
00128         default:
00129         {
00130             // We really should never get here, but if we do just forward....
00131             ASSERT(FALSE);
00132             IoSkipCurrentIrpStackLocation (Irp);
00133             ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
00134             break;
00135 
00136         }
00137 
00138     }
00139 
00140     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_DispatchSysCtrl::"));
00141     FreeBT_IoDecrement(deviceExtension);
00142 
00143     return ntStatus;
00144 
00145 }
00146 
00147 NTSTATUS FreeBT_QueryWmiRegInfo(
00148     IN  PDEVICE_OBJECT  DeviceObject,
00149     OUT ULONG           *RegFlags,
00150     OUT PUNICODE_STRING InstanceName,
00151     OUT PUNICODE_STRING *RegistryPath,
00152     OUT PUNICODE_STRING MofResourceName,
00153     OUT PDEVICE_OBJECT  *Pdo
00154     )
00155 /*++
00156 
00157 Routine Description:
00158 
00159     This routine is a callback into the driver to retrieve the list of
00160     guids or data blocks that the driver wants to register with WMI. This
00161     routine may not pend or block. Driver should NOT call
00162     WmiCompleteRequest.
00163 
00164 Arguments:
00165 
00166     DeviceObject is the device whose data block is being queried
00167 
00168     *RegFlags returns with a set of flags that describe the guids being
00169         registered for this device. If the device wants enable and disable
00170         collection callbacks before receiving queries for the registered
00171         guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
00172         returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
00173         the instance name is determined from the PDO associated with the
00174         device object. Note that the PDO must have an associated devnode. If
00175         WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
00176         name for the device.
00177 
00178     InstanceName returns with the instance name for the guids if
00179         WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
00180         caller will call ExFreePool with the buffer returned.
00181 
00182     *RegistryPath returns with the registry path of the driver
00183 
00184     *MofResourceName returns with the name of the MOF resource attached to
00185         the binary file. If the driver does not have a mof resource attached
00186         then this can be returned as NULL.
00187 
00188     *Pdo returns with the device object for the PDO associated with this
00189         device if the WMIREG_FLAG_INSTANCE_PDO flag is returned in
00190         *RegFlags.
00191 
00192 Return Value:
00193 
00194     status
00195 
00196 --*/
00197 {
00198     PDEVICE_EXTENSION deviceExtension;
00199 
00200     PAGED_CODE();
00201 
00202     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiRegInfo: Entered\n"));
00203 
00204     deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
00205 
00206     *RegFlags     = WMIREG_FLAG_INSTANCE_PDO;
00207     *RegistryPath = &Globals.FreeBT_RegistryPath;
00208     *Pdo          = deviceExtension->PhysicalDeviceObject;
00209     RtlInitUnicodeString(MofResourceName, MOFRESOURCENAME);
00210 
00211     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiRegInfo: Leaving\n"));
00212 
00213     return STATUS_SUCCESS;
00214 
00215 }
00216 
00217 NTSTATUS FreeBT_QueryWmiDataBlock(
00218     IN PDEVICE_OBJECT DeviceObject,
00219     IN PIRP           Irp,
00220     IN ULONG          GuidIndex,
00221     IN ULONG          InstanceIndex,
00222     IN ULONG          InstanceCount,
00223     IN OUT PULONG     InstanceLengthArray,
00224     IN ULONG          OutBufferSize,
00225     OUT PUCHAR        Buffer
00226     )
00227 /*++
00228 
00229 Routine Description:
00230 
00231     This routine is a callback into the driver to query for the contents of
00232     a data block. When the driver has finished filling the data block it
00233     must call WmiCompleteRequest to complete the irp. The driver can
00234     return STATUS_PENDING if the irp cannot be completed immediately.
00235 
00236 Arguments:
00237 
00238     DeviceObject is the device whose data block is being queried
00239 
00240     Irp is the Irp that makes this request
00241 
00242     GuidIndex is the index into the list of guids provided when the
00243         device registered
00244 
00245     InstanceIndex is the index that denotes which instance of the data block
00246         is being queried.
00247 
00248     InstanceCount is the number of instances expected to be returned for
00249         the data block.
00250 
00251     InstanceLengthArray is a pointer to an array of ULONG that returns the
00252         lengths of each instance of the data block. If this is NULL then
00253         there was not enough space in the output buffer to fulfill the request
00254         so the irp should be completed with the buffer needed.
00255 
00256     OutBufferSize has the maximum size available to write the data
00257         block.
00258 
00259     Buffer on return is filled with the returned data block
00260 
00261 
00262 Return Value:
00263 
00264     status
00265 
00266 --*/
00267 {
00268     PDEVICE_EXTENSION deviceExtension;
00269     NTSTATUS          ntStatus;
00270     ULONG             size;
00271     WCHAR             modelName[] = L"Aishverya\0\0";
00272     USHORT            modelNameLen;
00273 
00274     PAGED_CODE();
00275 
00276     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiDataBlock: Entered\n"));
00277 
00278     size = 0;
00279     modelNameLen = (wcslen(modelName) + 1) * sizeof(WCHAR);
00280 
00281     // Only ever registers 1 instance per guid
00282     ASSERT((InstanceIndex == 0) && (InstanceCount == 1));
00283 
00284     deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
00285     switch (GuidIndex)
00286     {
00287     case WMI_FREEBT_DRIVER_INFORMATION:
00288         size = sizeof(ULONG) + modelNameLen + sizeof(USHORT);
00289         if (OutBufferSize < size )
00290         {
00291             FreeBT_DbgPrint(3, ("FBTUSB: OutBuffer too small\n"));
00292             ntStatus = STATUS_BUFFER_TOO_SMALL;
00293             break;
00294 
00295         }
00296 
00297         * (PULONG) Buffer = DebugLevel;
00298         Buffer += sizeof(ULONG);
00299 
00300         // put length of string ahead of string
00301         *((PUSHORT)Buffer) = modelNameLen;
00302         Buffer = (PUCHAR)Buffer + sizeof(USHORT);
00303         RtlCopyBytes((PVOID)Buffer, (PVOID)modelName, modelNameLen);
00304         *InstanceLengthArray = size ;
00305 
00306         ntStatus = STATUS_SUCCESS;
00307         break;
00308 
00309     default:
00310         ntStatus = STATUS_WMI_GUID_NOT_FOUND;
00311 
00312     }
00313 
00314     ntStatus = WmiCompleteRequest(DeviceObject,
00315                                 Irp,
00316                                 ntStatus,
00317                                 size,
00318                                 IO_NO_INCREMENT);
00319 
00320     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_QueryWmiDataBlock: Leaving\n"));
00321 
00322     return ntStatus;
00323 
00324 }
00325 
00326 
00327 NTSTATUS FreeBT_SetWmiDataItem(
00328     IN PDEVICE_OBJECT DeviceObject,
00329     IN PIRP           Irp,
00330     IN ULONG          GuidIndex,
00331     IN ULONG          InstanceIndex,
00332     IN ULONG          DataItemId,
00333     IN ULONG          BufferSize,
00334     IN PUCHAR         Buffer
00335     )
00336 /*++
00337 
00338 Routine Description:
00339 
00340     This routine is a callback into the driver to set for the contents of
00341     a data block. When the driver has finished filling the data block it
00342     must call WmiCompleteRequest to complete the irp. The driver can
00343     return STATUS_PENDING if the irp cannot be completed immediately.
00344 
00345 Arguments:
00346 
00347     DeviceObject is the device whose data block is being queried
00348 
00349     Irp is the Irp that makes this request
00350 
00351     GuidIndex is the index into the list of guids provided when the
00352         device registered
00353 
00354     InstanceIndex is the index that denotes which instance of the data block
00355         is being queried.
00356 
00357     DataItemId has the id of the data item being set
00358 
00359     BufferSize has the size of the data item passed
00360 
00361     Buffer has the new values for the data item
00362 
00363 
00364 Return Value:
00365 
00366     status
00367 
00368 --*/
00369 {
00370     PDEVICE_EXTENSION deviceExtension;
00371     NTSTATUS          ntStatus;
00372     ULONG             info;
00373 
00374     PAGED_CODE();
00375 
00376     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataItem: Entered\n"));
00377 
00378     deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
00379     info = 0;
00380 
00381     switch(GuidIndex)
00382     {
00383     case WMI_FREEBT_DRIVER_INFORMATION:
00384         if(DataItemId == 1)
00385         {
00386             if(BufferSize == sizeof(ULONG))
00387             {
00388                 DebugLevel = *((PULONG)Buffer);
00389                 ntStatus = STATUS_SUCCESS;
00390                 info = sizeof(ULONG);
00391 
00392             }
00393 
00394             else
00395             {
00396                 ntStatus = STATUS_INFO_LENGTH_MISMATCH;
00397 
00398             }
00399 
00400         }
00401 
00402         else
00403         {
00404             ntStatus = STATUS_WMI_READ_ONLY;
00405 
00406         }
00407 
00408         break;
00409 
00410     default:
00411         ntStatus = STATUS_WMI_GUID_NOT_FOUND;
00412 
00413     }
00414 
00415     ntStatus = WmiCompleteRequest(DeviceObject,
00416                                 Irp,
00417                                 ntStatus,
00418                                 info,
00419                                 IO_NO_INCREMENT);
00420 
00421     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataItem: Leaving\n"));
00422 
00423     return ntStatus;
00424 
00425 }
00426 
00427 NTSTATUS FreeBT_SetWmiDataBlock(
00428     IN PDEVICE_OBJECT DeviceObject,
00429     IN PIRP           Irp,
00430     IN ULONG          GuidIndex,
00431     IN ULONG          InstanceIndex,
00432     IN ULONG          BufferSize,
00433     IN PUCHAR         Buffer
00434     )
00435 /*++
00436 
00437 Routine Description:
00438 
00439     This routine is a callback into the driver to set the contents of
00440     a data block. When the driver has finished filling the data block it
00441     must call WmiCompleteRequest to complete the irp. The driver can
00442     return STATUS_PENDING if the irp cannot be completed immediately.
00443 
00444 Arguments:
00445 
00446     DeviceObject is the device whose data block is being queried
00447 
00448     Irp is the Irp that makes this request
00449 
00450     GuidIndex is the index into the list of guids provided when the
00451         device registered
00452 
00453     InstanceIndex is the index that denotes which instance of the data block
00454         is being queried.
00455 
00456     BufferSize has the size of the data block passed
00457 
00458     Buffer has the new values for the data block
00459 
00460 --*/
00461 {
00462     PDEVICE_EXTENSION deviceExtension;
00463     NTSTATUS          ntStatus;
00464     ULONG             info;
00465 
00466     PAGED_CODE();
00467 
00468     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataBlock: Entered\n"));
00469 
00470     deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
00471     info = 0;
00472 
00473     switch(GuidIndex)
00474     {
00475     case WMI_FREEBT_DRIVER_INFORMATION:
00476         if(BufferSize == sizeof(ULONG))
00477         {
00478             DebugLevel = *(PULONG) Buffer;
00479             ntStatus = STATUS_SUCCESS;
00480             info = sizeof(ULONG);
00481 
00482         }
00483 
00484         else
00485         {
00486             ntStatus = STATUS_INFO_LENGTH_MISMATCH;
00487 
00488         }
00489 
00490         break;
00491 
00492     default:
00493         ntStatus = STATUS_WMI_GUID_NOT_FOUND;
00494 
00495     }
00496 
00497     ntStatus = WmiCompleteRequest(DeviceObject,
00498                                 Irp,
00499                                 ntStatus,
00500                                 info,
00501                                 IO_NO_INCREMENT);
00502 
00503     FreeBT_DbgPrint(3, ("FBTUSB: FreeBT_SetWmiDataBlock: Leaving\n"));
00504 
00505     return ntStatus;
00506 
00507 }
00508 
00509 PCHAR WMIMinorFunctionString(UCHAR MinorFunction)
00510 {
00511     switch (MinorFunction)
00512     {
00513         case IRP_MN_CHANGE_SINGLE_INSTANCE:
00514             return "IRP_MN_CHANGE_SINGLE_INSTANCE\n";
00515 
00516         case IRP_MN_CHANGE_SINGLE_ITEM:
00517             return "IRP_MN_CHANGE_SINGLE_ITEM\n";
00518 
00519         case IRP_MN_DISABLE_COLLECTION:
00520             return "IRP_MN_DISABLE_COLLECTION\n";
00521 
00522         case IRP_MN_DISABLE_EVENTS:
00523             return "IRP_MN_DISABLE_EVENTS\n";
00524 
00525         case IRP_MN_ENABLE_COLLECTION:
00526             return "IRP_MN_ENABLE_COLLECTION\n";
00527 
00528         case IRP_MN_ENABLE_EVENTS:
00529             return "IRP_MN_ENABLE_EVENTS\n";
00530 
00531         case IRP_MN_EXECUTE_METHOD:
00532             return "IRP_MN_EXECUTE_METHOD\n";
00533 
00534         case IRP_MN_QUERY_ALL_DATA:
00535             return "IRP_MN_QUERY_ALL_DATA\n";
00536 
00537         case IRP_MN_QUERY_SINGLE_INSTANCE:
00538             return "IRP_MN_QUERY_SINGLE_INSTANCE\n";
00539 
00540         case IRP_MN_REGINFO:
00541             return "IRP_MN_REGINFO\n";
00542 
00543         default:
00544             return "IRP_MN_?????\n";
00545 
00546     }
00547 
00548 }

Generated on Sat May 26 2012 04:25:44 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.