registering device interface

Ok here is my story… I am modifying the i8042prt.sys driver (mouse
port driver) that comes with the DDK so as to get data directly from the
driver to my application. On NT this had proven to be not as difficult of
a task as it has on 2000. Following is what I have tried and what I have
run against.

First I simply named my device in the AddDevice routine, tested it
successfully and then tried creating a symbolic link the old fashion way
in the “AddDevice” routine itself. This caused both the mouse and keyboard
to not work (drv probably never loaded). So I decided to use
IoRegisterDeviceInterface() instead, again in the AddDevice routine.

I called the IoSetDeviceInterfaceState(pdo, true) in response to the
IRP_MN_START_DEVICE irp. The interface registered yet I was not able to
use CreateFile. It always failed except when I deleted the GENERIC_READ
flag leaving GENERIC_WRITE only in the call. Even so the handle so
obtained when used with the ReadFile() and WriteFile() failed to read or
write, of course. I then tried both REGISTERING and enabling the
interfaces in I8xMouseStartDevice routine of the sample (called in
response to IRP_MN_START_DEVICE irp). Again I was able to register but
had the same problem with CreateFile().

I then tried both naming and registering the device, which previously I
was not able to do when I was registering the device in the AddDevice
routine. This time it worked though, yet I had the same problem with
CreateFile. So I tried creating a symbolic link to my named device from
the user application using DefineDosDevice(DDD_RAW_TARGET_PATH,
“somename”, \Device\Optic01), this succeeded. Yet the CreateFile had
the same problem.

I have gone through the registry to see if there were some keys causing
this problem, have found none. I used a utility called Devview.exe, that
came with a book i bought, to look at the security on the device objects
and Under “Allow To everyone” it said, FILE_READ_DATA, FILE_WRITE_DATA
along with other attributes. So for all practical purposes it should
work. Dose anyone have any idea as to what I may be doing wrong here?
I’ve been working at this problem for a while now and am now getting
desperate, any help would be greatly appreciated.

drv_hndl = CreateFile(&dev_path_array[0][0],
/*GENERIC_READ|*/GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
NULL);

Kernel level

dev_index = InterlockedIncrement(&last_index);

_snwprintf(name, NAME_SIZE, L"\Device\Optic%2.2d",
dev_index);

RtlInitUnicodeString(&dev_name, name);

status = IoCreateDevice(Driver, // driver

maxSize, // size of extension

&dev_name, // device name

FILE_DEVICE_8042_PORT, // device type ??
unknown at this time!!!

,
// device characteristics

FALSE, // exclusive

&device // new device

);

Registration process in I8xMouseStart

status = IoRegisterDeviceInterface(MouseExtension->PDO,
&GUID_DEVCLASS_MOUSE, NULL, &MouseExtension->sys_mou_interface);

if (NT_SUCCESS(status))
status = IoSetDeviceInterfaceState(&MouseExtension->sys_mou_interface,
TRUE);
if (!NT_SUCCESS(status))
goto I8xMouseStartDeviceExit;

Please look at writing a device upper level filter. You are provided an
ISR hook and the ability to modify reported MOUSE_INPUT_DATA packets
from the filter and you can leverage the std processing in i8042prt.

As for your create issues, this is because the class driver is blocking
you from succeeding. Keyboards and mice are protected system devices
that can only be opened for read by a kernel level component. To work
around this, you need to create a 2ndary device named object, create the
symbolic link for it (you don’t have to do this in user mode, it can be
done by the driver) and then reroute from the 2ndary devobj to the
device object in the stack.

See this KB article for details:
http://support.microsoft.com/default.aspx?scid=kb;en-us;262305

d

-----Original Message-----
From: xxxxx@mouse-trak.com [mailto:xxxxx@mouse-trak.com]
Sent: Tuesday, January 28, 2003 9:43 AM
To: NT Developers Interest List
Subject: [ntdev] registering device interface

Ok here is my story… I am modifying the i8042prt.sys driver (mouse
port driver) that comes with the DDK so as to get data directly from the
driver to my application. On NT this had proven to be not as difficult
of
a task as it has on 2000. Following is what I have tried and what I
have
run against.

First I simply named my device in the AddDevice routine, tested it
successfully and then tried creating a symbolic link the old fashion way
in the “AddDevice” routine itself. This caused both the mouse and
keyboard
to not work (drv probably never loaded). So I decided to use
IoRegisterDeviceInterface() instead, again in the AddDevice routine.

I called the IoSetDeviceInterfaceState(pdo, true) in response to the
IRP_MN_START_DEVICE irp. The interface registered yet I was not able to
use CreateFile. It always failed except when I deleted the
GENERIC_READ
flag leaving GENERIC_WRITE only in the call. Even so the handle so
obtained when used with the ReadFile() and WriteFile() failed to read or
write, of course. I then tried both REGISTERING and enabling the
interfaces in I8xMouseStartDevice routine of the sample (called in
response to IRP_MN_START_DEVICE irp). Again I was able to register but
had the same problem with CreateFile().

I then tried both naming and registering the device, which previously
I
was not able to do when I was registering the device in the AddDevice
routine. This time it worked though, yet I had the same problem with
CreateFile. So I tried creating a symbolic link to my named device from
the user application using DefineDosDevice(DDD_RAW_TARGET_PATH,
“somename”, \Device\Optic01), this succeeded. Yet the CreateFile had
the same problem.

I have gone through the registry to see if there were some keys causing
this problem, have found none. I used a utility called Devview.exe,
that
came with a book i bought, to look at the security on the device objects
and Under “Allow To everyone” it said, FILE_READ_DATA, FILE_WRITE_DATA
along with other attributes. So for all practical purposes it should
work. Dose anyone have any idea as to what I may be doing wrong here?
I’ve been working at this problem for a while now and am now getting
desperate, any help would be greatly appreciated.

drv_hndl = CreateFile(&dev_path_array[0][0],
/*GENERIC_READ|*/GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
NULL);

Kernel level

dev_index = InterlockedIncrement(&last_index);

_snwprintf(name, NAME_SIZE, L"\Device\Optic%2.2d",
dev_index);

RtlInitUnicodeString(&dev_name, name);

status = IoCreateDevice(Driver, // driver

maxSize, // size of
extension

&dev_name, // device name

FILE_DEVICE_8042_PORT, // device type ??
unknown at this time!!!

,

// device characteristics

FALSE, // exclusive

&device // new device

);

Registration process in I8xMouseStart

status =
IoRegisterDeviceInterface(MouseExtension->PDO,
&GUID_DEVCLASS_MOUSE, NULL, &MouseExtension->sys_mou_interface);

if (NT_SUCCESS(status))
status =
IoSetDeviceInterfaceState(&MouseExtension->sys_mou_interface,
TRUE);
if (!NT_SUCCESS(status))
goto I8xMouseStartDeviceExit;


You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com