共用方式為


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