Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404/*++
Copyright (c) Microsoft Corporation
Module Name:
FxDeviceInterfaceAPI.cpp
Abstract:
This module implements the device interface object external APIs
Author:
Environment:
kernel and user mode
Revision History:
--*/
#include "fxsupportpch.hpp"
extern "C" {// #include "FxDeviceInterfaceAPI.tmh"}
//// extern "C" the entire file//extern "C" {
_Must_inspect_result___drv_maxIRQL(PASSIVE_LEVEL)NTSTATUSNTAPIWDFEXPORT(WdfDeviceCreateDeviceInterface)( __in PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFDEVICE Device, __in CONST GUID *InterfaceClassGUID, __in_opt PCUNICODE_STRING ReferenceString )/*++
Routine Description: Creates a device interface associated with the passed in device object
Arguments: Device - Handle which represents the device exposing the interface
InterfaceGUID - GUID describing the interface being exposed
ReferenceString - OPTIONAL string which allows the driver writer to distinguish between different exposed interfaces
Return Value: STATUS_SUCCESS or appropriate NTSTATUS code
--*/{ DDI_ENTRY();
SINGLE_LIST_ENTRY **ppPrev, *pCur; PFX_DRIVER_GLOBALS pFxDriverGlobals; FxDeviceInterface *pDeviceInterface; FxDevice *pDevice; FxPkgPnp* pPkgPnp; NTSTATUS status;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE, (PVOID*) &pDevice, &pFxDriverGlobals);
FxPointerNotNull(pFxDriverGlobals, InterfaceClassGUID);
status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL); if (!NT_SUCCESS(status)) { return status; }
if (ReferenceString != NULL) { status = FxValidateUnicodeString(pFxDriverGlobals, ReferenceString); if (!NT_SUCCESS(status)) { return status; } }
if (pDevice->IsLegacy()) { status = STATUS_INVALID_DEVICE_REQUEST;
DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, "WDFDEVICE %p is not a PNP device, device interface creation not " "allowed %!STATUS!", Device, status);
return status; }
pDeviceInterface = new(pFxDriverGlobals, PagedPool) FxDeviceInterface();
if (pDeviceInterface == NULL) { status = STATUS_INSUFFICIENT_RESOURCES;
DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, "WDFDEVICE %p DeviceInterface object creation failed, %!STATUS!", Device, status);
return status; }
status = pDeviceInterface->Initialize(pFxDriverGlobals, InterfaceClassGUID, ReferenceString);
if (!NT_SUCCESS(status)) { DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, "WDFDEVICE %p, DeviceInterface object initialization failed, %!STATUS!", Device, status );
goto Done; }
pPkgPnp = pDevice->m_PkgPnp;
pPkgPnp->m_DeviceInterfaceLock.AcquireLock(pFxDriverGlobals);
status = pDeviceInterface->Register(pDevice);
if (NT_SUCCESS(status)) { // // Insert into the end of the list // ppPrev = &pPkgPnp->m_DeviceInterfaceHead.Next; pCur = pPkgPnp->m_DeviceInterfaceHead.Next; while (pCur != NULL) { ppPrev = &pCur->Next; pCur = pCur->Next; }
*ppPrev = &pDeviceInterface->m_Entry; }
pPkgPnp->m_DeviceInterfaceLock.ReleaseLock(pFxDriverGlobals);
Done: if (!NT_SUCCESS(status)) { delete pDeviceInterface; pDeviceInterface = NULL; }
return status;}
__drv_maxIRQL(PASSIVE_LEVEL)VOIDNTAPIWDFEXPORT(WdfDeviceSetDeviceInterfaceState)( __in PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFDEVICE Device, __in CONST GUID *InterfaceClassGUID, __in_opt PCUNICODE_STRING RefString, __in BOOLEAN State ){ DDI_ENTRY();
PSINGLE_LIST_ENTRY ple; PFX_DRIVER_GLOBALS pFxDriverGlobals; NTSTATUS status; FxDevice* pDevice; FxPkgPnp* pPkgPnp;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE, (PVOID*) &pDevice, &pFxDriverGlobals);
FxPointerNotNull(pFxDriverGlobals, InterfaceClassGUID);
status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL); if (!NT_SUCCESS(status)) { FxVerifierDbgBreakPoint(pFxDriverGlobals); return; }
if (RefString != NULL) { status = FxValidateUnicodeString(pFxDriverGlobals, RefString); if (!NT_SUCCESS(status)) { FxVerifierDbgBreakPoint(pFxDriverGlobals); return; } }
if (pDevice->IsLegacy()) { DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, "WDFDEVICE %p is not a PNP device, device interfaces not allowed", Device); FxVerifierDbgBreakPoint(pFxDriverGlobals); return; }
pPkgPnp = pDevice->m_PkgPnp;
pPkgPnp->m_DeviceInterfaceLock.AcquireLock(pFxDriverGlobals);
// // Iterate over the interfaces and see if we have a match // for (ple = pPkgPnp->m_DeviceInterfaceHead.Next; ple != NULL; ple = ple->Next) { FxDeviceInterface *pDI;
pDI = FxDeviceInterface::_FromEntry(ple);
if (FxIsEqualGuid(&pDI->m_InterfaceClassGUID, InterfaceClassGUID)) { if (RefString != NULL) { if ((RefString->Length == pDI->m_ReferenceString.Length) && (RtlCompareMemory(RefString->Buffer, pDI->m_ReferenceString.Buffer, RefString->Length) == RefString->Length)) { // // They match, carry on // DO_NOTHING(); } else { // // The ref strings do not match, continue on in the search // of the collection. // continue; } } else if (pDI->m_ReferenceString.Length > 0) { // // Caller didn't specify a ref string but this interface has // one, continue on in the search through the collection. // continue; }
// // Set the state and break out of the loop because we found our // interface. // pDI->SetState(State); break; } }
pPkgPnp->m_DeviceInterfaceLock.ReleaseLock(pFxDriverGlobals);}
_Must_inspect_result___drv_maxIRQL(PASSIVE_LEVEL)NTSTATUSNTAPIWDFEXPORT(WdfDeviceRetrieveDeviceInterfaceString)( __in PWDF_DRIVER_GLOBALS DriverGlobals, __in WDFDEVICE Device, __in CONST GUID* InterfaceClassGUID, __in_opt PCUNICODE_STRING RefString, __in WDFSTRING String )/*++
Routine Description: Returns the symbolic link value of the registered device interface.
Arguments:
Return Value:
--*/
{ DDI_ENTRY();
PSINGLE_LIST_ENTRY ple; PFX_DRIVER_GLOBALS pFxDriverGlobals; FxDevice* pDevice; FxPkgPnp* pPkgPnp; FxString* pString; NTSTATUS status;
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE, (PVOID*) &pDevice, &pFxDriverGlobals );
FxPointerNotNull(pFxDriverGlobals, InterfaceClassGUID);
status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL); if (!NT_SUCCESS(status)) { return status; }
if (RefString != NULL) { status = FxValidateUnicodeString(pFxDriverGlobals, RefString); if (!NT_SUCCESS(status)) { return status; } }
if (pDevice->IsLegacy()) { status = STATUS_INVALID_DEVICE_REQUEST;
DoTraceLevelMessage( pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, "WDFDEVICE %p is not a PNP device, device interface creation not " "allowed %!STATUS!", Device, status);
return status; }
FxObjectHandleGetPtr(pFxDriverGlobals, String, FX_TYPE_STRING, (PVOID*) &pString);
pPkgPnp = pDevice->m_PkgPnp;
status = STATUS_OBJECT_NAME_NOT_FOUND;
pPkgPnp->m_DeviceInterfaceLock.AcquireLock(pFxDriverGlobals);
// // Iterate over the interfaces and see if we have a match // for (ple = pPkgPnp->m_DeviceInterfaceHead.Next; ple != NULL; ple = ple->Next) { FxDeviceInterface *pDI;
pDI = FxDeviceInterface::_FromEntry(ple);
if (FxIsEqualGuid(&pDI->m_InterfaceClassGUID, InterfaceClassGUID)) { if (RefString != NULL) { if ((RefString->Length == pDI->m_ReferenceString.Length) && (RtlCompareMemory(RefString->Buffer, pDI->m_ReferenceString.Buffer, RefString->Length) == RefString->Length)) { // // They match, carry on // DO_NOTHING(); } else { // // The ref strings do not match, continue on in the search // of the collection. // continue; } } else if (pDI->m_ReferenceString.Length > 0) { // // Caller didn't specify a ref string but this interface has // one, continue on in the search through the collection. // continue; }
status = pDI->GetSymbolicLinkName(pString);
break; } }
pPkgPnp->m_DeviceInterfaceLock.ReleaseLock(pFxDriverGlobals);
return status;}
} // extern "C"