Quantcast
Channel: Configuration Manager 2007 Operating System Deployment forum
Viewing all articles
Browse latest Browse all 1063

How to use IRP_MJ_DEVICE_CONTROL in BDA driver

$
0
0

I would appreciate very much if you could spare me a little time to attend to my question.

I make a BDA USB driver for TV device, but we need some private interface for BDA USB driver. I want to use IRP_MJ_DEVICE_CONTROL interface using application request with driver. Now, the problem which is CreateFile return INVALID_HANDLE_VALUE always befalls me.

In the BDA driver, use the IoRegisterDeviceInterface routine registers a deice interface class. as following,

 

static const GUID GUID_USB_TV =

{0xa1e49895, 0x489e, 0x401f,  {0x82, 0x3e, 0x32, 0xdc, 0xf3, 0xe1, 0x3d, 0x7}};

 

In the AddDevice funcation

 

Status = IoRegisterDeviceInterface(pKSDevice->PhysicalDeviceObject, & GUID_USB_TV, NULL, &pDevExt->guidname);

 

if (NT_SUCCESS(Status))

{

IoSetDeviceInterfaceState(&pDevExt->guidname, TRUE);

}

 

In the RemoveDevice and Stopdevice

IoSetDeviceInterfaceState(&pDevExt->guidname, FALSE);

 

In the application, use the CreateFile function to create device. If install my BDA driver to OS, then CreateFile function always return 0xFFFFFFFF, if use WDM simple code bulkusb(WINDDK\3790\src\wdm\usb\bulkusb\sys), the CreateFile function return is successful and can use DeviceIoControl function sends a control code. As following,

 

// Get handle to relevant device information set

HDEVINFO info = SetupDiGetClassDevs(GUID_USB_TV, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

         if(info==INVALID_HANDLE_VALUE)

         {

                   printf("No HDEVINFO available for this GUID\n");

                   return NULL;

         }

 

         // Get interface data for the requested instance

         SP_INTERFACE_DEVICE_DATA ifdata;

         ifdata.cbSize = sizeof(ifdata);

         if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, instance, &ifdata))

         {

                   printf("No SP_INTERFACE_DEVICE_DATA available for this GUID instance\n");

                   SetupDiDestroyDeviceInfoList(info);

                   return NULL;

         }

 

         // Get size of symbolic link name

         DWORD ReqLen;

         SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL);

         PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]);

         if( ifDetail==NULL)

         {

                   SetupDiDestroyDeviceInfoList(info);

                   return NULL;

         }

 

         // Get symbolic link name

         ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

         if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL))

         {

                   SetupDiDestroyDeviceInfoList(info);

                   delete ifDetail;

                  return NULL;

         }

 

         printf("Symbolic link is %s\n",ifDetail->DevicePath);

 

         // Open file

         HANDLE file = CreateFile(ifDetail->DevicePath,

                   GENERIC_READ | GENERIC_WRITE,

                   FILE_SHARE_READ | FILE_SHARE_WRITE,

                   NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

 

         if( file==INVALID_HANDLE_VALUE) file = NULL;

 

         DWORD dwlasterror = GetLastError();

 

         delete ifDetail;

         SetupDiDestroyDeviceInfoList(info);

 


Viewing all articles
Browse latest Browse all 1063

Trending Articles