2021年1月6日星期三

BTH_DEVICE_INFO_LIST IOCTL Execution

I am trying to execute IOCTL_BTH_GET_DEVICE_INFO for this purpose,as a beginner I write following code

#include <ntddk.h>  #include <stdio.h>  #include <conio.h>  #include <stdlib.h>  #include <ntddk.h>  #include <wdf.h>  #include <initguid.h>   #include <ntstrsafe.h>  #include <bthdef.h>  #include <ntintsafe.h>  #include <bthguid.h>  #include <bthioctl.h>  #include <sdpnode.h>  #include <bthddi.h>  #include <bthsdpddi.h>  #include <bthsdpdef.h>  #include <wdfobject.h>  #include <wdfdriver.h>  #include <wdm.h>    DRIVER_INITIALIZE DriverEntry;  EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\MyDeivce123");  PDEVICE_OBJECT DeviceObject = NULL;  UNICODE_STRING SymLinkName = RTL_CONSTANT_STRING(L"\\??\mydevicelink123");  NTSTATUS BleDispatchCreate(PDEVICE_OBJECT device_obj, PIRP Irp)  {  KdPrint((" Inside BleDispatchCreate "));  KdPrint((" BleDispatchCreate Execution complete"));  //need to return status  return STATUS_SUCCESS;  }    NTSTATUS BleDispatchDeviceControl(PDEVICE_OBJECT device_obj, PIRP Irp)  {  KdPrint((" Inside BleDispatchDeviceControl "));    KdPrint((" BleDispatchDeviceControl Execution complete"));  //need to return status  return STATUS_SUCCESS;  }  //removed Unload function  NTSTATUS BleTest(PDEVICE_OBJECT device_obj, PIRP Irp)  {  PBTH_DEVICE_INFO_LIST PBLRI = (PBTH_DEVICE_INFO_LIST)Irp- >AssociatedIrp.SystemBuffer;  NTSTATUS status = STATUS_SUCCESS;  PIO_STACK_LOCATION irp_sl = IoGetCurrentIrpStackLocation(Irp);  KdPrint(("Number of devices are before i/ocall  %lu", PBLRI->numOfDevices));  status = IoCallDriver(device_obj, Irp);  if (status == STATUS_SUCCESS) {      KdPrint(("IOCALLDRIVER  SUCCESS : \n "));      KdPrint(("Number of devices are %lu", PBLRI->numOfDevices));  }  else {      KdPrint(("Driver call Failed!\r\n"));      return status;  }  return status;  }  NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING   RegistryPath) {  NTSTATUS status = STATUS_SUCCESS;  int i;  DriverObject->DriverUnload = Unload;    status = IoCreateDevice(DriverObject, 0,   &DeviceName,FILE_DEVICE_BLUETOOTH,FILE_CHARACTERISTIC_PNP_DEVICE, FALSE,   &DeviceObject);  if (!NT_SUCCESS(status)){      KdPrint(("creating device failed \n "));      return status;  }else      KdPrint(("Device creation successful\r\n"));  status = IoCreateSymbolicLink(&SymLinkName, &DeviceName);  if (!NT_SUCCESS(status)){      KdPrint(("creating symbolic link failed \n"));      IoDeleteDevice(DeviceObject);      return status;  }else      KdPrint(("Symbolic link creation successful\r\n"));  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =   BleDispatchDeviceControl;  /********fill IRP *****************************/  PIRP Irp = NULL;  ULONG IoControlCode = IOCTL_BTH_GET_DEVICE_INFO;  ULONG InputBufferLength = sizeof(BTH_DEVICE_INFO_LIST);  BTH_DEVICE_INFO_LIST  InputBuffer;  ULONG OutputBufferLength = sizeof(BTH_DEVICE_INFO_LIST);  BTH_DEVICE_INFO_LIST  OutputBuffer;  BOOLEAN InternalDeviceIoControl = FALSE;  PKEVENT Event = NULL;  IO_STATUS_BLOCK ISB;  PIO_STATUS_BLOCK IoStatusBlock = &ISB;  Irp = IoBuildDeviceIoControlRequest(IoControlCode, DeviceObject,&InputBuffer,   InputBufferLength, &OutputBuffer, OutputBufferLength,InternalDeviceIoControl,   Event, IoStatusBlock);  /* IO_COMPLETION_ROUTINE CdDevCtrlCompletionRoutine;  NTSTATUS      CdDevCtrlCompletionRoutine(          _In_ PDEVICE_OBJECT DeviceObject,          _In_ PIRP Irp,          _In_reads_opt_(_Inexpressible_("varies")) PVOID Contxt      );*/  BleTest(DeviceObject, Irp);  KdPrint(("Driver LOAD ENDS returning success \n "));  return status;  }  

Output log file is

  • Device creation successful
  • Symbolic link creation successful
  • Number of devices are before I/O call 1313444832
  • Inside BleDispatchDeviceControl
  • BleDispatchDeviceControl Execution complete
  • IOCALLDRIVER SUCCESS :
  • Number of devices are 1313444832
  • Driver LOAD ENDS returning success
  • Driver unload called

It print some garbage value in my opinion.Please point out to the mistake I made init ? I am beginner in this field.If this is post is not clear please point me.I will try to make it more consise.

https://stackoverflow.com/questions/65562393/bth-device-info-list-ioctl-execution January 04, 2021 at 08:01PM

没有评论:

发表评论