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