deviceinfo.c
来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 196 行
C
196 行
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// File: deviceinfo.c
//
// This file implements the IOCTL_HAL_GET_DEVICE_INFO handler.
//
#include <windows.h>
#include <bldver.h>
#include <oal.h>
//------------------------------------------------------------------------------
//
// Local: platformVersionXxxx
//
// Version strings for the different platform types.
//
#define NUM_TOTALPLATFORMS_SMARTPHONE 1
const PLATFORMVERSION platformVersionSmartphone[NUM_TOTALPLATFORMS_SMARTPHONE] = {{4, 0}};
#define NUM_TOTALPLATFORMS_POCKETPC 2
static const PLATFORMVERSION platformVersionPocketPC[NUM_TOTALPLATFORMS_POCKETPC] = {{4, 0}, {5, 0}};
#define NUM_TOTALPLATFORMS_WINCE 1
static const PLATFORMVERSION platformVersionWinCe[NUM_TOTALPLATFORMS_WINCE] = {{CE_MAJOR_VER, CE_MINOR_VER}};
//------------------------------------------------------------------------------
//
// Function: OALIoCtlGetDeviceInfo
//
// Implements the IOCTL_HAL_GET_DEVICE_INFO handler
//
BOOL OALIoCtlHalGetDeviceInfo(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize
) {
BOOL rc = FALSE;
UINT32 length;
const PLATFORMVERSION *pVersion;
LPCWSTR pTypeDesc;
OALMSG(OAL_IOCTL&&OAL_FUNC, (L"+OALIoCtlHalGetDeviceInfo(...)\r\n"));
// Validate inputs
if (pInpBuffer == NULL || inpSize < sizeof(UINT32))
{
NKSetLastError(ERROR_INVALID_PARAMETER);
OALMSG(OAL_ERROR, (
L"ERROR: OALIoCtlHalGetDeviceInfo: Invalid parameter\r\n"
));
goto cleanUp;
}
// Process according to input request
switch (*(UINT32*)pInpBuffer)
{
case SPI_GETPLATFORMTYPE:
// Differentiate based on platform type
if (g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_SMARTPHONE ||
g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_POCKETPC)
{
// on PocketPC and Smartphone platforms the platform type
// string may contain NULLs and is terminated with a
// double NULL.
//
const WCHAR* pwszTemp;
UINT32 nSubStrLen;
length = sizeof(WCHAR);
pTypeDesc = pwszTemp = g_oalIoCtlPlatformType;
while( *pwszTemp != 0 )
{
nSubStrLen = NKwcslen(pwszTemp) + 1;
length += nSubStrLen * sizeof(WCHAR);
pwszTemp += nSubStrLen;
}
}
else
{
pTypeDesc = g_oalIoCtlPlatformType;
length = (NKwcslen(pTypeDesc) + 1) * sizeof(WCHAR);
}
// Return required size
if (pOutSize != NULL)
{
*pOutSize = length;
}
// If there isn't output buffer or it is small return error
if (pOutBuffer == NULL || outSize < length)
{
NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
OALMSG(OAL_WARN, (
L"WARN: OALIoCtlHalGetDeviceInfo: Insufficient buffer\r\n"
));
break;
}
// Copy requested data to caller's buffer
memcpy(pOutBuffer, pTypeDesc, length);
rc = TRUE;
break;
case SPI_GETOEMINFO:
// Validate output buffer size
length = (NKwcslen(g_oalIoCtlPlatformOEM) + 1) * sizeof(WCHAR);
// Return required size
if (pOutSize != NULL)
{
*pOutSize = length;
}
// If there isn't output buffer or it is small return error
if (pOutBuffer == NULL || outSize < length)
{
NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
OALMSG(OAL_WARN, (
L"WARN: OALIoCtlHalGetDeviceInfo: Insufficient buffer\r\n"
));
break;
}
// Copy requested data to caller's buffer, set output length
memcpy(pOutBuffer, g_oalIoCtlPlatformOEM, length);
rc = TRUE;
break;
case SPI_GETPLATFORMVERSION:
// Differentiate based on platform type
if (g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_SMARTPHONE)
{
length = sizeof(platformVersionSmartphone);
pVersion = platformVersionSmartphone;
}
else if (g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_POCKETPC)
{
length = sizeof(platformVersionPocketPC);
pVersion = platformVersionPocketPC;
}
else
{
length = sizeof(platformVersionWinCe);
pVersion = platformVersionWinCe;
}
// Return required size
if (pOutSize != NULL)
{
*pOutSize = length;
}
// Return platform version
if (outSize < length)
{
NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
OALMSG(OAL_WARN, (
L"WARN: OALIoCtlHalGetDeviceInfo: Insufficient buffer\r\n"
));
}
else if (!pOutBuffer)
{
NKSetLastError(ERROR_INVALID_PARAMETER);
OALMSG(OAL_WARN, (
L"WARN: OALIoCtlHalGetDeviceInfo: Invalid parameter\r\n"
));
}
else
{
memcpy(pOutBuffer, pVersion, length);
rc = TRUE;
}
break;
default:
OALMSG(OAL_ERROR, (
L"ERROR: OALIoCtlHalGetDeviceInfo: Invalid request\r\n"
));
break;
}
cleanUp:
// Indicate status
OALMSG(OAL_FUNC&&OAL_IOCTL, (
L"-OALIoCtlHalGetDeviceInfo(rc = %d)\r\n", rc
));
return rc;
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?