Condividi tramite


Compilazione e invio di un blocco di richiesta Bluetooth (BRB)

La procedura seguente descrive il processo generale che un driver del profilo segue per compilare e inviare un blocco di richieste Bluetooth (BRB). Un BRB è un blocco di dati che descrive l'operazione Bluetooth da eseguire.

Per compilare e inviare un BRB

  1. Allocare un'istanza di IRP. Per altre informazioni sull'uso di IRP, vedere Gestione degli indirizzi IP.
  2. Allocare un BRB. Per allocare i BRB, chiamare la funzione BthAllocateBrb esportata dallo stack di driver Bluetooth da usare dai driver del profilo. Per ottenere un puntatore alla funzione BthAllocateBrb , vedere Querying for Bluetooth Interfaces.
  3. Inizializzare i parametri del BRB. Ogni BRB usa una struttura corrispondente. Impostare i membri della struttura in base all'uso previsto. Per un elenco di BRBs e delle relative strutture corrispondenti, vedere Uso dello stack di driver Bluetooth.
  4. Inizializzare i parametri dell'IRP. Impostare il membro MajorFunction dell'IRP su IRP_MJ_INTERNAL_DEVICE_CONTROL. Impostare il membro Parameters.DeviceIoControl.IoControlCode su IOCTL_INTERNAL_BTH_SUBMIT_BRB. Impostare il membro Parameters.Others.Argument1 per puntare a BRB.
  5. Passare l'IRP verso il basso lo stack di driver. Chiamare IoCallDriver per inviare l'IRP al driver inferiore successivo.

Nell'esempio di pseudocodice seguente viene illustrato come configurare un BRB ping L2CAP per lo stack di driver Bluetooth da elaborare. Per la leggibilità, l'esempio non dimostra la gestione degli errori.

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