查询蓝牙接口

蓝牙驱动程序堆栈会公开以下接口,配置文件驱动程序可使用这些接口与蓝牙设备交互。

接口 说明
GUID_BTHDDI_SDP_NODE_INTERFACE 配置文件驱动程序会查询 GUID_BTHDDI_SDP_NODE_INTERFACE 以获取指向允许其创建服务发现协议 (SDP) 记录的函数的指针。

此接口对应于 BTHDDI_SDP_NODE_INTERFACE 结构。
GUID_BTHDDI_SDP_PARSE_INTERFACE 配置文件驱动程序会查询 GUID_BTHDDI_SDP_PARSE_INTERFACE 以获取指向允许其分析 SDP 记录的函数的指针。

此接口对应于 BTHDDI_SDP_PARSE_INTERFACE 结构。
GUID_BTHDDI_PROFILE_DRIVER_INTERFACE 配置文件驱动程序会查询 BTHDDI_PROFILE_DRIVER_INTERFACE 以获取指向允许其创建、分配、重用和释放 BRB 的函数的指针。

此接口对应于 BTH_PROFILE_DRIVER_INTERFACE 结构。

若要获取这些接口中的任何一个,配置文件驱动程序必须首先生成 IRP_MN_QUERY_INTERFACE IRP 并将其发送到蓝牙驱动程序堆栈。

以下过程是获取其中一个接口的常规过程。

查询接口

  1. 分配和初始化 IRP。
  2. 分配和初始化接口的实例。
  3. 指定要查询接口的主要和次要函数代码。
  4. 指定要查询的接口。
  5. 沿着要处理的驱动程序堆栈向下方向传递 IRP。

以下伪代码示例演示了如何设置 IRP_MN_QUERY_INTERFACE IRP 来查询蓝牙驱动程序堆栈,以获取 GUID_BTHDDI_PROFILE_DRIVER_INTERFACE。 为了提高可读性,该示例不演示错误处理。

#include <bthddi.h>

...

// Define a custom pool tag to identify your profile driver's dynamic memory allocations. You should change this tag to easily identify your driver's allocations from other drivers.
#define PROFILE_DRIVER_POOL_TAG '_htB'

PIRP Irp;
Irp = IoAllocateIrp( DeviceExtension->ParentDeviceObject->StackSize, FALSE );

PBTH_PROFILE_DRIVER_INTERFACE BthInterface; // Define storage for an instance of the BTH_PROFILE_DRIVER_INTERFACE structure
BthInterface = ExAllocatePoolWithTag( NonPagedPool, sizeof( BTH_PROFILE_DRIVER_INTERFACE ), PROFILE_DRIVER_POOL_TAG );

// Zero the memory associated with the structure
RtlZeroMemory( BthInterface, sizeof( BTH_PROFILE_DRIVER_INTERFACE ) );

// Set up the next IRP stack location
PIO_STACK_LOCATION NextIrpStack;
NextIrpStack = IoGetNextIrpStackLocation( Irp );
NextIrpStack->MajorFunction = IRP_MJ_PNP;
NextIrpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
NextIrpStack->Parameters.QueryInterface.InterfaceType = (LPGUID) &GUID_BTHDDI_PROFILE_DRIVER_INTERFACE;
NextIrpStack->Parameters.QueryInterface.Size = sizeof( BTH_PROFILE_DRIVER_INTERFACE );
NextIrpStack->Parameters.QueryInterface.Version = BTHDDI_PROFILE_DRIVER_INTERFACE_VERSION_FOR_QI;
NextIrpStack->Parameters.QueryInterface.Interface = (PINTERFACE) BthInterface;
NextIrpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;

// Pass the IRP down the driver stack
NTSTATUS Status;
Status = IoCallDriver( DeviceExtension->NextLowerDriver, Irp );

如果 IRP 成功返回,则配置文件驱动程序可以访问和使用该接口中包含的函数指针。