Ejemplo n.º 1
0
NTSTATUS 
PrepareBluetooth(
	_In_ PDEVICE_CONTEXT DeviceContext
	)
{
    NTSTATUS Status = STATUS_SUCCESS;
	PBLUETOOTH_DEVICE_CONTEXT BluetoothContext = &(DeviceContext->BluetoothContext);
	WDF_MEMORY_DESCRIPTOR  DeviceInfoMemDescriptor;
	BTH_DEVICE_INFO	DeviceInfo;

	BluetoothContext->ControlChannelHandle = NULL;
	BluetoothContext->InterruptChannelHandle = NULL;

	//Get Interfaces
	Status = WdfFdoQueryForInterface(
		DeviceContext->Device, 
		&GUID_BTHDDI_PROFILE_DRIVER_INTERFACE, 
		(PINTERFACE)(&(BluetoothContext->ProfileDriverInterface)), 
		sizeof(BluetoothContext->ProfileDriverInterface), 
		BTHDDI_PROFILE_DRIVER_INTERFACE_VERSION_FOR_QI, 
		NULL); 
	
	if (!NT_SUCCESS(Status))
    {
        return Status;
    }

	//Get BluetoothAdress
	RtlZeroMemory(&DeviceInfo, sizeof(DeviceInfo));
	WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&DeviceInfoMemDescriptor, &DeviceInfo, sizeof(DeviceInfo));

	Status = WdfIoTargetSendInternalIoctlSynchronously(
		DeviceContext->IoTarget, 
		NULL, 
		IOCTL_INTERNAL_BTHENUM_GET_DEVINFO, 
		NULL, 
		&DeviceInfoMemDescriptor, 
		NULL, 
		NULL);
	 
    if (!NT_SUCCESS(Status)) 
	{
		return Status;
    }

	BluetoothContext->DeviceAddress = DeviceInfo.address;

	return Status;
}
Ejemplo n.º 2
0
NTSTATUS
BthEchoCliBthQueryInterfaces(
    __in PBTHECHOSAMPLE_CLIENT_CONTEXT DevCtx
    )
/*++

Description:

    Query profile driver interface

Arguments:

    DevCtx - Client context where we store the interface

Return Value:

    NTSTATUS Status code.

--*/
{
    NTSTATUS status;

    PAGED_CODE();

    status = WdfFdoQueryForInterface(
        DevCtx->Header.Device,
        &GUID_BTHDDI_PROFILE_DRIVER_INTERFACE, 
        (PINTERFACE) (&DevCtx->Header.ProfileDrvInterface),
        sizeof(DevCtx->Header.ProfileDrvInterface), 
        BTHDDI_PROFILE_DRIVER_INTERFACE_VERSION_FOR_QI, 
        NULL
        );
                
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, 
            "QueryInterface failed for Interface profile driver interface, version %d, Status code %!STATUS!\n", 
            BTHDDI_PROFILE_DRIVER_INTERFACE_VERSION_FOR_QI,
            status);

        goto exit;
    }

exit:
    return status;    
}
Ejemplo n.º 3
0
NTSTATUS
Acpi_PrepareHardware (
    _In_ PACPI_CONTEXT AcpiCtx
    )
{
    NTSTATUS status;
    WDFDEVICE device;

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_ACPI);

    device = Context_GetWdfDevice(AcpiCtx);

    if (AcpiCtx->Initialized != FALSE)
    {
        status = STATUS_INVALID_DEVICE_STATE;
        TRACE_ERROR(TRACE_FLAG_ACPI, "[Device: 0x%p] ACPI already initialized", device);
        goto Exit;
    }

    status = WdfFdoQueryForInterface(device,
                                     &GUID_ACPI_INTERFACE_STANDARD2,
                                     (PINTERFACE) &AcpiCtx->AcpiInterface,
                                     sizeof(ACPI_INTERFACE_STANDARD2),
                                     1,
                                     NULL);

    if (!NT_SUCCESS(status))
    {
        TRACE_ERROR(TRACE_FLAG_ACPI, "[Device: 0x%p] WdfFdoQueryForInterface for ACPI_INTERFACE_STANDARD2 failed - %!STATUS!", device, status);
        goto Exit;
    }

    AcpiCtx->Initialized = TRUE;

    TRACE_INFO(TRACE_FLAG_ACPI, "[Device: 0x%p] ACPI prepare hardware completed", device);

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_ACPI);

    return status;
}
Ejemplo n.º 4
0
// 此函数类似于WDM中的PNP_MN_START_DEVICE函数,紧接着PnpAdd之后被调用。
// 此时PNP管理器经过甄别之后,已经决定将那些系统资源分配给当前设备。
// 参数ResourceList和ResourceListTranslated代表了这些系统资源。
// 当个函数被调用时候,设备已经进入了D0电源状态;函数完成后,设备即正式进入工作状态。
NTSTATUS DrvClass::PnpPrepareHardware(IN WDFCMRESLIST ResourceList, IN WDFCMRESLIST ResourceListTranslated)
{
	NTSTATUS status;
	PDEVICE_CONTEXT pContext = NULL; 
	ULONG ulNumRes = 0;
	ULONG ulIndex;
	CM_PARTIAL_RESOURCE_DESCRIPTOR*  pResDes = NULL;

	KDBG(DPFLTR_INFO_LEVEL, "[PnpPrepareHardware]");

	pContext = GetDeviceContext(m_hDevice);

	// 配置设备
	status = ConfigureUsbDevice();
	if(!NT_SUCCESS(status))
		return status;

	// 获取Pipe句柄
	status = GetUsbPipes();
	if(!NT_SUCCESS(status))
		return status;

	// 初始电源策略,
	status = InitPowerManagement();

	// 获取USB总线驱动接口。总线接口中包含总线驱动提供的回调函数和其他信息。
	// 总线接口由系统共用GUID标识。
	status = WdfFdoQueryForInterface(
		m_hDevice,
		&USB_BUS_INTERFACE_USBDI_GUID1,		// 总线接口ID
		(PINTERFACE)&m_busInterface,		// 保存在设备环境块中
		sizeof(USB_BUS_INTERFACE_USBDI_V1),
		1, NULL);

	// 调用接口函数,判断USB版本。
	if(NT_SUCCESS(status) && m_busInterface.IsDeviceHighSpeed){
		if(m_busInterface.IsDeviceHighSpeed(m_busInterface.BusContext))
			KDBG(DPFLTR_INFO_LEVEL, "USB 2.0");
		else
			KDBG(DPFLTR_INFO_LEVEL, "USB 1.1");
	}

	// 对系统资源列表,我们不做实质性的操作,仅仅打印一些信息。
	// 读者完全可以把下面的这些代码都注释掉。
	ulNumRes = WdfCmResourceListGetCount(ResourceList);
	KDBG(DPFLTR_INFO_LEVEL, "ResourceListCount:%d\n", ulNumRes);

	// 下面我们饶有兴致地枚举这些系统资源,并打印出它们的相关名称信息。
	for(ulIndex = 0; ulIndex < ulNumRes; ulIndex++)
	{
		pResDes = WdfCmResourceListGetDescriptor(ResourceList, ulIndex);		
		if(!pResDes)continue; // 取得失败,则跳到下一个

		switch (pResDes->Type) 
		{
		case CmResourceTypeMemory:
			KDBG(DPFLTR_INFO_LEVEL, "System Resource:CmResourceTypeMemory\n");
			break;

		case CmResourceTypePort:
			KDBG(DPFLTR_INFO_LEVEL, "System Resource:CmResourceTypePort\n");
			break;

		case CmResourceTypeInterrupt:
			KDBG(DPFLTR_INFO_LEVEL, "System Resource:CmResourceTypeInterrupt\n");
			break;

		default:
			KDBG(DPFLTR_INFO_LEVEL, "System Resource:Others %d\n", pResDes->Type);
			break;
		}
	}

	return STATUS_SUCCESS;
}
Ejemplo n.º 5
0
NTSTATUS
BthEchoSrvEvtDeviceSelfManagedIoInit(
    _In_ WDFDEVICE  Device
    )
/*++

Description:

    This routine is called by the framework only once
    and hence we use it for our one time initialization.

    In this routine we retrieve local bth address and local stack supported
    features. We also register the server and publish SDP record.

Arguments:

    Device - Framework device object

Return Value:

    NTSTATUS Status code.

--*/
{
    NTSTATUS status;
    PBTHECHOSAMPLE_SERVER_CONTEXT devCtx = GetServerDeviceContext(Device);
    PUCHAR sdpRecordStream = NULL;
    ULONG sdpRecordLength = 0;
    BTHDDI_SDP_NODE_INTERFACE sdpNodeInterface;
    BTHDDI_SDP_PARSE_INTERFACE sdpParseInterface;

    status = BthEchoSharedRetrieveLocalInfo(&devCtx->Header);
    if (!NT_SUCCESS(status))
    {
        goto exit;
    }

    status = BthEchoSrvRegisterPSM(devCtx);
    if (!NT_SUCCESS(status))
    {
        goto exit;
    }

    status = BthEchoSrvRegisterL2CAPServer(devCtx);
    if (!NT_SUCCESS(status))
    {
        goto exit;
    }

    status = WdfFdoQueryForInterface(
        Device,
        &GUID_BTHDDI_SDP_PARSE_INTERFACE, 
        (PINTERFACE) (&sdpParseInterface),
        sizeof(sdpParseInterface), 
        BTHDDI_SDP_PARSE_INTERFACE_VERSION_FOR_QI, 
        NULL
        );
                
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, 
            "QueryInterface failed for Interface sdp parse interface, version %d, Status code %!STATUS!\n", 
            BTHDDI_SDP_PARSE_INTERFACE_VERSION_FOR_QI,
            status);

        goto exit;
    }

    status = WdfFdoQueryForInterface(
        Device,
        &GUID_BTHDDI_SDP_NODE_INTERFACE, 
        (PINTERFACE) (&sdpNodeInterface),
        sizeof(sdpNodeInterface), 
        BTHDDI_SDP_NODE_INTERFACE_VERSION_FOR_QI, 
        NULL
        );
                
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, 
            "QueryInterface failed for Interface sdp node interface, version %d, Status code %!STATUS!\n", 
            BTHDDI_SDP_NODE_INTERFACE_VERSION_FOR_QI,
            status);

        goto exit;
    }

    status = CreateSdpRecord(
        &sdpNodeInterface,
        &sdpParseInterface,
        &BTHECHOSAMPLE_SVC_GUID,
        BthEchoSampleSvcName,
        devCtx->Psm,
        &sdpRecordStream,
        &sdpRecordLength
        );                                                
    if (!NT_SUCCESS(status))
    {
        goto exit;
    }
    
    status = BthEchoSrvPublishSdpRecord(devCtx, sdpRecordStream, sdpRecordLength);
    if (!NT_SUCCESS(status))
    {
        goto exit;
    }
    
exit:

    if (sdpRecordStream)
    {
        FreeSdpRecord(sdpRecordStream);
    }
    
    return status;    
}