Powered By Blogger
Thursday, June 11, 2009

Adding a kernel IOCTL

It is assumed that , the OAL code is cloned to the BSP under development, including the ioctl code. For the purpose of explaining the process, the Mainstone III reference platform will be used.

The BSP specific, ioctl will be located under the directory, MAINSTONEIII\SRC\OAL\OALLIB\ioctl.c.

Now lets assume that we need to implement an ioctl to flag the backing up of system alarm setting during shutdown.

  • Define a new function in ioctl.c as:
BOOL OALIoCtlHalAlarmSet
( UINT32 code, VOID *pInpBuffer,
UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize)
{
g_oalIoCtlUserAlarmSet = TRUE;
return(TRUE);
}

  • Define a macro for the new IOCTL.
#define FILE_DEVICE_CUST_OEM   32806

#define IOCTL_DDK_SET_ALARM_FLAG \
CTL_CODE(FILE_DEVICE_CUST_OEM, 0x0100, METHOD_BUFFERED, FILE_ANY_ACCESS)
  • Modify g_oalIoCtlTable variable in ioctl.c to add the new ioctl mapping:
const OAL_IOCTL_HANDLER g_oalIoCtlTable[] = {
.....
{
IOCTL_DDK_SET_ALARM_FLAG,
0,
OALIoCtlHalAlarmSet
},
#include
.....
}

Now we have a kernel ioctl, which can be invoked from any section coming under kernel address space. For making this IOCTL accessible from User space, we need to customise (clone) OALIOCTL, which will be described in another post in detail

2 comments:

GSR said...

Could you please let us know how to call KernelIOCTL calls from an User Application.

Vaisakh P S said...

Hi,
Thanks for dropping by my blog. Regarding your query you cannot directly invoke a kernel ioctl from a user mode application. For doing so, you will need to clone and modify OALIOCTL module and add your required ioctl. (if you are adding a new one).

OALIOCTL is located in WINCE600\PUBLIC\COMMON\OAK\OALIOCTL.

Once the ioctl is present in that, you invoke it using KernelIoControl function (http://msdn.microsoft.com/en-us/library/ms886729.aspx).