/* $Id$ */
/** @file
* VBoxSmcUtil - Quick hack for viewing SMC data on a mac.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOReturn.h>
#include <CoreFoundation/CoreFoundation.h>
#include <unistd.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
enum
{
kSMCSuccess = 0,
};
typedef enum
{
kSMCUserClientOpen = 0,
} KSMCFUNCTION;
typedef struct
{
struct
{
} Version;
struct
{
struct
{
} KeyInfo;
} SMCPARAM;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static int ConnectToSmc(void)
{
if (g_hSmcService == IO_OBJECT_NULL)
return VERR_NOT_FOUND;
{
rcIo = IOConnectCallMethod(g_hSmcConnect, kSMCUserClientOpen, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL);
if (rcIo == kIOReturnSuccess)
return VINF_SUCCESS;
}
else
{
}
return RTErrConvertFromDarwinIO(rcIo);
}
static void DisconnectFromSmc(void)
{
if (g_hSmcConnect)
{
}
if (g_hSmcService)
{
}
}
{
IOReturn rcIo = IOConnectCallStructMethod(g_hSmcConnect, kSMCHandleYPCEvent, pIn, sizeof(*pIn), pOut, &cbOut);
if (rcIo == kIOReturnSuccess)
return VINF_SUCCESS;
return RTErrConvertFromDarwinIO(rcIo);
}
{
if (RT_SUCCESS(rc))
else
*pcKeys = 1;
return rc;
}
{
if (RT_SUCCESS(rc))
{
{
/* Get the key info. */
{
/* Get the key value. */
if (RT_SUCCESS(rc) && (pKeyData->uResult == kSMCSuccess || pKeyData->uResult == 0x85 /* not readable */))
{
rc = VINF_SUCCESS;
}
else if (RT_SUCCESS(rc))
{
}
}
else if (RT_SUCCESS(rc))
{
}
}
else
{
}
}
return rc;
}
{
{
/* Get the key value. */
if (RT_SUCCESS(rc) && (pKeyData->uResult == kSMCSuccess || pKeyData->uResult == 0x85 /* not readable */))
{
rc = VINF_SUCCESS;
}
else if (RT_SUCCESS(rc))
{
}
}
else if (RT_SUCCESS(rc))
{
}
return rc;
}
{
RTPrintf("key=%4.4s type=%4.4s cb=%#04x fAttr=%#04x",
{
bool fPrintable = true;
{
fPrintable = false;
break;
}
if (fPrintable)
else
}
RTPrintf(" <not readable>\n");
}
{
if (RT_SUCCESS(rc))
DisplayKey(&Key);
}
{
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
rc = ConnectToSmc();
if (RT_SUCCESS(rc))
{
/*
* Dump the keys.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
DisplayKey(&Key);
}
}
/*
* Known keys that doesn't make it into the enumeration.
*/
DisplayKeyByName('OSK0');
DisplayKeyByName('OSK1');
DisplayKeyByName('OSK2');
/* Negative checks, sometimes maybe. */
DisplayKeyByName('$Num');
DisplayKeyByName('MSTf');
DisplayKeyByName('MSDS');
DisplayKeyByName('LSOF');
}
if (RT_SUCCESS(rc))
return RTEXITCODE_SUCCESS;
return RTEXITCODE_FAILURE;
}