生成和发送蓝牙请求块 (BRB)

以下过程概述了配置文件驱动程序生成和发送蓝牙请求块 (BRB) 应遵循的一般流程。 BRB 是描述要执行的蓝牙操作的数据块。

生成和发送 BRB

  1. 分配 IRP。 有关如何使用 IRP 的详细信息,请参阅处理 IRP
  2. 分配 BRB。 若要分配 BRB,请调用蓝牙驱动程序堆栈导出以供配置文件驱动程序使用的 BthAllocateBrb 函数。 若要获取指向 BthAllocateBrb 函数的指针,请参阅查询蓝牙接口
  3. 初始化 BRB 的参数。 每个 BRB 都使用相应的结构。 根据预期用途设置结构的成员。 有关 BRB 及其相应结构的列表,请参阅使用蓝牙驱动程序堆栈
  4. 初始化 IRP 的参数。 将 IRP 的 MajorFunction 成员设置为 IRP_MJ_INTERNAL_DEVICE_CONTROL。 将 Parameters.DeviceIoControl.IoControlCode 成员设置为 IOCTL_INTERNAL_BTH_SUBMIT_BRB。 将 Parameters.Others.Argument1 成员设置为指向 BRB。
  5. 沿着驱动程序堆栈向下方向传递 IRP。 调用 IoCallDriver 以将 IRP 发送到下一个较低的驱动程序。

以下伪代码示例演示了如何为要处理的蓝牙驱动程序堆栈设置 L2CAP Ping BRB。 为了提高可读性,该示例不演示错误处理。

#include <bthddi.h>

// Code for obtaining the BthInterface pointer

// 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 );

PBRB_L2CA_PING BrbPing; // Define storage for a L2CAP Ping BRB

// Allocate the Ping BRB
BrbPing = BthInterface->BthAllocateBrb( BRB_L2CA_PING, PROFILE_DRIVER_POOL_TAG );

// Set up the next IRP stack location
PIO_STACK_LOCATION NextIrpStack;
NextIrpStack = IoGetNextIrpStackLocation( Irp );
NextIrpStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
NextIrpStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_BTH_SUBMIT_BRB;
NextIrpStack->Parameters.Others.Argument1 = BrbPing;

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