// bluetooth_sender.c
//
// Generated by C DriverWizard 3.2.0 (Build 2485)
// Requires DDK Only
// File created on 2/15/2010
//
#include "pch.h"
#include "..\intrface.h"
#ifdef BLUETOOTH_SENDER_WMI_TRACE
#include "bluetooth_sender.tmh"
#endif
// global data
BLUETOOTH_SENDER_DATA g_Data;
///////////////////////////////////////////////////////////////////////////////////////////////////
// DriverEntry
// Installable driver initialization entry point.
// This entry point is called directly by the I/O system.
//
// Arguments:
// IN DriverObject
// pointer to the driver object
//
// IN RegistryPath
// pointer to a unicode string representing the path,
// to driver-specific key in the registry.
//
// Return Value:
// Status
//
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
NTSTATUS status;
bluetooth_senderDebugPrint(DBG_INIT, DBG_TRACE, __FUNCTION__"++");
bluetooth_senderDebugPrint(DBG_INIT, DBG_INFO, "Compiled at %s on %s", __TIME__, __DATE__);
#ifdef DBG
// DbgBreakPoint();
#endif
#ifdef BLUETOOTH_SENDER_WMI_TRACE
WPP_INIT_TRACING(DriverObject, RegistryPath);
#endif
status = STATUS_SUCCESS;
RtlZeroMemory(&g_Data, sizeof(BLUETOOTH_SENDER_DATA));
// save registry path for wmi
g_Data.RegistryPath.Length = RegistryPath->Length;
g_Data.RegistryPath.MaximumLength = RegistryPath->Length + sizeof(UNICODE_NULL);
g_Data.RegistryPath.Buffer = (PWCHAR)ExAllocatePoolWithTag(
PagedPool,
g_Data.RegistryPath.MaximumLength,
BLUETOOTH_SENDER_POOL_TAG
);
if (g_Data.RegistryPath.Buffer == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
bluetooth_senderDebugPrint(DBG_INIT, DBG_ERR, __FUNCTION__": Failed to allocate memory for RegistryPath");
return status;
}
RtlCopyUnicodeString(&g_Data.RegistryPath, RegistryPath);
// detect current operating system
if (IoIsWdmVersionAvailable(1, 0x30))
{
g_Data.WdmVersion = 0x0130;
}
else if (IoIsWdmVersionAvailable(1, 0x20))
{
g_Data.WdmVersion = 0x0120;
}
else if (IoIsWdmVersionAvailable(1, 0x10))
{
g_Data.WdmVersion = 0x0110;
}
else if (IoIsWdmVersionAvailable(1, 0x05))
{
g_Data.WdmVersion = 0x0105;
}
else
{
g_Data.WdmVersion = 0x0100;
}
// setup our dispatch function table in the driver object
DriverObject->MajorFunction[IRP_MJ_PNP] = bluetooth_senderPnpDispatch;
DriverObject->MajorFunction[IRP_MJ_POWER] = bluetooth_senderPowerDispatch;
DriverObject->MajorFunction[IRP_MJ_CREATE] = bluetooth_senderCreateDispatch;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = bluetooth_senderCloseDispatch;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = bluetooth_senderDeviceIoControlDispatch;
DriverObject->MajorFunction[IRP_MJ_READ] = bluetooth_senderReadDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = bluetooth_senderWriteDispatch;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = bluetooth_senderCleanupDispatch;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = bluetooth_senderSystemControlDispatch;
DriverObject->DriverExtension->AddDevice = bluetooth_senderAddDevice;
DriverObject->DriverUnload = bluetooth_senderUnload;
bluetooth_senderDebugPrint(DBG_INIT, DBG_TRACE, __FUNCTION__"--. STATUS %x", status);
return status;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// bluetooth_senderAddDevice
// The PnP manager new device callback
//
// Arguments:
// IN DeviceObject
// pointer to a device object.
//
// IN PhysicalDeviceObject
// pointer to a device object created by the
// underlying bus driver.
//
// Return Value:
// Status
//
NTSTATUS bluetooth_senderAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
NTSTATUS status;
PDEVICE_OBJECT deviceObject;
PBLUETOOTH_SENDER_DEVICE_EXTENSION deviceExtension;
POWER_STATE powerState;
bluetooth_senderDebugPrint(DBG_INIT, DBG_TRACE, __FUNCTION__"++: PDO %p", PhysicalDeviceObject);
// Create our function device object.
status = IoCreateDevice(
DriverObject,
sizeof (BLUETOOTH_SENDER_DEVICE_EXTENSION),
NULL, // no name
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN, // Do not use if binary intended for 9x
FALSE,
&deviceObject
);
if (!NT_SUCCESS(status))
{
bluetooth_senderDebugPrint(DBG_INIT, DBG_ERR, __FUNCTION__"--. IoCreateDevice STATUS %x", status);
return status;
}
bluetooth_senderDebugPrint(DBG_INIT, DBG_INFO, __FUNCTION__": Created FDO %p", deviceObject);
// Initialize the device extension.
deviceExtension = (PBLUETOOTH_SENDER_DEVICE_EXTENSION)deviceObject->DeviceExtension;
// Zero the memory
RtlZeroMemory(deviceExtension, sizeof(BLUETOOTH_SENDER_DEVICE_EXTENSION));
// save the PDO pointer
deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
// save our device object
deviceExtension->DeviceObject = deviceObject;
// Initialize the powering down flag
deviceExtension->bPowerStop = FALSE;
// set RemoveCount to 1. Transition to zero
// means IRP_MN_REMOVE_DEVICE was received
deviceExtension->RemoveCount = 1;
// Initialize Remove event
KeInitializeEvent(&deviceExtension->RemoveEvent, NotificationEvent, FALSE);
// initialize io lock
bluetooth_senderInitializeIoLock(&deviceExtension->IoLock, deviceObject);
// set numints which help app;
deviceExtension->NumInts = 0;
InitializeListHead(&deviceExtension->IntData);
KeInitializeSpinLock(&deviceExtension->IntLock);
deviceExtension->PnpState = PnpStateNotStarted;
deviceExtension->PreviousPnpState = PnpStateNotStarted;
// allocate WorkItem for power processing
deviceExtension->PowerWorkItem = IoAllocateWorkItem(deviceExtension->DeviceObject);
if (deviceExtension->PowerWorkItem == NULL)
{
bluetooth_senderDebugPrint(DBG_INIT, DBG_ERR, __FUNCTION__"--. Failed to allocated PowerWorkItem");
IoDeleteDevice(deviceObject);
return STATUS_INSUFFICIENT_RESOURCES;
}
// Initialize the device object flags
// All WDM drivers are supposed to set this flag. Devices
// requiring a large amount of current at statup set the
// DO_POWER_INRUSH flag instead. These flags are mutually
// exclusive.
if (PhysicalDeviceObject->Flags & DO_POWER_PAGABLE)
{
deviceObject->Flags |= DO_POWER_PAGABLE;
}
// This flag sets the buffering method for reads and writes
// to METHOD_DIRECT. IOCTLs are handled by IO control codes
// independent of the value of this flag.
deviceObject->Flags |= DO_DIRECT_IO;
// Typically, (almost always) the function driver for a device is the
// power policy owner for that device. In some cases
// another driver or system component may assume this role.
// Set the initial device power state of the device to powered down.
deviceExtension->DevicePowerState = PowerDeviceD3;
powerState.DeviceState = deviceExtension->DevicePowerState;
// the initial system power state must be working or we wouldn't be h