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