共用方式為


構建和傳送藍牙要求區塊(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 );