예제 #1
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlImmediateChar
//
VOID
UartCtlImmediateChar(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status;

    UNREFERENCED_PARAMETER(Device);
    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    //
    // Interleaving an immediate character into the write path
    // has not been implemented in this sample.
    //

    status = STATUS_NOT_IMPLEMENTED;

    TraceMessage(TRACE_LEVEL_WARNING,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #2
0
파일: regutils.cpp 프로젝트: uri247/wdk80
VOID
UartEvaluateLineStatus(
    _In_ WDFDEVICE Device,
    _Out_ PBOOLEAN CanReceive,
    _Out_ PBOOLEAN CanTransmit,
    _Out_ PBOOLEAN HasErrors
    )
{
    UCHAR regLineStatus = 0;
    UCHAR oldErrorBits = 0;
    PUART_DEVICE_EXTENSION pDevExt = NULL;

    FuncEntry(TRACE_FLAG_REGUTIL);

    pDevExt = UartGetDeviceExtension(Device);

    regLineStatus = READ_LINE_STATUS(pDevExt, pDevExt->Controller);

    if (pDevExt->LineStatus != regLineStatus)
    {
        // LSR changed.
        // If there is an error indicated, binary OR it with the previous error.
        oldErrorBits = pDevExt->LineStatus & SERIAL_LSR_ERROR;
        pDevExt->LineStatus = regLineStatus | oldErrorBits;
    }

    pDevExt->HoldingEmpty = ((pDevExt->LineStatus & SERIAL_LSR_THRE) != 0);
    
    *CanReceive = ((pDevExt->LineStatus & SERIAL_LSR_DR) != 0);
    *CanTransmit = pDevExt->HoldingEmpty && UartFlowCanTransmit(Device);
    *HasErrors = ((pDevExt->LineStatus & SERIAL_LSR_ERROR) != 0);

    FuncExit(TRACE_FLAG_REGUTIL);
}
예제 #3
0
파일: Device.cpp 프로젝트: Realhram/wdk81
/////////////////////////////////////////////////////////////////////////
//
//  CMyDevice::OnReleaseHardware
//
//  Called by WUDF to uninitialize the hardware.
//
//  Parameters:
//      pWdfDevice - pointer to an IWDFDevice object for the device
//      pWdfResourcesTranslated - pointer to the translated resource list
//
//  Return Values:
//      status
//
/////////////////////////////////////////////////////////////////////////
HRESULT CMyDevice::OnReleaseHardware(
    _In_ IWDFDevice3 * pWdfDevice,
    _In_ IWDFCmResourceList * pWdfResourcesTranslated
    )
{
    FuncEntry();

    UNREFERENCED_PARAMETER(pWdfDevice);
    UNREFERENCED_PARAMETER(pWdfResourcesTranslated);

    HRESULT hr = S_OK;

    // Uninitialize and release the class extension.
    if (m_spClassExtension != nullptr)
    {
        hr = m_spClassExtension->Uninitialize();
    }
    
    // Uninitialize the sensor DDI
    if (m_pSensorDdi != nullptr)
    {
        m_pSensorDdi->Uninitialize();
        SAFE_RELEASE(m_pSensorDdi);
    }

    // Release the IWDFDevice handle, if it matches
    if (pWdfDevice == m_spWdfDevice.p)
    {
        m_spWdfDevice.Release();
    }

    FuncExit();

    return hr;
}
VOID
ControllerUninitialize(
    _In_  PPBC_DEVICE  pDevice
    )
/*++
 
  Routine Description:

    This routine uninitializes the controller hardware.

  Arguments:

    pDevice - a pointer to the PBC device context

  Return Value:

    None.

--*/
{
    FuncEntry(TRACE_FLAG_PBCLOADING);

    NT_ASSERT(pDevice != NULL);

    // TODO: Uninitialize controller hardware via the
    //       pDevice->pRegisters->* register interface
    //       if necessary.  Work may include disabling
    //       interrupts, etc.

    UNREFERENCED_PARAMETER(pDevice);

    FuncExit(TRACE_FLAG_PBCLOADING);
}
예제 #5
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlSetBreakOff
//
VOID
UartCtlSetBreakOff(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status;

    UNREFERENCED_PARAMETER(Device);
    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    //
    // Software flow control and in-band signaling 
    // have not been implemented in this sample.
    //

    status = STATUS_NOT_IMPLEMENTED;

    TraceMessage(TRACE_LEVEL_WARNING,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
VOID
ControllerInitialize(
    _In_  PPBC_DEVICE  pDevice
    )
/*++
 
  Routine Description:

    This routine initializes the controller hardware.

  Arguments:

    pDevice - a pointer to the PBC device context

  Return Value:

    None.

--*/
{
    FuncEntry(TRACE_FLAG_PBCLOADING);
                        
    NT_ASSERT(pDevice != NULL);

    // TODO: Initialize controller hardware via the
    //       pDevice->pRegisters->* register interface.
    //       Work may include configuring operating modes,
    //       FIFOs, clock, interrupts, etc.

    UNREFERENCED_PARAMETER(pDevice);

    FuncExit(TRACE_FLAG_PBCLOADING);
}
VOID
ControllerDisableInterrupts(
    _In_  PPBC_DEVICE   pDevice
    )
/*++
 
  Routine Description:

    This routine disables all controller interrupts.

  Arguments:

    pDevice - a pointer to the PBC device context

  Return Value:

    None.

--*/
{
    FuncEntry(TRACE_FLAG_TRANSFER);

    NT_ASSERT(pDevice != NULL);

    // TODO: Disable all interrupts.

    UNREFERENCED_PARAMETER(pDevice);

    FuncExit(TRACE_FLAG_TRANSFER);
}
예제 #8
0
파일: Device.cpp 프로젝트: Realhram/wdk81
/////////////////////////////////////////////////////////////////////////
//
//  CMyDevice::CreateInstance
//
//  This static method is used to create and initialize an instance of
//  CMyDevice for use with a given hardware device.
//
//  Parameters:
//      pDriver     - pointer to an IWDFDriver interface
//      pDeviceInit - pointer to an interface used to intialize the device
//      ppMyDevice  - pointer to a location to place the CMyDevice instance
//
//  Return Values:
//      status
//
/////////////////////////////////////////////////////////////////////////
HRESULT CMyDevice::CreateInstance(
    _In_  IWDFDriver*              pDriver,
    _In_  IWDFDeviceInitialize*    pDeviceInit,
    _Out_ CComObject<CMyDevice>**  ppMyDevice
    )
{
    FuncEntry();

    CComObject<CMyDevice>* pMyDevice = nullptr;

    HRESULT hr = CComObject<CMyDevice>::CreateInstance(&pMyDevice);

    if (SUCCEEDED(hr))
    {
        pMyDevice->AddRef();

        hr = pMyDevice->Initialize(pDriver, pDeviceInit);

        if (SUCCEEDED(hr))
        {
            *ppMyDevice = pMyDevice;
        }
    }

    FuncExit();

    return hr;
}
예제 #9
0
파일: Device.cpp 프로젝트: Realhram/wdk81
/////////////////////////////////////////////////////////////////////////
//
//  CMyDevice::ProcessIoControl
//
//  This method is a helper that takes the incoming IOCTL and forwards
//  it to the Windows Sensor Class Extension for processing.
//
//  Parameters:
//      pQueue                  - pointer to the UMDF queue that
//                                handled the request
//      pRequest                - pointer to the request
//      ControlCode             - the IOCTL code
//      InputBufferSizeInBytes  - size of the incoming IOCTL buffer
//      OutputBufferSizeInBytes - size of the outgoing IOCTL buffer
//      pcbWritten              - pointer to a DWORD containing the number
//                                of bytes returned
//
//  Return Values:
//      status
//
/////////////////////////////////////////////////////////////////////////
HRESULT CMyDevice::ProcessIoControl(
    _In_ IWDFIoQueue*     pQueue,
    _In_ IWDFIoRequest*   pRequest,
    _In_ ULONG            ControlCode,
         SIZE_T           InputBufferSizeInBytes,
         SIZE_T           OutputBufferSizeInBytes,
         DWORD*           pcbWritten)
{
    FuncEntry();

    UNREFERENCED_PARAMETER(pQueue);
    UNREFERENCED_PARAMETER(ControlCode);
    UNREFERENCED_PARAMETER(InputBufferSizeInBytes);
    UNREFERENCED_PARAMETER(OutputBufferSizeInBytes);
    UNREFERENCED_PARAMETER(pcbWritten);

    HRESULT hr = S_OK;
    
    if (m_spClassExtension == nullptr)
    {
        hr = E_POINTER;
    }
    
    if (SUCCEEDED(hr))
    {
        hr = m_spClassExtension->ProcessIoControl(pRequest);
    }

    FuncExit();

    return hr;
}
예제 #10
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlSetFifoControl
//
VOID
UartCtlSetFifoControl(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    UCHAR fifoControlRegister = 0;
    UCHAR fifoControlRegisterSaved = 0;
    PUCHAR pFifoControl = NULL;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveInputBuffer(Request, 
                    sizeof(UCHAR), 
                    (PVOID*)(& pFifoControl), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve input buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        // This value is not verified.  This is as specified in the documentation.
        fifoControlRegister = *pFifoControl;

        // Save the value of the FCR to be written, with the reset bits unset.
        fifoControlRegisterSaved = fifoControlRegister & 
                        (~(SERIAL_FCR_RCVR_RESET | SERIAL_FCR_TXMT_RESET));

        // Acquires the interrupt lock and writes the FCR.
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        WRITE_FIFO_CONTROL(pDevExt, pDevExt->Controller, fifoControlRegister);
        pDevExt->FifoControl = fifoControlRegisterSaved;
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #11
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlClearStats
//
VOID
UartCtlClearStats(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);
  
    WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
    RtlZeroMemory(&pDevExt->PerfStats, sizeof(SERIALPERF_STATS));
    WdfInterruptReleaseLock(pDevExt->WdfInterrupt);

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
VOID
ControllerAcknowledgeInterrupts(
    _In_  PPBC_DEVICE   pDevice,
    _In_  ULONG         InterruptMask
    )
/*++
 
  Routine Description:

    This routine acknowledges the
    specificed interrupt bits.

  Arguments:

    pDevice - a pointer to the PBC device context
    InterruptMask - interrupt bits to acknowledge

  Return Value:

    None.

--*/
{
    FuncEntry(TRACE_FLAG_TRANSFER);

    NT_ASSERT(pDevice != NULL);

    // TODO: Acknowledge requested interrupts.
    
    UNREFERENCED_PARAMETER(pDevice);
    UNREFERENCED_PARAMETER(InterruptMask);

    FuncExit(TRACE_FLAG_TRANSFER);
}
예제 #13
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlSetChars
//
VOID
UartCtlSetChars(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PSERIAL_CHARS pSpecialChars = NULL;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveInputBuffer(Request, 
                    sizeof(SERIAL_CHARS), 
                    (PVOID*)(& pSpecialChars), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve input buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        //
        // Software flow control and in-band signaling
        // have not been implemented in this sample. Characters
        // are not checked for valid range or values.
        //

        pDevExt->SpecialChars.EofChar = pSpecialChars->EofChar;
        pDevExt->SpecialChars.ErrorChar = pSpecialChars->ErrorChar;
        pDevExt->SpecialChars.BreakChar = pSpecialChars->BreakChar;
        pDevExt->SpecialChars.EventChar = pSpecialChars->EventChar;
        pDevExt->SpecialChars.XonChar = pSpecialChars->XonChar;
        pDevExt->SpecialChars.XoffChar = pSpecialChars->XoffChar;
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #14
0
VOID
OnTopLevelIoDefault(
    _In_  WDFQUEUE    FxQueue,
    _In_  WDFREQUEST  FxRequest
    )
/*++

  Routine Description:

    Accepts all incoming requests and pends or forwards appropriately.

  Arguments:

    FxQueue -  Handle to the framework queue object that is associated with the
        I/O request.
    FxRequest - Handle to a framework request object.

  Return Value:

    None.

--*/
{
    FuncEntry(TRACE_FLAG_SPBAPI);
    
    UNREFERENCED_PARAMETER(FxQueue);

    WDFDEVICE device;
    PDEVICE_CONTEXT pDevice;
    WDF_REQUEST_PARAMETERS params;
    NTSTATUS status;

    device = WdfIoQueueGetDevice(FxQueue);
    pDevice = GetDeviceContext(device);

    WDF_REQUEST_PARAMETERS_INIT(&params);

    WdfRequestGetParameters(FxRequest, &params);

	status = WdfRequestForwardToIoQueue(FxRequest, pDevice->SpbQueue);

	if (!NT_SUCCESS(status))
	{
		CyapaPrint(
			DEBUG_LEVEL_ERROR,
			DBG_IOCTL,
			"Failed to forward WDFREQUEST %p to SPB queue %p - %!STATUS!",
			FxRequest,
			pDevice->SpbQueue,
			status);
		
		WdfRequestComplete(FxRequest, status);
	}

    FuncExit(TRACE_FLAG_SPBAPI);
}
예제 #15
0
파일: unit.cpp 프로젝트: KWMalik/hiphop-php
const Func* Unit::getFunc(Offset pc) const {
  FuncEntry key = FuncEntry(pc, NULL);
  FuncTable::const_iterator it =
    upper_bound(m_funcTable.begin(), m_funcTable.end(), key);
  if (it != m_funcTable.end()) {
    ASSERT(pc < it->pastOffset());
    return it->val();
  }
  return NULL;
}
예제 #16
0
NTSTATUS
#pragma prefast(suppress:__WARNING_DRIVER_FUNCTION_TYPE, "thanks, i know this already")
DriverEntry(
    _In_ PDRIVER_OBJECT  DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
{
    /*WDF_DRIVER_CONFIG_INIT(&driverConfig, OnDeviceAdd);*/
	NTSTATUS               status = STATUS_SUCCESS;
	WDF_DRIVER_CONFIG      driverConfig;
	WDF_OBJECT_ATTRIBUTES  driverAttributes;
	WDFDRIVER fxDriver;

	WPP_INIT_TRACING(DriverObject, RegistryPath);

	FuncEntry(TRACE_FLAG_WDFLOADING);

	WDF_DRIVER_CONFIG_INIT(&driverConfig, OnDeviceAdd);
	driverConfig.DriverPoolTag = SPBT_POOL_TAG;

	WDF_OBJECT_ATTRIBUTES_INIT(&driverAttributes);
	driverAttributes.EvtCleanupCallback = OnDriverCleanup;

	//
	// Create a framework driver object to represent our driver.
	//

	status = WdfDriverCreate(DriverObject,
		RegistryPath,
		&driverAttributes,
		&driverConfig,
		&fxDriver
		);

	if (!NT_SUCCESS(status))
	{
		Trace(
			TRACE_LEVEL_ERROR,
			TRACE_FLAG_WDFLOADING,
			"Error creating WDF driver object - %!STATUS!",
			status);
		goto exit;
	}

	Trace(
		TRACE_LEVEL_VERBOSE,
		TRACE_FLAG_WDFLOADING,
		"Created WDF driver object");

exit:

	FuncExit(TRACE_FLAG_WDFLOADING);

	return status;
}
예제 #17
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlGetDtrrts
//
VOID
UartCtlGetDtrrts(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PULONG pBuffer;
    UCHAR regModemControl;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveOutputBuffer(Request, 
                    sizeof(ULONG), 
                    (PVOID*)(& pBuffer), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve output buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        regModemControl = READ_MODEM_CONTROL(pDevExt, pDevExt->Controller);
        regModemControl &= SERIAL_DTR_STATE | SERIAL_RTS_STATE;

        *pBuffer = regModemControl;

        WdfRequestSetInformation(Request, sizeof(ULONG));
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #18
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlGetBaudRate
//
VOID
UartCtlGetBaudRate(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PSERIAL_BAUD_RATE pBaudRate = NULL;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveOutputBuffer(Request, 
                    sizeof(SERIAL_BAUD_RATE), 
                    (PVOID*)(& pBaudRate), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve output buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        // Acquires the interrupt lock and retrieves the current baud rate.
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        pBaudRate->BaudRate = pDevExt->CurrentBaud;
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);

        WdfRequestSetInformation(Request, sizeof(SERIAL_BAUD_RATE));
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #19
0
파일: regutils.cpp 프로젝트: uri247/wdk80
USHORT UartWaitableEvents(
    _In_ WDFDEVICE Device
    )
{
    PUART_DEVICE_EXTENSION pDevExt = NULL;
    USHORT someEvent = 0;

    pDevExt = UartGetDeviceExtension(Device);    

    FuncEntry(TRACE_FLAG_REGUTIL);

    // Note that each if statement here is consistent in that it compares
    // LineStatus to SERIAL_LSR_* and compares ModemStatus to SERIAL_MSR_*.

    if ((pDevExt->LineStatus & SERIAL_LSR_DR) != 0)
        someEvent = someEvent | SERIAL_EV_RXCHAR;

    // SERIAL_EV_RXFLAG is not handled in this function.

    if ((pDevExt->LineStatus & SERIAL_LSR_TEMT) != 0)
        someEvent = someEvent | SERIAL_EV_TXEMPTY;

    if ((pDevExt->LineStatus & SERIAL_LSR_BI) != 0)
        someEvent = someEvent | SERIAL_EV_BREAK;

    if ((pDevExt->LineStatus & SERIAL_LSR_ERROR) != 0)
        someEvent = someEvent | SERIAL_EV_ERR;

    if ((pDevExt->ModemStatus & SERIAL_MSR_DCTS) != 0)
        someEvent = someEvent | SERIAL_EV_CTS;

    if ((pDevExt->ModemStatus & SERIAL_MSR_DDSR) != 0)
        someEvent = someEvent | SERIAL_EV_DSR;

    if ((pDevExt->ModemStatus & SERIAL_MSR_TERI) != 0)
        someEvent = someEvent | SERIAL_EV_RLSD;

    if ((pDevExt->ModemStatus & SERIAL_MSR_RI) != 0)
        someEvent = someEvent | SERIAL_EV_RING;

    // SERIAL_EV_PERR is not possible.
    // SERIAL_EV_RX80FULL is not handled in this function.
    // SERIAL_EV_EVENT1 is not possible.
    // SERIAL_EV_EVENT2 is not possible.

    // Clear the modem status events
    pDevExt->ModemStatus &= ~(SERIAL_MSR_EVENTS);

    FuncExit(TRACE_FLAG_REGUTIL);

    return someEvent;
}
예제 #20
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlGetModemControl
//
VOID
UartCtlGetModemControl(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PULONG pBuffer;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveOutputBuffer(Request, 
                    sizeof(ULONG), 
                    (PVOID*)(&pBuffer), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve output buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        // Acquires the interrupt lock and reads the modem control register.
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        *pBuffer = READ_MODEM_CONTROL(pDevExt, pDevExt->Controller);
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);

        WdfRequestSetInformation(Request, sizeof(ULONG));
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #21
0
VOID
OnDriverCleanup(
    _In_ WDFOBJECT Object
    )
{
    FuncEntry(TRACE_FLAG_WDFLOADING);

    UNREFERENCED_PARAMETER(Object);

    WPP_CLEANUP(nullptr);

    FuncExit(TRACE_FLAG_WDFLOADING);
}
예제 #22
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlGetStats
//
VOID
UartCtlGetStats(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PSERIALPERF_STATS pStats = NULL;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    status = WdfRequestRetrieveOutputBuffer(Request, 
                    sizeof(SERIALPERF_STATS), 
                    (PVOID*)(& pStats), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve output buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        *pStats = pDevExt->PerfStats;
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);

        WdfRequestSetInformation(Request, sizeof(SERIALPERF_STATS));
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #23
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlClrRts
//
VOID
UartCtlClrRts(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    UCHAR regModemControl;
    NTSTATUS status = STATUS_SUCCESS;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    if (((pDevExt->HandFlow.FlowReplace & SERIAL_RTS_MASK) ==
        SERIAL_RTS_HANDSHAKE) ||
        ((pDevExt->HandFlow.FlowReplace & SERIAL_RTS_MASK) ==
        SERIAL_TRANSMIT_TOGGLE))
    {
        status = STATUS_INVALID_PARAMETER;
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "RTS cannot be cleared when automatic RTS flow control or "
            "transmit toggling is used - %!STATUS!",
            status);
    }

    if (NT_SUCCESS(status))
    {
        // Acquires the interrupt lock and sets the MCR.
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        regModemControl = READ_MODEM_CONTROL(pDevExt, pDevExt->Controller);
        regModemControl &= ~SERIAL_MCR_RTS;
        WRITE_MODEM_CONTROL(pDevExt, pDevExt->Controller, regModemControl);
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #24
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlGetHandflow
//
VOID
UartCtlGetHandflow(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    PSERIAL_HANDFLOW pHandFlow = NULL;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

     status = WdfRequestRetrieveOutputBuffer(Request, 
                    sizeof(SERIAL_HANDFLOW), 
                    (PVOID*)(& pHandFlow), 
                    NULL);

    if (!NT_SUCCESS(status))
    {
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "Failed to retrieve output buffer for WDFREQUEST %p - "
            "%!STATUS!",
            Request,
            status);
    }

    if (NT_SUCCESS(status))
    {
        *pHandFlow = pDevExt->HandFlow;

        WdfRequestSetInformation(Request, sizeof(SERIAL_HANDFLOW));
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #25
0
파일: Device.cpp 프로젝트: Realhram/wdk81
/////////////////////////////////////////////////////////////////////////
//
//  CMyDevice::OnCleanupFile
//
//  This method is called when the file handle to the device is closed
//
//  Parameters:
//      pWdfFile - pointer to a file object
//
//  Return Values:
//      none
//
/////////////////////////////////////////////////////////////////////////
VOID CMyDevice::OnCleanupFile(
    _In_ IWDFFile* pWdfFile
    )
{
    FuncEntry();

    if (m_spClassExtension != nullptr)
    {
        m_spClassExtension->CleanupFile(pWdfFile);
    }

    FuncExit();

    return;
}
예제 #26
0
파일: ioctls.cpp 프로젝트: 340211173/Driver
//
// Internal Function: UartCtlSetDtr
//
VOID
UartCtlSetDtr(
    _In_ WDFDEVICE Device, 
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength
    )
{
    PUART_DEVICE_EXTENSION pDevExt = UartGetDeviceExtension(Device);
    UCHAR regModemControl;
    NTSTATUS status = STATUS_SUCCESS;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    FuncEntry(TRACE_FLAG_CONTROL);

    if ((pDevExt->HandFlow.ControlHandShake & SERIAL_DTR_MASK) ==
        SERIAL_DTR_HANDSHAKE)
    {
        status = STATUS_INVALID_PARAMETER;
        TraceMessage(
            TRACE_LEVEL_ERROR,
            TRACE_FLAG_CONTROL,
            "DTR cannot be set when automatic DTR flow control is used - "
            "%!STATUS!",
            status);
    }

    if (NT_SUCCESS(status))
    {
        // Acquires the interrupt lock and sets the MCR.
        WdfInterruptAcquireLock(pDevExt->WdfInterrupt);
        regModemControl = READ_MODEM_CONTROL(pDevExt, pDevExt->Controller);
        regModemControl |= SERIAL_MCR_DTR;
        WRITE_MODEM_CONTROL(pDevExt, pDevExt->Controller, regModemControl);
        WdfInterruptReleaseLock(pDevExt->WdfInterrupt);
    }

    TraceMessage(TRACE_LEVEL_INFORMATION,
                    TRACE_FLAG_CONTROL,
                    "WdfRequestComplete( %!HANDLE! => %!STATUS! )",
                    Request,
                    status);
    WdfRequestComplete(Request, status);

    FuncExit(TRACE_FLAG_CONTROL);
}
예제 #27
0
파일: Device.cpp 프로젝트: Realhram/wdk81
/////////////////////////////////////////////////////////////////////////
//
//  CMyDevice::Configure
//  
//  This method is called after the device callback object has been initialized 
//  and returned to the driver.  It would setup the device's queues and their 
//  corresponding callback objects.
//
//  Parameters:
//
//  Return Values:
//      status
//
/////////////////////////////////////////////////////////////////////////
HRESULT CMyDevice::Configure()
{
    FuncEntry();

    HRESULT hr = CMyQueue::CreateInstance(m_spWdfDevice, this);

    if (FAILED(hr))
    {
        Trace(
            TRACE_LEVEL_ERROR,
            "Failed to create instance of CMyQueue, %!HRESULT!",
            hr);
    }

    FuncExit();

    return hr;
}
예제 #28
0
NTSTATUS BOOTTRACKPAD(
	_In_  PDEVICE_CONTEXT  pDevice
	)
{
	NTSTATUS status = 0;

	static char bl_exit[] = {
		0x00, 0xff, 0xa5, 0x00, 0x01,
		0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

	static char bl_deactivate[] = {
		0x00, 0xff, 0x3b, 0x00, 0x01,
		0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

	cyapa_boot_regs boot;

	FuncEntry(TRACE_FLAG_WDFLOADING);

	SpbReadDataSynchronously(&pDevice->I2CContext, CMD_BOOT_STATUS, &boot, sizeof(boot));

	if ((boot.stat & CYAPA_STAT_RUNNING) == 0) {
		if (boot.error & CYAPA_ERROR_BOOTLOADER)
			SpbWriteDataSynchronously(&pDevice->I2CContext, CMD_BOOT_STATUS, bl_deactivate, sizeof(bl_deactivate));
		else
			SpbWriteDataSynchronously(&pDevice->I2CContext, CMD_BOOT_STATUS, bl_exit, sizeof(bl_exit));
	}

	WDF_TIMER_CONFIG              timerConfig;
	WDFTIMER                      hTimer;
	WDF_OBJECT_ATTRIBUTES         attributes;

	WDF_TIMER_CONFIG_INIT(&timerConfig, CyapaBootTimer);

	WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
	attributes.ParentObject = pDevice->FxDevice;
	status = WdfTimerCreate(&timerConfig, &attributes, &hTimer);

	WdfTimerStart(hTimer, WDF_REL_TIMEOUT_IN_MS(75));

	FuncExit(TRACE_FLAG_WDFLOADING);
	return status;
}
예제 #29
0
NTSTATUS BOOTTRACKPAD(
	_In_  PDEVICE_CONTEXT  pDevice
	)
{
	if (deviceLoaded)
		return 0;

	NTSTATUS status = 0;

	static char bl_exit[] = {
		0x00, 0xff, 0xa5, 0x00, 0x01,
		0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

	FuncEntry(TRACE_FLAG_WDFLOADING);
	SpbWriteDataSynchronously(&pDevice->I2CContext, 0x00, bl_exit, sizeof(bl_exit));
	FuncExit(TRACE_FLAG_WDFLOADING);

	deviceLoaded = true;
	return status;
}
예제 #30
0
NTSTATUS
OnD0Entry(
    _In_  WDFDEVICE               FxDevice,
    _In_  WDF_POWER_DEVICE_STATE  FxPreviousState
    )
/*++
 
  Routine Description:

    This routine allocates objects needed by the driver.

  Arguments:

    FxDevice - a handle to the framework device object
    FxPreviousState - previous power state

  Return Value:

    Status

--*/
{
    FuncEntry(TRACE_FLAG_WDFLOADING);
    
    UNREFERENCED_PARAMETER(FxPreviousState);

    PDEVICE_CONTEXT pDevice = GetDeviceContext(FxDevice);
    NTSTATUS status = STATUS_SUCCESS;

	WdfTimerStart(pDevice->Timer, WDF_REL_TIMEOUT_IN_MS(10));

	BOOTTRACKPAD(pDevice);

	pDevice->RegsSet = false;
	pDevice->ConnectInterrupt = true;

    FuncExit(TRACE_FLAG_WDFLOADING);

    return status;
}