00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define LIBSMBIOS_SOURCE
00020 #include "smbios/ISmbios.h"
00021 #include "smbios/IToken.h"
00022
00023 #include "smbios/SystemInfo.h"
00024 #include "smbios/IMemory.h"
00025 #include "smbios/SmbiosDefs.h"
00026 #include "ExceptionImpl.h"
00027
00028 #include "SystemDetect.h"
00029 #include "DellMagic.h"
00030
00031
00032 #include "smbios/message.h"
00033
00034 using namespace smbios;
00035 using namespace cmos;
00036 using namespace std;
00037
00038 extern smbios::Exception<smbios::IException> SysInfoException;
00039
00040
00041
00042
00043
00044
00045 static u16 getIdByteFromMem ()
00046 {
00047 u16 tempWord = 0;
00048 u16 idWord = 0;
00049 memory::IMemory *mem = 0;
00050
00051 struct two_byte_structure tbs;
00052 struct two_byte_structure *ptbs = &tbs;
00053 struct one_byte_structure *pobs =
00054 reinterpret_cast<one_byte_structure*>(&(tbs.bios_version));
00055
00056 mem = memory::MemoryFactory::getFactory()->getSingleton();
00057
00058 if( 0 == mem )
00059 throw InternalErrorImpl();
00060
00061
00062 u8 strBuf[DELL_SYSTEM_STRING_LEN] = { 0, };
00063 mem->fillBuffer( strBuf, DELL_SYSTEM_STRING_LOC, DELL_SYSTEM_STRING_LEN - 1 );
00064 if( strncmp( reinterpret_cast<char*>(strBuf), DELL_SYSTEM_STRING, DELL_SYSTEM_STRING_LEN ) != 0 )
00065 goto out;
00066
00067
00068 mem->fillBuffer( reinterpret_cast<u8 *>(ptbs), TWO_BYTE_STRUCT_LOC, sizeof(two_byte_structure) );
00069
00070
00071
00072
00073
00074 tempWord = pobs->system_id;
00075
00076
00077
00078 if (0xFE == tempWord)
00079 {
00080
00081
00082
00083
00084
00085 tempWord = ptbs->two_byte_id;
00086 }
00087
00088 idWord = tempWord;
00089
00090 out:
00091 return idWord;
00092 }
00093
00094 static u16 getIdByteFromMem_Diamond ()
00095 {
00096 u16 idWord = 0;
00097 memory::IMemory *mem = 0;
00098 u8 strBuf[DELL_SYSTEM_STRING_LEN] = { 0, };
00099
00100 mem = memory::MemoryFactory::getFactory()->getSingleton();
00101
00102 if( 0 == mem )
00103 throw InternalErrorImpl();
00104
00105
00106 mem->fillBuffer( strBuf, DELL_SYSTEM_STRING_LOC_DIAMOND_1, DELL_SYSTEM_STRING_LEN - 1 );
00107 if( strncmp( reinterpret_cast<char*>(strBuf), DELL_SYSTEM_STRING, DELL_SYSTEM_STRING_LEN ) == 0 )
00108 if( SYSTEM_ID_DIAMOND == mem->getByte( ID_BYTE_LOC_DIAMOND_1 ) )
00109 idWord = SYSTEM_ID_DIAMOND;
00110
00111 mem->fillBuffer( strBuf, DELL_SYSTEM_STRING_LOC_DIAMOND_2, DELL_SYSTEM_STRING_LEN - 1 );
00112 if( strncmp( reinterpret_cast<char*>(strBuf), DELL_SYSTEM_STRING, DELL_SYSTEM_STRING_LEN ) == 0 )
00113 if( SYSTEM_ID_DIAMOND == mem->getByte( ID_BYTE_LOC_DIAMOND_2 ) )
00114 idWord = SYSTEM_ID_DIAMOND;
00115
00116 return idWord;
00117 }
00118
00119 static u16 getIdByteFromOEMItem ()
00120 {
00121
00122 u16 idWord = 0;
00123 smbios::ISmbiosTable *table = 0;
00124 smbios::ISmbiosTable::iterator item;
00125 if (!couldBeBayonet())
00126 goto out;
00127
00128 table = smbios::SmbiosFactory::getFactory()->getSingleton();
00129
00130 if (0 == table)
00131 throw InternalErrorImpl();
00132
00133
00134 for( item = (*table)[OEM_Strings] ; item != table->end(); ++item)
00135 {
00136 const char *str = item->getStringByStringNumber (2);
00137
00138
00139
00140
00141 if( 0 != str )
00142
00143 idWord = static_cast<u16>(strtol( &str[2], NULL, 16 ));
00144 }
00145
00146 out:
00147
00148 return idWord;
00149 }
00150
00151 static u16 getIdByteFromRevItem ()
00152 {
00153
00154 u16 idWord = 0;
00155 smbios::ISmbiosTable *table = 0;
00156 smbios::ISmbiosTable::iterator item;
00157
00158 table = smbios::SmbiosFactory::getFactory()->getSingleton();
00159
00160 if (0 == table)
00161 throw InternalErrorImpl();
00162
00163
00164 for( item = (*table)[Dell_Revisions_and_IDs]; item != table->end(); ++item)
00165 {
00166
00167 idWord = getU8_FromItem(*item, 0x06);
00168 if( 0xFE == idWord )
00169 {
00170 idWord = getU16_FromItem(*item, 0x08);
00171 }
00172 }
00173
00174 return idWord;
00175 }
00176
00177
00178
00179 struct DellIdByteFunctions
00180 {
00181 u16 (*f_ptr)();
00182 }
00183 DellIdByteFunctions[] = {
00184 {&getIdByteFromMem,},
00185
00186 {&getIdByteFromOEMItem,},
00187 {&getIdByteFromMem_Diamond,},
00188
00189
00190
00191
00192 {&getIdByteFromRevItem,},
00193 };
00194
00195
00196
00197
00198 int SMBIOSGetDellSystemId()
00199 {
00200
00201 int systemId = 0;
00202 int numEntries =
00203 sizeof (DellIdByteFunctions) / sizeof (DellIdByteFunctions[0]);
00204
00205 for (int i = 0; i < numEntries; ++i)
00206 {
00207
00208 try
00209 {
00210
00211 systemId = DellIdByteFunctions[i].f_ptr ();
00212 }
00213 catch(const smbios::IException &e)
00214 {
00215 SysInfoException.setMessageString(e.what());
00216 }
00217 catch(...)
00218 {
00219 SysInfoException.setMessageString( _("Unknown internal error occurred") );
00220 }
00221 if (0 != systemId)
00222 {
00223 break;
00224 }
00225 }
00226
00227 return systemId;
00228 }
00229