Bagikan melalui


Membangun dan mengirim blok permintaan Bluetooth (BRB)

Prosedur berikut menguraikan proses umum yang diikuti driver profil untuk membangun dan mengirim blok permintaan Bluetooth (BRB). BRB adalah blok data yang menjelaskan operasi Bluetooth untuk dilakukan.

Untuk membangun dan mengirim BRB

  1. Mengalokasikan IRP. Untuk informasi selengkapnya tentang cara menggunakan IRP, lihat Menangani RUNPS.
  2. Mengalokasikan BRB. Untuk mengalokasikan BRB, panggil fungsi BthAllocateBrb yang diekspor tumpukan driver Bluetooth untuk digunakan oleh driver profil. Untuk mendapatkan penunjuk ke fungsi BthAllocateBrb , lihat Mengkueri Antarmuka Bluetooth.
  3. Menginisialisasi parameter BRB. Setiap BRB menggunakan struktur yang sesuai. Atur anggota struktur sesuai dengan penggunaan yang dimaksudkan. Untuk daftar BRB dan struktur yang sesuai, lihat Menggunakan Bluetooth Driver Stack.
  4. Menginisialisasi parameter IRP. Atur anggota MajorFunction dari IRP ke IRP_MJ_INTERNAL_DEVICE_CONTROL. Atur anggota Parameters.DeviceIoControl.IoControlCode ke IOCTL_INTERNAL_BTH_SUBMIT_BRB. Atur anggota Parameters.Others.Argument1 untuk menunjuk ke BRB.
  5. Lewati IRP ke bawah tumpukan driver. Panggil IoCallDriver untuk mengirim IRP ke driver yang lebih rendah berikutnya.

Contoh pseudocode berikut menunjukkan cara menyiapkan L2CAP Ping BRB untuk diproses oleh tumpukan driver Bluetooth. Untuk keterbacaan, contohnya tidak menunjukkan penanganan kesalahan.

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