1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
*
* Copyright (C) 2005 Dell Inc.
* by Michael Brown <Michael_E_Brown@dell.com>
* Licensed under the Open Software License version 2.1
*
* Alternatively, you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
#define LIBSMBIOS_SOURCE
#include "smbios/ISmbios.h"
#include "smbios/IToken.h"
#include "smbios/SystemInfo.h"
#include "smbios/IMemory.h"
#include "smbios/SmbiosDefs.h"
#include "ExceptionImpl.h"
#include "SystemDetect.h"
// all our magic numbers
#include "DellMagic.h"
#include <string.h>
// include this last.
#include "smbios/message.h"
using namespace smbios;
using namespace cmos;
using namespace std;
// This is defined in SysInfoError.cpp
extern smbios::Exception<smbios::IException> SysInfoException;
//
//
// Detection functions
//
//
bool couldBeDiamond ()
{
bool couldBeDiamond = false;
if(SMBIOSGetDellSystemId() == SYSTEM_ID_DIAMOND )
couldBeDiamond=true;
return couldBeDiamond;
}
bool couldBeBayonet ()
{
//functionEnter( "%s", "" );
bool couldBeBayonet = false;
const smbios::ISmbiosTable *table =
smbios::SmbiosFactory::getFactory()->getSingleton();
// crappy msvc compiler workaround
smbios::ISmbiosTable::const_iterator item ;
if (0 == table)
throw InternalErrorImpl();
// search through 0x0B (OEM_Strings_Structure) items
for( item = (*table)[OEM_Strings] ; item != table->end(); ++item)
{
const char *str = item->getStringByStringNumber (OEM_String_Field_Number); // no need to free retval.
if ((0 != str) && (0 == strncmp (str, Bayonet_Detect_String, strlen(Bayonet_Detect_String))))
couldBeBayonet = true;
}
//functionLeave( "\t\tretval = %i\n", (int)couldBeBayonet );
return couldBeBayonet;
}
static bool isStdDellBiosSystem ()
{
//functionEnter( "%s", "" );
bool dellSystem = false;
// OEM String is 5 chars ("Dell\0")
char OEMString[5] = { 0, };
memory::IMemory *mem =
memory::MemoryFactory::getFactory()->getSingleton();
mem->fillBuffer( reinterpret_cast<u8 *>(OEMString), OEM_String_Location, 4 );
if (0 == strncmp (OEMString, OEM_Dell_String, 5))
dellSystem = true;
//functionLeave( "\t\tretval = %i\n", (int)dellSystem );
return dellSystem;
}
//
// List of detection functions
//
struct SystemDetectionFunction
{
bool (*f_ptr)();
}
DellDetectionFunctions[] = {
{&isStdDellBiosSystem,},
{&couldBeBayonet,},
{&couldBeDiamond,},
};
//
// The main detection routine
//
int SMBIOSIsDellSystem ()
{
bool isDell = false;
int retval = 0;
//functionEnter( "%s", "" );
// notice how extensible this is...
// We can add new detection functions to the array defined
// above at any time...
//
// Why not add an 8450 detection routine? Anybody?
//
int numEntries =
sizeof (DellDetectionFunctions) /
sizeof (DellDetectionFunctions[0]);
for (int i = 0; i < numEntries; ++i)
{
try
{
isDell = DellDetectionFunctions[i].f_ptr ();
}
catch(const smbios::IException &e)
{
SysInfoException.setMessageString(e.what());
}
catch(...)
{
SysInfoException.setMessageString( _("Unknown internal error occurred") );
}
if (isDell)
break;
}
//Convert to an int for our C-caller friends
if(isDell)
{
retval = 1;
}
else
{
retval = 0;
}
//functionLeave( "\t\tretval = %i\n", (int)retval );
return retval;
}
|