static VOID
NfcCxSNEPInterfaceConnCB(
    _In_ VOID *pContext,
    _In_ NFCSTATUS NfcStatus,
    _In_ phLibNfc_Handle ConnHandle
    )
{
    PNFCCX_SNEP_INTERFACE snepInterface = (PNFCCX_SNEP_INTERFACE)pContext;
    PNFCCX_RF_INTERFACE rfInterface = NfcCxSNEPInterfaceGetRFInterface(snepInterface);

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    if (NFCSTATUS_INCOMING_CONNECTION == NfcStatus) {
        TRACE_LINE(LEVEL_INFO, "Incoming Connection %p", ConnHandle);
        snepInterface->pConnHandleDef = ConnHandle;
        NfcStatus = phLibNfc_SnepServer_Accept(&snepInterface->sDataInbox,
                                               &snepInterface->sConfigInfo.sOptions,
                                               rfInterface->pLibNfcContext->pRemDevList[0].hTargetDev,
                                               snepInterface->pServerHandleDef,
                                               snepInterface->pConnHandleDef,
                                               NfcCxSNEPInterfaceServerPutNtfCB,
                                               NULL,
                                               (VOID *)snepInterface);
    }
    else if (NFCSTATUS_CONNECTION_SUCCESS == NfcStatus) {
        TRACE_LINE(LEVEL_INFO, "Connection Success");
    }
    else {
        TRACE_LINE(LEVEL_INFO, "Connection Failed, %!NFCSTATUS!", NfcStatus);
    }

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
}
NTSTATUS
FileObjectContext::Create()
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    UNICODE_STRING* fileObjectName = WdfFileObjectGetFileName(_FileObject);
    if (CSTR_EQUAL == CompareStringOrdinal(fileObjectName->Buffer, fileObjectName->Length / sizeof(WCHAR), L"\\" FILE_NAMESPACE_NCI_SIMULATOR, int(wcslen(L"\\" FILE_NAMESPACE_NCI_SIMULATOR)), /*IgnoreCase*/ TRUE))
    {
        _Type = Type::NciSim;
    }
    else
    {
        status = STATUS_OBJECT_NAME_NOT_FOUND;
        TRACE_LINE(LEVEL_ERROR, "Unknown file namespace: %S. %!STATUS!", fileObjectName->Buffer, status);
        return status;
    }

    status = _DeviceContext->ClientConnected(this);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "DeviceContext::ClientConnected failed. %!STATUS!", status);
        return status;
    }

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
NTSTATUS
DeviceContext::CommandNciRead(
    _In_ WDFREQUEST Request
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    WDFMEMORY nciPacket;
    status = WdfRequestRetrieveInputMemory(Request, &nciPacket);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "WdfRequestRetrieveInputMemory failed. %!STATUS!", status);
        return status;
    }

    status = NfcCxNciReadNotification(_Device, nciPacket);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "NfcCxNciReadNotification failed. %!STATUS!", status);
        return status;
    }

    WdfRequestComplete(Request, STATUS_SUCCESS);

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
static VOID
NfcCxSNEPInterfaceClientConnCB(
    _In_ PVOID pContext, 
    _In_ NFCSTATUS NfcStatus, 
    _In_ phLibNfc_Handle ConnHandle
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    PNFCCX_SNEP_INTERFACE snepInterface = ((PNFCCX_SNEP_LIBNFC_REQUEST_CONTEXT)pContext)->SNEPInterface;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    snepInterface->pClientHandleDef = ConnHandle;

    if (NULL != snepInterface->pClientHandleDef && NFCSTATUS_CONNECTION_SUCCESS == NfcStatus) {
        TRACE_LINE(LEVEL_INFO, "Connection Success %p", ConnHandle);
        NfcCxRFInterfaceP2pConnectionEstablished(NfcCxSNEPInterfaceGetRFInterface(snepInterface));
    }
    else {
        TRACE_LINE(LEVEL_ERROR, "Connection Failed, %!NFCSTATUS!", NfcStatus);
        status = STATUS_UNSUCCESSFUL;
    }

    NfcCxInternalSequence(NfcCxSNEPInterfaceGetRFInterface(snepInterface), ((PNFCCX_SNEP_LIBNFC_REQUEST_CONTEXT)pContext)->Sequence, status, NULL, NULL);

    TRACE_FUNCTION_EXIT_NTSTATUS(LEVEL_VERBOSE, status);
}
NTSTATUS
NfcCxSNEPInterfaceDeinit(
    _In_ PNFCCX_SNEP_INTERFACE SNEPInterface
    )
{
    NFCSTATUS nfcStatus = NFCSTATUS_SUCCESS;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    if (NULL != SNEPInterface->pClientHandleDef) {
        nfcStatus = phLibNfc_SnepClient_DeInit(SNEPInterface->pClientHandleDef);
        SNEPInterface->pClientHandleDef = NULL;
        TRACE_LINE(LEVEL_INFO, "phLibNfc_SnepClient_DeInit returned %!NFCSTATUS!", nfcStatus);
    }

    if (NULL != SNEPInterface->pServerHandleDef) {
        nfcStatus = phLibNfc_SnepServer_DeInit(SNEPInterface->pServerHandleDef);
        SNEPInterface->sDataInbox.length = MAX_INBOX_SIZE;
        SNEPInterface->pServerHandleDef = NULL;
        TRACE_LINE(LEVEL_INFO, "phLibNfc_SnepServer_DeInit returned %!NFCSTATUS!", nfcStatus);
    }

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
HRESULT CNfcRadioManager::FireOnInstanceChange(
    _In_ IRadioInstance *pnfcRadioInstanceObj
    )
{
    TRACE_METHOD_ENTRY(LEVEL_VERBOSE);

    HRESULT hr = S_OK;
    DEVICE_RADIO_STATE radioStateCurrent = DRS_HW_RADIO_OFF_UNCONTROLLABLE;
    BSTR bstrInstanceID = NULL;
        
    hr = pnfcRadioInstanceObj->GetInstanceSignature(&bstrInstanceID);

    if (SUCCEEDED(hr))
    {
        hr = pnfcRadioInstanceObj->GetRadioState(&radioStateCurrent);
    }

    if (SUCCEEDED(hr))
    {
        //
        // Use ATL standard lock to be sync with Advise()/UnAdvise()
        // This can make sure sink is still alive when event is raised
        //
        Lock();

        for (IUnknown** ppUnkSrc = m_vec.begin(); ppUnkSrc < m_vec.end(); ppUnkSrc++)
        {
            if ((NULL != ppUnkSrc) && (NULL != *ppUnkSrc))
            {
                CComPtr<IMediaRadioManagerNotifySink> spSink;

                hr = (*ppUnkSrc)->QueryInterface(IID_PPV_ARGS(&spSink));

                if (SUCCEEDED(hr))
                {
                    hr = spSink->OnInstanceRadioChange(bstrInstanceID, radioStateCurrent);

                    if (FAILED(hr))
                    {
                        TRACE_LINE(LEVEL_ERROR, L"NotifySink OnInstanceRadioChange Failed");
                    }
                    else
                    {
                        TRACE_LINE(LEVEL_VERBOSE, L"FireOnInstanceChange completed successfully");
                    }
                }
            }
        }
        Unlock();
    }

    if (bstrInstanceID)
    {
        SysFreeString(bstrInstanceID);
    }

    TRACE_METHOD_EXIT_HR(LEVEL_COND, hr);
    return hr;
}
NTSTATUS
NfcCxEvtSetLlcpConfig(
    _In_ PNFCCX_DRIVER_GLOBALS NfcCxGlobals,
    _In_ WDFDEVICE Device,
    _In_ PCNFC_CX_LLCP_CONFIG Config
    )
/*++

Routine Description:

    This routine is called by the CX client to configure
    the RF discovery settings.

Arguments:

    NfcCxGlobal - CX global pointer
    Device - WDF device to initialize
    Config - Pointer to a structure containing the LLCP configuration

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS status = STATUS_SUCCESS;
    PNFCCX_FDO_CONTEXT fdoContext;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    if (!VerifyPrivateGlobals(NfcCxGlobals)) {
        TRACE_LINE(LEVEL_ERROR, "Invalid CX global pointer");
        status = STATUS_INVALID_PARAMETER;
        goto Done;
    }

    if (NULL == Config ||
        sizeof(*Config) != Config->Size) {
        TRACE_LINE(LEVEL_ERROR, "Invalid Client Driver Configuration");
        status = STATUS_INVALID_PARAMETER;
        goto Done;
    }

    fdoContext = NfcCxFdoGetContext(Device);

    if (fdoContext->RFInterface == NULL) {
        TRACE_LINE(LEVEL_ERROR, "CX not initialized");
        status = STATUS_INVALID_DEVICE_STATE;
        goto Done;
    }

    status = NfcCxRFInterfaceSetLLCPConfig(fdoContext->RFInterface, Config);

Done:

    TRACE_FUNCTION_EXIT_NTSTATUS(LEVEL_VERBOSE, status);
    return status;
}
NTSTATUS
NfcCxEvtDeviceDeinitialize(
    _In_ PNFCCX_DRIVER_GLOBALS NfcCxGlobals,
    _In_ WDFDEVICE Device
    )
/*++

Routine Description:

    This routine is called by the CX client to indicate
    that a device deinitialization is required.

Arguments:

    NfcCxGlobal - CX global pointer
    Device - WDF device to initialize

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS status = STATUS_SUCCESS;
    PNFCCX_FDO_CONTEXT fdoContext;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    if (!VerifyPrivateGlobals(NfcCxGlobals)) {
        TRACE_LINE(LEVEL_ERROR, "Invalid CX global pointer");
        status = STATUS_INVALID_PARAMETER;
        goto Done;
    }

    fdoContext = NfcCxFdoGetContext(Device);

    status = NfcCxFdoCleanup(fdoContext);
    if (!NT_SUCCESS(status)) {
        TRACE_LINE(LEVEL_ERROR, "Failed to cleanup the Fdo context failed %!STATUS!", status);
        goto Done;
    }

Done:

    TRACE_FUNCTION_EXIT_NTSTATUS(LEVEL_VERBOSE, status);
    TRACE_LOG_NTSTATUS_ON_FAILURE(status);
    
    return status;
}
NTSTATUS
NfcCxSNEPInterfaceCreate(
    _In_ PNFCCX_RF_INTERFACE RFInterface,
    _Out_ PNFCCX_SNEP_INTERFACE * PPSNEPInterface
    )
{
    NTSTATUS status = STATUS_SUCCESS;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    *PPSNEPInterface = (PNFCCX_SNEP_INTERFACE)malloc(sizeof(NFCCX_SNEP_INTERFACE));
    if (NULL == *PPSNEPInterface) {
        TRACE_LINE(LEVEL_ERROR, "Insufficient resources");
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto Done;
    }
    RtlZeroMemory(*PPSNEPInterface, sizeof(NFCCX_SNEP_INTERFACE));

    (*PPSNEPInterface)->FdoContext = RFInterface->FdoContext;

    (*PPSNEPInterface)->sDataInbox.buffer = (PUCHAR)malloc(MAX_INBOX_SIZE);
    if(NULL == (*PPSNEPInterface)->sDataInbox.buffer) {
        TRACE_LINE(LEVEL_ERROR, "Failed to allocate the SNEP inbox buffer");
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto Done;
    }
    
    (*PPSNEPInterface)->sDataInbox.length = MAX_INBOX_SIZE;
    RtlZeroMemory((*PPSNEPInterface)->sDataInbox.buffer, MAX_INBOX_SIZE);

    (*PPSNEPInterface)->sConfigInfo.SnepServerType = phLibNfc_SnepServer_Default;
    (*PPSNEPInterface)->sConfigInfo.SnepServerName = NULL;
    (*PPSNEPInterface)->sConfigInfo.sOptions.miu = 
                        RFInterface->pLibNfcContext->LLCPInterface->sLlcpConfigParams.uMIU;
    (*PPSNEPInterface)->sConfigInfo.sOptions.rw = 
                        RFInterface->pLibNfcContext->LLCPInterface->sLlcpConfigParams.uRecvWindowSize;

Done:
    if (!NT_SUCCESS(status)) {
        if (NULL != *PPSNEPInterface) {
            NfcCxSNEPInterfaceDestroy(*PPSNEPInterface);
            *PPSNEPInterface = NULL;
        }
    }

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
    return status;
}
Esempio n. 10
0
static cell AMX_NATIVE_CALL trace_normal(AMX *amx, cell *params)
{
	int iEnt = params[1];

	cell *cStart = MF_GetAmxAddr(amx, params[2]);
	cell *cEnd = MF_GetAmxAddr(amx, params[3]);
	REAL fStartX = amx_ctof(cStart[0]);
	REAL fStartY = amx_ctof(cStart[1]);
	REAL fStartZ = amx_ctof(cStart[2]);
	REAL fEndX = amx_ctof(cEnd[0]);
	REAL fEndY = amx_ctof(cEnd[1]);
	REAL fEndZ = amx_ctof(cEnd[2]);

	cell *vRet = MF_GetAmxAddr(amx, params[4]);

	Vector vStart = Vector(fStartX, fStartY, fStartZ);
	Vector vEnd = Vector(fEndX, fEndY, fEndZ);

	TraceResult tr;
	TRACE_LINE(vStart, vEnd, dont_ignore_monsters, INDEXENT2(iEnt), &tr);

	vRet[0] = amx_ftoc(tr.vecPlaneNormal.x);
	vRet[1] = amx_ftoc(tr.vecPlaneNormal.y);
	vRet[2] = amx_ftoc(tr.vecPlaneNormal.z);

	if (tr.flFraction >= 1.0)
		return 0;

	return 1;
}
HRESULT CNfcRadioManager::FireOnInstanceRemove(_In_ BSTR bstrRadioInstanceID)
{
    UNREFERENCED_PARAMETER(bstrRadioInstanceID);

    TRACE_METHOD_ENTRY(LEVEL_VERBOSE);
    
    HRESULT hr = S_OK;
    
    //
    // Use ATL standard lock to be sync with Advise()/UnAdvise()
    // This can make sure sink is still alive when event is raised
    //
    Lock();
    for (IUnknown** ppUnkSrc = m_vec.begin(); ppUnkSrc < m_vec.end(); ppUnkSrc++)
    {
        if ((nullptr != ppUnkSrc) && (nullptr != *ppUnkSrc))
        {
            CComPtr<IMediaRadioManagerNotifySink> spSink;

            hr = (*ppUnkSrc)->QueryInterface(IID_PPV_ARGS(&spSink));
            if (SUCCEEDED(hr))
            {
                spSink->OnInstanceRemove(bstrRadioInstanceID);
                TRACE_LINE(LEVEL_VERBOSE, L"FireOnInstanceRemove completed successfully");
            }
        }
    }
    Unlock();

    TRACE_METHOD_EXIT_HR(LEVEL_COND, hr);
    return hr;
}
static VOID
NfcCxLLCPInterfaceLinkStatusCB(
    _In_ VOID *pContext,
    _In_ phFriNfc_LlcpMac_eLinkStatus_t eLinkStatus
)
{
    PNFCCX_LLCP_INTERFACE LLCPInterface = (NFCCX_LLCP_INTERFACE*)pContext;
    PNFCCX_RF_INTERFACE RFInterface = NfcCxLLCPInterfaceGetRFInterface(LLCPInterface);

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    LLCPInterface->eLinkStatus = eLinkStatus;

    TRACE_LINE(LEVEL_INFO, "Link Status: %!phFriNfc_LlcpMac_eLinkStatus_t!", eLinkStatus);

    switch (eLinkStatus)
    {
    case phFriNfc_LlcpMac_eLinkActivated:
    {
        NfcCxSNEPInterfaceServerInit(RFInterface->pLibNfcContext->SNEPInterface);
        NfcCxPostLibNfcThreadMessage(RFInterface, LIBNFC_STATE_HANDLER, NfcCxEventActivated, NULL, NULL, NULL);
    }
    break;

    case phFriNfc_LlcpMac_eLinkDeactivated:
    {
        NfcCxRFInterfaceP2pConnectionLost(RFInterface);
        NfcCxSNEPInterfaceDeinit(NfcCxLLCPInterfaceGetLibNfcContext(LLCPInterface)->SNEPInterface);
        NfcCxPostLibNfcThreadMessage(RFInterface, LIBNFC_STATE_HANDLER, NfcCxEventDeactivated, NULL, NULL, NULL);
    }
    break;
    }

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
}
NTSTATUS
NfcCxLLCPInterfaceCreate(
    _In_ PNFCCX_RF_INTERFACE RFInterface,
    _Outptr_ PNFCCX_LLCP_INTERFACE * PPLLCPInterface
)
{
    NTSTATUS status = STATUS_SUCCESS;

    *PPLLCPInterface = (PNFCCX_LLCP_INTERFACE)malloc(sizeof(NFCCX_LLCP_INTERFACE));
    if (NULL == *PPLLCPInterface) {
        TRACE_LINE(LEVEL_ERROR, "Insufficient resources");
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto Done;
    }
    RtlZeroMemory(*PPLLCPInterface, sizeof(NFCCX_LLCP_INTERFACE));

    (*PPLLCPInterface)->FdoContext = RFInterface->FdoContext;
    (*PPLLCPInterface)->sLlcpConfigParams.uMIU = NFC_CX_LLCP_MIU_DEFAULT;
    (*PPLLCPInterface)->sLlcpConfigParams.uLTO = NFC_CX_LLCP_LTO_DEFAULT;
    (*PPLLCPInterface)->sLlcpConfigParams.uRecvWindowSize = NFC_CX_LLCP_RECV_WINDOW_SIZE;
    (*PPLLCPInterface)->eLinkStatus = phFriNfc_LlcpMac_eLinkDeactivated;
    (*PPLLCPInterface)->eRequestState = NFCCX_LLCP_REQUEST_COMPLETE;

Done:
    if (!NT_SUCCESS(status)) {
        if (NULL != *PPLLCPInterface) {
            NfcCxLLCPInterfaceDestroy(*PPLLCPInterface);
            *PPLLCPInterface = NULL;
        }
    }
    return status;
}
StorageCardManager*
StorageCardManager::Create(
                            _In_ phNfc_eRemDevType_t DeviceType,
                            _In_ DWORD Sak,
                            _In_ PNFCCX_SC_INTERFACE PSCInterface
                            )
{
    StorageCardManager* pManager = NULL;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    pManager = new StorageCardManager(DeviceType, Sak, PSCInterface);

    if (pManager == NULL) {
        TRACE_LINE(LEVEL_ERROR, "Insufficient resources");
        goto Done;
    }

    if (pManager->m_pStorageClass == NULL) {
        delete pManager;
        pManager = NULL;
    }

Done:
    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
    return pManager;
}
Esempio n. 15
0
static cell AMX_NATIVE_CALL is_visible(AMX *amx, cell *params)
{
	int src = params[1];
	int dest = params[2];
	CHECK_ENTITY(src);
	CHECK_ENTITY(dest);

	edict_t *pEntity = INDEXENT2(src);
	edict_t *pTarget = INDEXENT2(dest);

	if (pTarget->v.flags & FL_NOTARGET)
		return 0;

	Vector vLooker = pEntity->v.origin + pEntity->v.view_ofs;
	Vector vTarget = pTarget->v.origin + pTarget->v.view_ofs;

    TraceResult tr;

	TRACE_LINE(vLooker, vTarget, FALSE, pEntity, &tr);

	if (tr.fInOpen && tr.fInWater)
		return 0;
	else if (tr.flFraction == 1.0)
		return 1;
	
	return 0;
}
NTSTATUS
DeviceContext::CommandNciWriteComplete(
    _In_ WDFREQUEST Request
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    WdfWaitLockAcquire(_ClientLock, nullptr);

    if (_NciWriteRequest == nullptr)
    {
        status = STATUS_INVALID_DEVICE_STATE;
        TRACE_LINE(LEVEL_ERROR, "No NCI write request is pending. %!STATUS!", status);
        WdfWaitLockRelease(_ClientLock);
        return status;
    }

    WDFREQUEST nciWriteRequest = _NciWriteRequest;
    _NciWriteRequest = nullptr;

    WdfWaitLockRelease(_ClientLock);

    // Complete NCI write I/O request.
    WdfRequestComplete(nciWriteRequest, STATUS_SUCCESS);

    // Complete I/O request.
    WdfRequestComplete(Request, STATUS_SUCCESS);

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
static VOID
NfcCxSNEPInterfaceServerPutNtfCB(
    _In_ VOID *pContext, 
    _In_ NFCSTATUS NfcStatus, 
    _In_ phLibNfc_Data_t *pDataInbox,
    _In_ phLibNfc_Handle ConnHandle
    )
{
    PNFCCX_SNEP_INTERFACE snepInterface = (PNFCCX_SNEP_INTERFACE)pContext;

    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    UNREFERENCED_PARAMETER(ConnHandle);

    if (NfcStatus == NFCSTATUS_SUCCESS) {
        TRACE_LINE(LEVEL_INFO, "Data received = %d bytes", pDataInbox->length);
        NfcStatus = phLibNfc_SnepProtocolSrvSendResponse(snepInterface->pConnHandleDef,
                                                         NULL,
                                                         NFCSTATUS_SUCCESS,
                                                         NfcCxSNEPInterfaceServerRspNtfCB,
                                                         (VOID *)snepInterface);
    }

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
}
// Called when a NciSim file handle is opened.
NTSTATUS
DeviceContext::ClientConnected(
    _In_ FileObjectContext* FileContext
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    WdfWaitLockAcquire(_ClientLock, nullptr);

    // Ensure there is only a single client connected at a time.
#ifdef WDF_IS_NOT_CALLING_FILE_CLOSE
    if (_CurrentSimClient)
    {
        WdfWaitLockRelease(_ClientLock);

        NTSTATUS status = STATUS_ACCESS_DENIED;
        TRACE_LINE(LEVEL_ERROR, "A client is already connected. %!STATUS!", status);
        return status;
    }
#endif

    _CurrentSimClient = FileContext;

    WdfWaitLockRelease(_ClientLock);

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
void
FileObjectContext::CreateCallback(
    _In_ WDFDEVICE Device,
    _In_ WDFREQUEST Request,
    _In_ WDFFILEOBJECT FileObject
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    DeviceContext* deviceContext = DeviceGetContext(Device);
    FileObjectContext* fileContext = FileObjectGetContext(FileObject);

    // Initialize class (using placement new operator).
    new (fileContext) FileObjectContext();
    fileContext->_FileObject = FileObject;
    fileContext->_DeviceContext = deviceContext;

    NTSTATUS status = fileContext->Create();
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "Create failed. %!STATUS!", status);
        WdfRequestComplete(Request, status);
    }

    WdfRequestComplete(Request, STATUS_SUCCESS);
    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
}
Esempio n. 20
0
void PlayerPostThink_Post(edict_t *pEntity)
{
	if(plinfo[ENTINDEX(pEntity)].pViewEnt) {
		edict_t *pCamEnt = plinfo[ENTINDEX(pEntity)].pViewEnt;

		MAKE_VECTORS(pEntity->v.v_angle + pEntity->v.punchangle);
		Vector vecSrc	 = pEntity->v.origin + pEntity->v.view_ofs;
		Vector vecAiming = gpGlobals->v_forward;
		TraceResult tr;

		switch(plinfo[ENTINDEX(pEntity)].iViewType) {
			case CAMERA_3RDPERSON:
				TRACE_LINE(vecSrc, vecSrc - (vecAiming * 128), ignore_monsters, ENT(pEntity), &tr);
				SET_VIEW(pEntity, pCamEnt);
				pCamEnt->v.origin = tr.vecEndPos;
				pCamEnt->v.angles = pEntity->v.v_angle;
				break;
			case CAMERA_UPLEFT:
				TRACE_LINE(vecSrc, vecSrc - ((vecAiming * 32) - ((gpGlobals->v_right * 15) + (gpGlobals->v_up * 15))), ignore_monsters, ENT(pEntity), &tr);
				SET_VIEW(pEntity, pCamEnt);
				pCamEnt->v.origin = tr.vecEndPos;
				pCamEnt->v.angles = pEntity->v.v_angle;
				break;
			case CAMERA_TOPDOWN:
				TRACE_LINE(vecSrc, vecSrc + Vector(0,0,2048), dont_ignore_monsters, ENT(pEntity), &tr);
				SET_VIEW(pEntity, pCamEnt);
				pCamEnt->v.origin = tr.vecEndPos;
				pCamEnt->v.origin.z -= 40;
				pCamEnt->v.angles = Vector(90,pEntity->v.v_angle.y,0);
				break;
			default:
				SET_VIEW(pEntity, pEntity);
				REMOVE_ENTITY(plinfo[ENTINDEX(pEntity)].pViewEnt);
				plinfo[ENTINDEX(pEntity)].iViewType = CAMERA_NONE;
				plinfo[ENTINDEX(pEntity)].pViewEnt = NULL;
				break;
		}
	}

	if (PlayerPostThinkForward != -1)
	{
		if (MF_ExecuteForward(PlayerPostThinkForward, (cell)ENTINDEX(pEntity)))
			RETURN_META(MRES_SUPERCEDE);
	}

	RETURN_META(MRES_IGNORED);
}
// Called when a NciSim file handle is closed.
void
DeviceContext::ClientDisconnected(
    _In_ FileObjectContext* FileContext
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    WdfWaitLockAcquire(_ClientLock, nullptr);

    if (FileContext != _CurrentSimClient)
    {
        WdfWaitLockRelease(_ClientLock);
        TRACE_LINE(LEVEL_WARNING, "Incorrect client.");
        return;
    }

    _CurrentSimClient = nullptr;

    // Acquire the pending NCI write request (if any).
    WDFREQUEST nciWriteRequest = _NciWriteRequest;
    _NciWriteRequest = nullptr;

    // Acquire the sequence completed function (if any).
    PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE sequenceCompleted = _SequenceCompleted;
    WDFCONTEXT sequenceCompletedContext = _SequenceCompletedContext;

    _SequenceCompleted = nullptr;
    _SequenceCompletedContext = nullptr;

    WdfWaitLockRelease(_ClientLock);

    if (nciWriteRequest)
    {
        TRACE_LINE(LEVEL_WARNING, "NCI write request was not completed by test client. Completing with error.");
        WdfRequestComplete(nciWriteRequest, STATUS_CONNECTION_DISCONNECTED);
    }

    if (sequenceCompleted)
    {
        // Complete the pending sequence handler, to help prevent the driver from getting into a blocked state.
        TRACE_LINE(LEVEL_INFO, "Completing leftover sequence handler.");
        sequenceCompleted(_Device, STATUS_SUCCESS, 0, sequenceCompletedContext);
    }

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
}
NTSTATUS
DeviceContext::CommandSequenceHandlerComplete(
    _In_ WDFREQUEST Request
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    // Get request's parameters.
    NciSimSequenceHandlerComplete* params;
    status = WdfRequestRetrieveInputBuffer(Request, sizeof(NciSimSequenceHandlerComplete), reinterpret_cast<void**>(&params), nullptr);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "WdfRequestRetrieveInputBuffer failed. %!STATUS!", status);
        return status;
    }

    WdfWaitLockAcquire(_ClientLock, nullptr);

    // Acquire the sequence completed function.
    PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE sequenceCompleted = _SequenceCompleted;
    WDFCONTEXT sequenceCompletedContext = _SequenceCompletedContext;

    _SequenceCompleted = nullptr;
    _SequenceCompletedContext = nullptr;

    WdfWaitLockRelease(_ClientLock);

    // Ensure there is a sequence handler pending.
    if (!sequenceCompleted)
    {
        status = STATUS_INVALID_DEVICE_STATE;
        TRACE_LINE(LEVEL_ERROR, "No sequence completion routine is pending. %!STATUS!", status);
        return status;
    }

    // Call the sequence completed function.
    sequenceCompleted(_Device, params->Status, params->Flags, sequenceCompletedContext);

    // Complete I/O request.
    WdfRequestComplete(Request, STATUS_SUCCESS);

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
// Called when NfcCx has an NCI packet it wishes to sent to the device.
void
DeviceContext::WriteNciPacket(
    _In_ WDFREQUEST Request
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    // Get NCI packet.
    void* nciBuffer;
    size_t nciLength;
    status = WdfRequestRetrieveInputBuffer(Request, 0, &nciBuffer, &nciLength);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "Failed to read input buffer. %!STATUS!", status);
        WdfRequestComplete(Request, status);
        return;
    }

    WdfWaitLockAcquire(_ClientLock, nullptr);

    if (_NciWriteRequest != nullptr)
    {
        status = STATUS_INVALID_DEVICE_STATE;
        TRACE_LINE(LEVEL_ERROR, "A pending NCI write already exists. %!STATUS!", status);
        WdfWaitLockRelease(_ClientLock);
        WdfRequestComplete(Request, status);
        return;
    }

    // Post NCI write callback.
    status = _ApiCallbacksManager.PostNciWriteCallback(nciBuffer, nciLength);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "CallbacksManager::PostNciWriteCallback failed. %!STATUS!", status);
        WdfWaitLockRelease(_ClientLock);
        WdfRequestComplete(Request, status);
        return;
    }

    _NciWriteRequest = Request;

    WdfWaitLockRelease(_ClientLock);
    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
}
VOID
NfcCxSCPresentAbsentDispatcherRequestCanceled(
    _In_ WDFREQUEST Request
    )
/*++

Routine Description:

    Called when a pending request has been canceled.

Arguments:

    Request - The request

Return Value:

    NTSTATUS

--*/
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);

    WDFFILEOBJECT fileObject = WdfRequestGetFileObject(Request);
    WDFDEVICE device = WdfFileObjectGetDevice(fileObject);

    PNFCCX_FILE_CONTEXT fileContext = NfcCxFileGetContext(fileObject);
    PNFCCX_FDO_CONTEXT fdoContext = NfcCxFdoGetContext(device);
    PNFCCX_SC_REQUEST_CONTEXT requestContext = NfcCxSCGetRequestContext(Request);
    PNFCCX_SC_PRESENT_ABSENT_DISPATCHER dispatcher = requestContext->Dispatcher;

    // Remove this request from the dispatcher
    void* previousRequest = InterlockedCompareExchangePointer((void**)&dispatcher->CurrentRequest, /*exchange*/ nullptr, /*compare*/ Request);

    // Check if another thread has already completed the request.
    if (previousRequest != Request)
    {
        // Request already completed by a different thread.
        // Nothing to do.
        goto Done;
    }

    // Release power reference (if required).
    if (dispatcher->PowerManaged)
    {
        NfcCxPowerFileRemoveReference(fdoContext->Power, fileContext, NfcCxPowerReferenceType_Proximity);
    }

    // Complete the request.
    TRACE_LINE(LEVEL_ERROR, "Smartcard Present/Absent request canceled. %!STATUS!", STATUS_CANCELLED);
    WdfRequestComplete(Request, STATUS_CANCELLED);

Done:
    // Release the cancel callback's extra ref-count
    WdfObjectDereference(Request);

    TRACE_FUNCTION_EXIT(LEVEL_VERBOSE);
}
Esempio n. 25
0
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *shooter, TraceResult *ptr) {
	TRACE_LINE(v1, v2, fNoMonsters, shooter, ptr);
	if ( ptr->pHit && (ptr->pHit->v.flags& (FL_CLIENT | FL_FAKECLIENT))
	&& shooter && (shooter->v.flags & (FL_CLIENT | FL_FAKECLIENT)) ) {
		int shooterIndex = ENTINDEX(shooter);
		if ( !(g_bodyhits[shooterIndex][ENTINDEX(ptr->pHit)] & (1<<ptr->iHitgroup)) )
			ptr->flFraction = 1.0;
	}
	RETURN_META(MRES_SUPERCEDE);
}
Esempio n. 26
0
void FindHullIntersection(const Vector &vecSrc, TraceResult &tr, float *pflMins, float *pfkMaxs, edict_t *pEntity)
{
	TraceResult trTemp;
	float flDistance = 1000000;
	float *pflMinMaxs[2] = { pflMins, pfkMaxs };
	Vector vecHullEnd = tr.vecEndPos;

	vecHullEnd = vecSrc + ((vecHullEnd - vecSrc) * 2);
	TRACE_LINE(vecSrc, vecHullEnd, dont_ignore_monsters, pEntity, &trTemp);

	if (trTemp.flFraction < 1)
	{
		tr = trTemp;
		return;
	}

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				Vector vecEnd;
				vecEnd.x = vecHullEnd.x + pflMinMaxs[i][0];
				vecEnd.y = vecHullEnd.y + pflMinMaxs[j][1];
				vecEnd.z = vecHullEnd.z + pflMinMaxs[k][2];

				TRACE_LINE(vecSrc, vecEnd, dont_ignore_monsters, pEntity, &trTemp);

				if (trTemp.flFraction < 1)
				{
					float flThisDistance = (trTemp.vecEndPos - vecSrc).Length();

					if (flThisDistance < flDistance)
					{
						tr = trTemp;
						flDistance = flThisDistance;
					}
				}
			}
		}
	}
}
void
DeviceContext::SequenceHandler(
    _In_ NFC_CX_SEQUENCE Sequence,
    _In_ PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE CompletionRoutine,
    _In_opt_ WDFCONTEXT CompletionContext
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    WdfWaitLockAcquire(_ClientLock, nullptr);

    if (!_CurrentSimClient)
    {
        // There currently isn't a connected client. So just complete the sequence handler immediately.
        // This helps improve the robustness of the driver if a test fails.
        TRACE_LINE(LEVEL_INFO, "Leftover sequence handler.");
        WdfWaitLockRelease(_ClientLock);
        CompletionRoutine(_Device, STATUS_SUCCESS, 0, CompletionContext);
        return;
    }

    // Notify the test process that a sequence handler was invoked.
    status = _ApiCallbacksManager.PostSequenceHandlerCallback(Sequence);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "CallbacksManager::PostSequenceHandlerCallback failed. %!STATUS!", status);
        WdfWaitLockRelease(_ClientLock);
        CompletionRoutine(_Device, status, 0, CompletionContext);
        return;
    }

    _SequenceCompleted = CompletionRoutine;
    _SequenceCompletedContext = CompletionContext;

    WdfWaitLockRelease(_ClientLock);
    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
}
NTSTATUS
DeviceContext::CommandHardwareEvent(
    _In_ WDFREQUEST Request
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    NFC_CX_HOST_ACTION* param;
    status = WdfRequestRetrieveInputBuffer(Request, sizeof(*param), (void**)&param, nullptr);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "WdfRequestRetrieveInputMemory failed. %!STATUS!", status);
        return status;
    }

    // The device's WDF lock provides a convenient way to serialize with the power event callbacks.
    WdfObjectAcquireLock(_Device);

    NFC_CX_HARDWARE_EVENT eventArgs = {};
    eventArgs.HostAction = *param;
    eventArgs.HardwareStatus = STATUS_SUCCESS;

    status = NfcCxHardwareEvent(_Device, &eventArgs);
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "NfcCxHardwareEvent (%d) failed. %!STATUS!", *param, status);
        WdfObjectReleaseLock(_Device);
        return status;
    }

    WdfRequestComplete(Request, STATUS_SUCCESS);

    WdfObjectReleaseLock(_Device);
    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}
Esempio n. 29
0
static cell AMX_NATIVE_CALL trace_line(AMX *amx, cell *params)
{
	int iEnt = params[1];

	cell *cStart = MF_GetAmxAddr(amx, params[2]);
	cell *cEnd = MF_GetAmxAddr(amx, params[3]);
	REAL fStartX = amx_ctof(cStart[0]);
	REAL fStartY = amx_ctof(cStart[1]);
	REAL fStartZ = amx_ctof(cStart[2]);
	REAL fEndX = amx_ctof(cEnd[0]);
	REAL fEndY = amx_ctof(cEnd[1]);
	REAL fEndZ = amx_ctof(cEnd[2]);

	cell *vRet = MF_GetAmxAddr(amx, params[4]);

	Vector vStart = Vector(fStartX, fStartY, fStartZ);
	Vector vEnd = Vector(fEndX, fEndY, fEndZ);

	TraceResult tr;

	if (iEnt == -1)
		TRACE_LINE(vStart, vEnd, ignore_monsters, NULL, &tr);
	else
		TRACE_LINE(vStart, vEnd, dont_ignore_monsters, INDEXENT2(iEnt), &tr);

	edict_t *pHit = tr.pHit;

	vRet[0] = amx_ftoc(tr.vecEndPos.x);
	vRet[1] = amx_ftoc(tr.vecEndPos.y);
	vRet[2] = amx_ftoc(tr.vecEndPos.z);

	if (FNullEnt(pHit))
		return 0;

	return ENTINDEX(pHit);
}
// Called when the device exits the D0 power state.
NTSTATUS
DeviceContext::D0Exit(
    _In_ WDF_POWER_DEVICE_STATE /*TargetState*/
    )
{
    TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE);
    NTSTATUS status;

    status = _ApiCallbacksManager.PostD0ExitCallback();
    if (!NT_SUCCESS(status))
    {
        TRACE_LINE(LEVEL_ERROR, "CallbacksManager::PostD0ExitCallback failed. %!STATUS!", status);
        return status;
    }

    TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE);
    return STATUS_SUCCESS;
}