Consultando interfaces Bluetooth

A pilha de drivers Bluetooth expõe as seguintes interfaces que os drivers de perfil podem usar para interagir com os dispositivos Bluetooth.

Interfaz Descrição
GUID_BTHDDI_SDP_NODE_INTERFACE Os drivers de perfil consultam o GUID_BTHDDI_SDP_NODE_INTERFACE para obter ponteiros para funções que lhes permitem criar registros SDP (Service Discovery Protocol).

Esta interface corresponde à estrutura BTHDDI_SDP_NODE_INTERFACE .
GUID_BTHDDI_SDP_PARSE_INTERFACE Os drivers de perfil consultam o GUID_BTHDDI_SDP_PARSE_INTERFACE para obter ponteiros para funções que lhes permitam analisar registros SDP.

Esta interface corresponde à estrutura BTHDDI_SDP_PARSE_INTERFACE .
GUID_BTHDDI_PROFILE_DRIVER_INTERFACE Os drivers de perfil consultam a BTHDDI_PROFILE_DRIVER_INTERFACE para obter ponteiros para funções que lhes permitam criar, alocar, reutilizar e liberar BRBs.

Esta interface corresponde à estrutura BTH_PROFILE_DRIVER_INTERFACE.

Para obter qualquer uma dessas interfaces, um driver de perfil deve primeiro criar e enviar um IRP_MN_QUERY_INTERFACE IRP para a pilha de drivers Bluetooth.

O procedimento a seguir é o processo geral para obter uma dessas interfaces.

Para consultar uma interface

  1. Aloque e inicialize um IRP.
  2. Aloque e inicialize uma instância da interface.
  3. Especifique os códigos de função principais e secundários para consultar a interface.
  4. Especifique a interface para consultar.
  5. Passe o IRP para baixo na pilha de drivers para ser processado.

O exemplo de pseudocódigo a seguir demonstra como configurar um IRP IRP_MN_QUERY_INTERFACE para consultar a pilha de driver Bluetooth para o GUID_BTHDDI_PROFILE_DRIVER_INTERFACE. Para facilitar a leitura, o exemplo não demonstra o tratamento de erros.

#include <bthddi.h>

...

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

PBTH_PROFILE_DRIVER_INTERFACE BthInterface; // Define storage for an instance of the BTH_PROFILE_DRIVER_INTERFACE structure
BthInterface = ExAllocatePoolWithTag( NonPagedPool, sizeof( BTH_PROFILE_DRIVER_INTERFACE ), PROFILE_DRIVER_POOL_TAG );

// Zero the memory associated with the structure
RtlZeroMemory( BthInterface, sizeof( BTH_PROFILE_DRIVER_INTERFACE ) );

// Set up the next IRP stack location
PIO_STACK_LOCATION NextIrpStack;
NextIrpStack = IoGetNextIrpStackLocation( Irp );
NextIrpStack->MajorFunction = IRP_MJ_PNP;
NextIrpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
NextIrpStack->Parameters.QueryInterface.InterfaceType = (LPGUID) &GUID_BTHDDI_PROFILE_DRIVER_INTERFACE;
NextIrpStack->Parameters.QueryInterface.Size = sizeof( BTH_PROFILE_DRIVER_INTERFACE );
NextIrpStack->Parameters.QueryInterface.Version = BTHDDI_PROFILE_DRIVER_INTERFACE_VERSION_FOR_QI;
NextIrpStack->Parameters.QueryInterface.Interface = (PINTERFACE) BthInterface;
NextIrpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;

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

Se o IRP retornar com êxito, o controlador de perfil poderá aceder e usar os ponteiros de função contidos na interface.