1 | /*␊ |
2 | * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project␊ |
3 | *␊ |
4 | * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | ␊ |
9 | #include "boot.h"␊ |
10 | #include "bootstruct.h"␊ |
11 | #include "smbios_getters.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_SMBIOS␊ |
14 | #define DEBUG_SMBIOS 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_SMBIOS==2␊ |
18 | #define DBG(x...)␉printf(x)␊ |
19 | #elif DEBUG_SMBIOS==1␊ |
20 | #define DBG(x...) msglog(x)␊ |
21 | #else␊ |
22 | #define DBG(x...)␉␊ |
23 | #endif␊ |
24 | ␊ |
25 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
26 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
27 | #define SMB_ALLOC_SIZE␉16384␊ |
28 | ␊ |
29 | ␊ |
30 | //-------------------------------------------------------------------------------------------------------------------------␊ |
31 | // SMBIOS Plist Keys␊ |
32 | //-------------------------------------------------------------------------------------------------------------------------␊ |
33 | /* BIOS Information */␊ |
34 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
35 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
36 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
37 | ␊ |
38 | /* System Information */␊ |
39 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
40 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
41 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
42 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
43 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
44 | ␊ |
45 | /* Base Board */␊ |
46 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
47 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
48 | ␊ |
49 | /* Processor Information */␊ |
50 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
51 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
52 | #define kSMBProcessorInformationCurrentClockKey␉␉"SMcurrentclock"␊ |
53 | ␊ |
54 | /* Memory Device */␊ |
55 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
56 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
57 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
58 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
59 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
60 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
61 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
62 | ␊ |
63 | /* Apple Specific */␊ |
64 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
65 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
66 | ␊ |
67 | //-------------------------------------------------------------------------------------------------------------------------␊ |
68 | // Default SMBIOS Data␊ |
69 | //-------------------------------------------------------------------------------------------------------------------------␊ |
70 | static char fake_serial[11];␊ |
71 | ␊ |
72 | static char const sn_gen_pn_str[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ␊ |
73 | ␊ |
74 | typedef struct {␊ |
75 | const char* key;␊ |
76 | const char* value;␊ |
77 | } SMStrEntryPair;␊ |
78 | ␊ |
79 | // defaults for a MacBook␊ |
80 | static const SMStrEntryPair const sm_macbook_defaults[]={␊ |
81 | ␉{"SMbiosvendor", "Apple Inc." },␊ |
82 | ␉{"SMbiosversion", "MB41.88Z.00C1.B00.0802091535"␉},␊ |
83 | ␉{"SMbiosdate", "02/09/2008" },␊ |
84 | ␉{"SMmanufacter", "Apple Inc." },␊ |
85 | ␉{"SMproductname", "MacBook4,1" },␊ |
86 | ␉{"SMsystemversion", "1.0" },␊ |
87 | ␉{"SMserial", "RM83064H0P1" },␊ |
88 | {"SMserialProductCountry",␉"RM" },␊ |
89 | {"SMserialYear", "8" },␊ |
90 | ␉{"SMserialWeek", "30" },␊ |
91 | ␉{"SMserialProductNumber",␉"64H" },␊ |
92 | ␉{"SMserialModel",␉␉␉"0P1" },␊ |
93 | ␉{"SMfamily", "MacBook" },␊ |
94 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
95 | ␉{"SMboardproduct", "Mac-F22788A9" },␊ |
96 | ␉{ "",""␉}␊ |
97 | };␊ |
98 | ␊ |
99 | // defaults for a MacBook Pro␊ |
100 | static const SMStrEntryPair const sm_macbookpro_defaults[]={␊ |
101 | ␉{"SMbiosvendor", "Apple Inc." },␊ |
102 | ␉{"SMbiosversion", "MBP41.88Z.00C1.B03.0802271651"␉},␊ |
103 | ␉{"SMbiosdate", "02/27/2008" },␊ |
104 | ␉{"SMmanufacter", "Apple Inc." },␊ |
105 | ␉{"SMproductname", "MacBookPro4,1" },␊ |
106 | ␉{"SMsystemversion", "1.0" },␊ |
107 | ␉{"SMserial", "W88198N6YJX" },␊ |
108 | {"SMserialProductCountry",␉"W8" },␊ |
109 | {"SMserialYear", "8" },␊ |
110 | ␉{"SMserialWeek", "19" },␊ |
111 | ␉{"SMserialProductNumber",␉"8N6" },␊ |
112 | ␉{"SMserialModel",␉␉␉"YJX" },␊ |
113 | ␉{"SMfamily", "MacBookPro" },␊ |
114 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
115 | ␉{"SMboardproduct", "Mac-F42C89C8" },␊ |
116 | ␉{ "",""␉}␊ |
117 | };␊ |
118 | ␊ |
119 | // defaults for a Mac mini ␊ |
120 | static const SMStrEntryPair const sm_macmini_defaults[]={␊ |
121 | ␉{"SMbiosvendor", "Apple Inc." },␊ |
122 | ␉{"SMbiosversion", "MM21.88Z.009A.B00.0706281359"␉},␊ |
123 | ␉{"SMbiosdate", "06/28/2007" },␊ |
124 | ␉{"SMmanufacter", "Apple Inc." },␊ |
125 | ␉{"SMproductname", "Macmini2,1" },␊ |
126 | ␉{"SMsystemversion", "1.0" },␊ |
127 | ␉{"SMserial", "YM8054BYYL2" },␊ |
128 | {"SMserialProductCountry",␉"YM" },␊ |
129 | {"SMserialYear", "8" },␊ |
130 | ␉{"SMserialWeek", "05" },␊ |
131 | ␉{"SMserialProductNumber",␉"4BY" },␊ |
132 | ␉{"SMserialModel",␉␉␉"YL2" },␊ |
133 | ␉{"SMfamily", "Napa Mac" },␊ |
134 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
135 | ␉{"SMboardproduct", "Mac-F4208EAA" },␊ |
136 | ␉{ "",""␉}␊ |
137 | };␊ |
138 | ␊ |
139 | // defaults for an iMac␊ |
140 | static const SMStrEntryPair const sm_imac_defaults[]={␊ |
141 | ␉{"SMbiosvendor", "Apple Inc." },␊ |
142 | ␉{"SMbiosversion", "IM71.88Z.007A.B03.0803051705"␉},␊ |
143 | ␉{"SMbiosdate", "03/05/2008" },␊ |
144 | ␉{"SMmanufacter", "Apple Inc." },␊ |
145 | ␉{"SMproductname", "iMac7,1" },␉␊ |
146 | ␉{"SMsystemversion", "1.0" },␊ |
147 | ␉{"SMserial", "W87410PWX87" },␊ |
148 | {"SMserialProductCountry",␉"W8" },␊ |
149 | {"SMserialYear", "7" },␊ |
150 | ␉{"SMserialWeek", "41" },␊ |
151 | ␉{"SMserialProductNumber",␉"0PW" },␊ |
152 | ␉{"SMserialModel",␉␉␉"X87" },␊ |
153 | ␉{"SMfamily", "Mac" },␊ |
154 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
155 | ␉{"SMboardproduct", "Mac-F4238CC8" },␊ |
156 | ␉{ "",""␉}␊ |
157 | };␊ |
158 | ␊ |
159 | // defaults for a Mac Pro␊ |
160 | static const SMStrEntryPair const sm_macpro_defaults[]={␊ |
161 | ␉{"SMbiosvendor", "Apple Computer, Inc."␉␉␉},␊ |
162 | ␉{"SMbiosversion", "MP31.88Z.006C.B02.0801021250"␉},␊ |
163 | ␉{"SMbiosdate", "01/02/2008"␉␉␉␉␉},␊ |
164 | ␉{"SMmanufacter", "Apple Computer, Inc."␉␉␉},␊ |
165 | ␉{"SMproductname", "MacPro3,1"␉␉␉␉␉␉},␊ |
166 | ␉{"SMsystemversion", "1.0"␉␉␉␉␉␉␉},␊ |
167 | ␉{"SMserial", "G88014V4XYK"␉␉␉␉␉},␊ |
168 | {"SMserialProductCountry",␉"G8" },␊ |
169 | {"SMserialYear", "8" },␊ |
170 | ␉{"SMserialWeek", "01" },␊ |
171 | ␉{"SMserialProductNumber",␉"4V4" },␊ |
172 | ␉{"SMserialModel",␉␉␉"XYK" },␊ |
173 | ␉{"SMfamily", "MacPro"␉␉␉␉␉␉},␊ |
174 | ␉{"SMboardmanufacter", "Apple Computer, Inc."␉␉␉},␊ |
175 | ␉{"SMboardproduct", "Mac-F42C88C8"␉␉␉␉␉},␊ |
176 | ␉{ "",""␉}␊ |
177 | };␊ |
178 | ␊ |
179 | // defaults for an iMac11,1 core i3/i5/i7␊ |
180 | static const SMStrEntryPair const sm_imac_core_defaults[]={␊ |
181 | ␉{"SMbiosvendor", "Apple Inc."␉␉␉␉␉},␊ |
182 | ␉{"SMbiosversion", "IM111.88Z.0034.B00.0910301727"␉},␊ |
183 | ␉{"SMbiosdate", "10/30/2009"␉␉␉␉␉},␊ |
184 | ␉{"SMmanufacter", "Apple Inc."␉␉␉␉␉},␊ |
185 | ␉{"SMproductname", "iMac11,1"␉␉␉␉␉␉},␉␊ |
186 | ␉{"SMsystemversion", "1.0"␉␉␉␉␉␉␉},␊ |
187 | ␉{"SMserial", "W89470DZ5RU"␉␉␉␉␉},␊ |
188 | {"SMserialProductCountry",␉ "W8" },␊ |
189 | {"SMserialYear", "9" },␊ |
190 | ␉{"SMserialWeek", "47" },␊ |
191 | ␉{"SMserialProductNumber",␉ "0DZ" },␊ |
192 | ␉{"SMserialModel", "5RU" },␊ |
193 | ␉{"SMfamily", "iMac"␉␉␉␉␉␉␉},␊ |
194 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
195 | ␉{"SMboardproduct", "Mac-F2268DAE"␉␉␉␉␉},␊ |
196 | ␉{ "",""␉}␊ |
197 | };␊ |
198 | ␊ |
199 | // defaults for an iMac12,1 : todo: populate correctly ␊ |
200 | static const SMStrEntryPair const sm_imac_sandy_defaults[]={␊ |
201 | ␉{"SMbiosvendor", "Apple Inc."␉␉␉␉␉},␊ |
202 | ␉{"SMbiosversion", "IM121.88Z.0047.B00.1102091756"},␊ |
203 | ␉{"SMbiosdate", "10/30/2011"␉␉␉␉␉},␊ |
204 | ␉{"SMmanufacter", "Apple Inc."␉␉␉␉␉},␊ |
205 | ␉{"SMproductname", "iMac12,1"␉␉␉␉␉␉},␉␊ |
206 | ␉{"SMsystemversion", "1.0"␉␉␉␉␉␉␉},␊ |
207 | ␉{"SMserial", "W89470DZ5RU"␉␉␉␉␉},␊ |
208 | {"SMserialProductCountry",␉ "W8" },␊ |
209 | {"SMserialYear", "9" },␊ |
210 | ␉{"SMserialWeek", "47" },␊ |
211 | ␉{"SMserialProductNumber",␉ "0DZ" },␊ |
212 | ␉{"SMserialModel", "5RU" },␊ |
213 | ␉{"SMfamily", "iMac"␉␉␉␉␉␉␉},␊ |
214 | ␉{"SMboardmanufacter", "Apple Inc." },␊ |
215 | ␉{"SMboardproduct", "Mac-F2268DAE"␉␉␉␉␉},␊ |
216 | ␉{ "",""␉}␊ |
217 | };␊ |
218 | ␊ |
219 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
220 | static const SMStrEntryPair const sm_macpro_core_defaults[]={␊ |
221 | ␉{"SMbiosvendor", "Apple Computer, Inc."␉␉␉},␊ |
222 | ␉{"SMbiosversion", "MP41.88Z.0081.B03.0902231259"␉},␊ |
223 | ␉{"SMbiosdate", "02/23/2009"␉␉␉␉␉},␊ |
224 | ␉{"SMmanufacter", "Apple Inc." },␊ |
225 | ␉{"SMproductname", "MacPro4,1"␉␉␉␉␉␉},␊ |
226 | ␉{"SMsystemversion", "1.0"␉␉␉␉␉␉␉},␊ |
227 | ␉{"SMserial", "CK91601V8Q0"␉␉␉␉␉},␊ |
228 | {"SMserialProductCountry",␉"CK" },␊ |
229 | {"SMserialYear", "9" },␊ |
230 | ␉{"SMserialWeek", "16" },␊ |
231 | ␉{"SMserialProductNumber",␉"01V" },␊ |
232 | ␉{"SMserialModel",␉␉␉"8Q0" },␊ |
233 | ␉{"SMfamily", "MacPro"␉␉␉␉␉␉},␊ |
234 | ␉{"SMboardmanufacter", "Apple Computer, Inc."␉␉␉},␊ |
235 | ␉{"SMboardproduct", "Mac-F221BEC8"␉␉␉␉␉},␊ |
236 | ␉{ "",""␉}␊ |
237 | };␊ |
238 | ␊ |
239 | // defaults for a Mac Pro 5,1 Westmere␊ |
240 | static const SMStrEntryPair const sm_macpro_westmere_defaults[]={␊ |
241 | ␉{"SMbiosvendor", "Apple Computer, Inc."␉␉␉},␊ |
242 | ␉{"SMbiosversion", "MP51.88Z.007F.B00.1008031144"␉},␊ |
243 | ␉{"SMbiosdate", "08/03/2010"␉␉␉␉␉},␊ |
244 | ␉{"SMmanufacter", "Apple Inc." },␊ |
245 | ␉{"SMproductname", "MacPro5,1"␉␉␉␉␉␉},␊ |
246 | ␉{"SMsystemversion", "0.0"␉␉␉␉␉␉␉},␊ |
247 | ␉{"SMserial", "YM0330U7EUH"␉␉␉␉␉},␊ |
248 | {"SMserialProductCountry",␉"YM" },␊ |
249 | {"SMserialYear", "0" },␊ |
250 | ␉{"SMserialWeek", "33" },␊ |
251 | ␉{"SMserialProductNumber",␉"0U7" },␊ |
252 | ␉{"SMserialModel",␉␉␉"EUH" },␊ |
253 | ␉{"SMfamily", "MacPro"␉␉␉␉␉␉},␊ |
254 | ␉{"SMboardmanufacter", "Apple Computer, Inc."␉␉␉},␊ |
255 | ␉{"SMboardproduct", "Mac-F221BEC8"␉␉␉␉␉},␊ |
256 | ␉{ "",""␉}␊ |
257 | };␊ |
258 | ␊ |
259 | // default for a Xserve␊ |
260 | static const SMStrEntryPair const sm_xserve_defaults[]={␊ |
261 | {"SMbiosvendor", "Apple Inc."␉␉␉␉␉},␊ |
262 | {"SMbiosversion", "XS21.88Z.006C.B06.0804011317"␉},␊ |
263 | {"SMbiosdate", "04/01/2008"␉␉␉␉␉},␊ |
264 | {"SMmanufacter", "Apple Inc."␉␉␉␉␉},␊ |
265 | {"SMproductname", "Xserve2,1"␉␉␉␉␉␉},␊ |
266 | {"SMsystemversion", "1.0"␉␉␉␉␉␉␉},␊ |
267 | {"SMserial", "CK816033X8S"␉␉␉␉␉},␊ |
268 | {"SMserialProductCountry",␉"CK" },␊ |
269 | {"SMserialYear", "8" },␊ |
270 | ␉{"SMserialWeek", "16" },␊ |
271 | ␉{"SMserialProductNumber",␉"033" },␊ |
272 | ␉{"SMserialModel",␉␉␉"X8S" },␊ |
273 | {"SMfamily", "Xserve"␉␉␉␉␉␉},␊ |
274 | {"SMboardmanufacter", "Apple Inc."␉␉␉␉␉},␊ |
275 | {"SMboardproduct", "Mac-F42289C8"␉␉␉␉␉},␊ |
276 | ␉{ "",""␉}␊ |
277 | };␊ |
278 | ␊ |
279 | typedef struct {␊ |
280 | const char* code;␊ |
281 | const char* info;␊ |
282 | } SMProductCountry;␊ |
283 | ␊ |
284 | static const SMProductCountry const sm_country_list[]={␊ |
285 | {"1C",␉␉"China" },␊ |
286 | {"2Z",␉␉"Refurbished" },␊ |
287 | {"4H",␉␉"China" },␊ |
288 | {"5K",␉␉"China" },␊ |
289 | {"8H",␉␉"China" },␊ |
290 | {"5D",␉␉"China" },␊ |
291 | {"7J",␉␉"China " },␊ |
292 | {"CK",␉␉"Cork " },␊ |
293 | /*{"E",␉␉"Singapur" },*/␊ |
294 | {"EE",␉␉"Taiwan" },␊ |
295 | /*{"F",␉␉"Fremont " },*/␊ |
296 | {"FC",␉␉"Fountain " },␊ |
297 | {"G8",␉␉"USA" },␊ |
298 | {"GQ",␉␉"Refurbished" },␊ |
299 | {"PT",␉␉"Korea" },␊ |
300 | {"CY",␉␉"Korea" },␊ |
301 | {"QT",␉␉"Taiwan" },␊ |
302 | {"QP",␉␉"China" },␊ |
303 | {"RN",␉␉"Mexico" },␊ |
304 | {"RM",␉␉"Refurbished/Remanufactured"␉␉␉},␊ |
305 | {"SG",␉␉"Singapore" },␊ |
306 | {"UV",␉␉"Taiwan" },␊ |
307 | {"U2",␉␉"Taiwan" },␊ |
308 | {"V7",␉␉"Taiwan" },␊ |
309 | {"VM",␉␉"China" },␊ |
310 | {"W8",␉␉"Shanghai" },␊ |
311 | {"WQ",␉␉"China" },␊ |
312 | {"XA",␉␉"Elk Grove Sacramento"␉␉␉␉␉},␊ |
313 | {"XB",␉␉"Elk Grove Sacramento"␉␉␉␉␉},␊ |
314 | {"YM",␉␉"China /Konfiguriert"␉␉␉␉␉}␊ |
315 | };␊ |
316 | ␊ |
317 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
318 | ␊ |
319 | typedef struct {␊ |
320 | ␉SMBStructHeader *orig;␊ |
321 | ␉SMBStructHeader *new;␊ |
322 | } SMBStructPtrs;␊ |
323 | ␊ |
324 | struct {␊ |
325 | ␉const char *vendor;␊ |
326 | ␉const char *version;␊ |
327 | ␉const char *releaseDate;␊ |
328 | } defaultBIOSInfo;␊ |
329 | ␊ |
330 | struct {␊ |
331 | ␉const char *manufacturer;␊ |
332 | ␉const char *productName;␊ |
333 | ␉const char *version;␊ |
334 | ␉const char *serialNumber;␊ |
335 | ␉const char *family;␊ |
336 | } defaultSystemInfo;␊ |
337 | ␊ |
338 | struct {␊ |
339 | ␉const char *manufacturer;␊ |
340 | ␉const char *product;␊ |
341 | } defaultBaseBoard;␊ |
342 | ␊ |
343 | ␊ |
344 | typedef struct {␊ |
345 | ␉uint8_t␉␉␉type;␊ |
346 | ␉SMBValueType␉valueType;␊ |
347 | ␉uint8_t␉␉␉fieldOffset;␊ |
348 | ␉char␉␉␉*keyString;␊ |
349 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
350 | ␉const char␉␉␉**defaultValue;␊ |
351 | } SMBValueSetter;␊ |
352 | ␊ |
353 | SMBValueSetter SMBSetters[] = ␊ |
354 | { ␊ |
355 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
356 | ␉// BIOSInformation␊ |
357 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
358 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
359 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
360 | ␊ |
361 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
362 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
363 | ␊ |
364 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
365 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
366 | ␊ |
367 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
368 | ␉// SystemInformation␊ |
369 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
370 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
371 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
372 | ␊ |
373 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
374 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
375 | ␊ |
376 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
377 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
378 | ␊ |
379 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
380 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
381 | ␊ |
382 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
383 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
384 | ␊ |
385 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
386 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
387 | ␊ |
388 | ␊ |
389 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
390 | ␉// BaseBoard␊ |
391 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
392 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
393 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
394 | ␊ |
395 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
396 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
397 | ␊ |
398 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
399 | ␊ |
400 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
401 | ␊ |
402 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
403 | ␊ |
404 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
405 | ␊ |
406 | ␊ |
407 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
408 | ␉// ProcessorInformation␊ |
409 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
410 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
411 | ␊ |
412 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
413 | ␊ |
414 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
415 | ␊ |
416 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
417 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
418 | ␊ |
419 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
420 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
421 | ␉␊ |
422 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, currentClock),␉␉kSMBProcessorInformationCurrentClockKey,␉␊ |
423 | ␉␉getProcessorInformationCurrentClock,␉NULL},␊ |
424 | ␊ |
425 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
426 | ␊ |
427 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
428 | ␊ |
429 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
430 | ␊ |
431 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
432 | ␉// Memory Device␊ |
433 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
434 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
435 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
436 | ␊ |
437 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
438 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
439 | ␊ |
440 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
441 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
442 | ␊ |
443 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
444 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
445 | ␊ |
446 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
447 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
448 | ␊ |
449 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
450 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
451 | ␊ |
452 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
453 | ␊ |
454 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
455 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
456 | ␊ |
457 | ␊ |
458 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
459 | ␉// Apple Specific␊ |
460 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
461 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
462 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
463 | ␊ |
464 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
465 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
466 | };␊ |
467 | ␊ |
468 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
469 | ␊ |
470 | SMBEntryPoint *neweps␉= 0;␊ |
471 | ␊ |
472 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
473 | static uint8_t stringsSize;␉// add string size␊ |
474 | ␊ |
475 | static SMBWord tableLength␉␉= 0;␊ |
476 | static SMBWord handle␉␉␉= 0;␊ |
477 | static SMBWord maxStructSize␉= 0;␊ |
478 | static SMBWord structureCount␉= 0;␊ |
479 | ␊ |
480 | static void setDefaultSMBData(void);␊ |
481 | static bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value);␊ |
482 | static void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field);␊ |
483 | static bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value);␊ |
484 | static void addSMBFirmwareVolume(SMBStructPtrs *structPtr);␊ |
485 | static void addSMBMemorySPD(SMBStructPtrs *structPtr);␊ |
486 | static void addSMBOemProcessorType(SMBStructPtrs *structPtr);␊ |
487 | static void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr);␊ |
488 | static void addSMBEndOfTable(SMBStructPtrs *structPtr);␊ |
489 | static void setSMBStruct(SMBStructPtrs *structPtr);␊ |
490 | static void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr);␊ |
491 | ␊ |
492 | ␊ |
493 | const char *getDefaultSMBproductName(void)␊ |
494 | {␊ |
495 | ␉setDefaultSMBData();␊ |
496 | ␉return defaultSystemInfo.productName;␊ |
497 | }␊ |
498 | ␊ |
499 | const char *getDefaultSMBBoardProduct(void)␊ |
500 | {␊ |
501 | ␉setDefaultSMBData();␊ |
502 | ␉return defaultBaseBoard.product;␊ |
503 | }␊ |
504 | ␊ |
505 | const char* sm_search_str(const SMStrEntryPair*␉sm_defaults, const char * key)␊ |
506 | {␊ |
507 | int i;␊ |
508 | ␊ |
509 | for (i=0; sm_defaults[i].key[0]; i++) {␊ |
510 | ␉␉if (!strcmp (sm_defaults[i].key, key)) {␊ |
511 | ␉␉␉return sm_defaults[i].value;␊ |
512 | ␉␉}␊ |
513 | ␉}␊ |
514 | ␊ |
515 | // Shouldn't happen␊ |
516 | printf ("Error: no default for %s known\n", key);␊ |
517 | sleep (2);␊ |
518 | return "";␊ |
519 | }␊ |
520 | ␊ |
521 | const char* sm_get_random_productNumber()␊ |
522 | {␊ |
523 | static char str[4] = {0x00,0x00,0x00,0x00};␊ |
524 | if(str[0] == 0)␊ |
525 | { ␊ |
526 | // Get randomized characters␊ |
527 | int rand_sn1 ;␊ |
528 | int rand_sn2 ;␊ |
529 | int rand_sn3 ;␊ |
530 | struct ran_obj* random_serial_obj = random_init(0,35);␊ |
531 | rand_sn1 = random(random_serial_obj);␊ |
532 | rand_sn2 = random(random_serial_obj);␊ |
533 | rand_sn3 = random(random_serial_obj);␊ |
534 | random_free(random_serial_obj); ␊ |
535 | ␊ |
536 | // Append all charaters to the string ␊ |
537 | char tmp[2];␊ |
538 | bzero(tmp,sizeof(tmp));␊ |
539 | sprintf(tmp,"%c",sn_gen_pn_str[rand_sn1]);␊ |
540 | strlcpy (str, tmp, sizeof(tmp)+1);␊ |
541 | ␊ |
542 | sprintf(tmp,"%c",sn_gen_pn_str[rand_sn2]);␊ |
543 | strcat (str, tmp);␊ |
544 | ␊ |
545 | sprintf(tmp,"%c",sn_gen_pn_str[rand_sn3]);␊ |
546 | strcat (str, tmp);␊ |
547 | ␊ |
548 | DBG ("fake_productNumber: %s\n",str);␊ |
549 | ␊ |
550 | }␊ |
551 | return str;␊ |
552 | }␊ |
553 | ␊ |
554 | const char* sm_get_random_week()␊ |
555 | {␊ |
556 | static char str[4] = {0x00,0x00,0x00,0x00};␊ |
557 | if(str[0] == 0)␊ |
558 | { ␊ |
559 | // Get randomized characters␊ |
560 | int rand_week ;␊ |
561 | struct ran_obj* random_week_obj = random_init(0,47)/* random_init(1,48) */;␊ |
562 | rand_week = random(random_week_obj); ␊ |
563 | random_free(random_week_obj); ␊ |
564 | ␊ |
565 | // Append all charaters to the string ␊ |
566 | char tmp[3];␊ |
567 | bzero(tmp,sizeof(tmp));␊ |
568 | ␊ |
569 | if (rand_week < 10) {␊ |
570 | sprintf(tmp,"0%d",rand_week);␊ |
571 | strlcpy (str, tmp, sizeof(tmp)+1);␊ |
572 | } else if (rand_week < 100) { // avoid overflow in case random return a number >= 100␊ |
573 | sprintf(tmp,"%d",rand_week);␊ |
574 | strlcpy (str, tmp, sizeof(tmp)+1);␊ |
575 | } ␊ |
576 | ␊ |
577 | DBG ("fake_week: %s\n",str);␊ |
578 | ␊ |
579 | }␊ |
580 | return str;␊ |
581 | }␊ |
582 | ␊ |
583 | const char* sm_get_random_year()␊ |
584 | {␊ |
585 | static char str[2] = {0x00,0x00};␊ |
586 | if(str[0] == 0)␊ |
587 | { ␊ |
588 | // Get randomized characters␊ |
589 | int rand_year ;␊ |
590 | struct ran_obj* random_year_obj = random_init(0,9);␊ |
591 | rand_year = random(random_year_obj); ␊ |
592 | random_free(random_year_obj);␊ |
593 | ␊ |
594 | // Append all charaters to the string ␊ |
595 | char tmp[2];␊ |
596 | bzero(tmp,sizeof(tmp));␊ |
597 | ␊ |
598 | if (rand_year < 10) {␊ |
599 | sprintf(tmp,"%d",rand_year);␊ |
600 | strlcpy (str, tmp, sizeof(tmp)+1);␊ |
601 | }␊ |
602 | ␊ |
603 | DBG ("fake_year: %s\n",str);␊ |
604 | ␊ |
605 | }␊ |
606 | return str;␊ |
607 | }␊ |
608 | ␊ |
609 | const char* sm_get_random_country()␊ |
610 | {␊ |
611 | static char str[3] = {0x00,0x00,0x00};␊ |
612 | if(str[0] == 0)␊ |
613 | { ␊ |
614 | ␊ |
615 | // Get randomized characters␊ |
616 | int rand_country ;␊ |
617 | struct ran_obj* random_country_obj = random_init(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);␊ |
618 | rand_country = random(random_country_obj); ␊ |
619 | random_free(random_country_obj); ␊ |
620 | ␊ |
621 | strlcpy (str, sm_country_list[rand_country].code,strlen(sm_country_list[rand_country].code)+1);␊ |
622 | ␊ |
623 | DBG ("fake_country: %s (%s)\n",str,sm_country_list[rand_country].info);␊ |
624 | ␊ |
625 | }␊ |
626 | return str;␊ |
627 | }␊ |
628 | ␊ |
629 | static void setDefaultSMBData(void)␊ |
630 | {␊ |
631 | ␉static bool setDefSMB = true;␊ |
632 | ␉␊ |
633 | ␉if (setDefSMB) {␉␉␊ |
634 | ␉␉␊ |
635 | const SMStrEntryPair*␉sm_defaults;␊ |
636 | const SMStrEntryPair*␉sm_chosen;␊ |
637 | ␊ |
638 | if (Platform->CPU.isServer == true)␊ |
639 | {␊ |
640 | sm_defaults=sm_xserve_defaults;␊ |
641 | } else if (Platform->CPU.isMobile == true) {␊ |
642 | if (Platform->CPU.NoCores > 1) {␊ |
643 | sm_defaults=sm_macbookpro_defaults;␊ |
644 | } else {␊ |
645 | sm_defaults=sm_macbook_defaults;␊ |
646 | }␊ |
647 | } else {␊ |
648 | switch (Platform->CPU.NoCores) ␊ |
649 | {␊ |
650 | case 1: ␊ |
651 | sm_defaults=sm_macmini_defaults; ␊ |
652 | break;␊ |
653 | case 2:␊ |
654 | sm_defaults=sm_imac_defaults;␊ |
655 | break;␊ |
656 | default:␊ |
657 | {␊ |
658 | switch (Platform->CPU.Family) ␊ |
659 | {␊ |
660 | case 0x06:␊ |
661 | {␊ |
662 | switch (Platform->CPU.Model)␊ |
663 | {␊ |
664 | case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm)␊ |
665 | case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ???␊ |
666 | case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
667 | case 0x19: // Intel Core i5 650 @3.20 Ghz ␊ |
668 | sm_defaults=sm_imac_core_defaults; ␊ |
669 | break;␊ |
670 | ␊ |
671 | case CPUID_MODEL_SANDYBRIDGE:␊ |
672 | case CPUID_MODEL_JAKETOWN:␊ |
673 | sm_defaults=sm_imac_sandy_defaults;␊ |
674 | break;␊ |
675 | ␊ |
676 | case CPUID_MODEL_NEHALEM: ␊ |
677 | case CPUID_MODEL_NEHALEM_EX:␊ |
678 | sm_defaults=sm_macpro_core_defaults; ␊ |
679 | break;␊ |
680 | ␊ |
681 | case CPUID_MODEL_WESTMERE: ␊ |
682 | case CPUID_MODEL_WESTMERE_EX:␊ |
683 | sm_defaults=sm_macpro_westmere_defaults; ␊ |
684 | break;␊ |
685 | ␊ |
686 | default:␊ |
687 | sm_defaults=sm_macpro_defaults; ␊ |
688 | break;␊ |
689 | }␊ |
690 | break;␊ |
691 | }␊ |
692 | default:␊ |
693 | sm_defaults=sm_macpro_defaults; ␊ |
694 | break;␊ |
695 | }␊ |
696 | break;␊ |
697 | }␊ |
698 | }␊ |
699 | }␊ |
700 | ␊ |
701 | {␊ |
702 | const char␉*str;␊ |
703 | int␉␉size;␊ |
704 | ␊ |
705 | if (getValueForKey("SMproductname", &str, &size, &bootInfo->smbiosConfig))␊ |
706 | { ␊ |
707 | if (strstr (str, "MacPro5"))␊ |
708 | {␊ |
709 | sm_chosen = sm_macpro_westmere_defaults ;␊ |
710 | }␊ |
711 | else if (strstr (str, "MacPro4"))␊ |
712 | {␊ |
713 | sm_chosen = sm_macpro_core_defaults ;␊ |
714 | }␊ |
715 | else if (strstr (str, "MacPro"))␊ |
716 | {␊ |
717 | sm_chosen = sm_macpro_defaults ;␊ |
718 | }␊ |
719 | else if (strstr (str,"MacBookPro"))␊ |
720 | {␊ |
721 | sm_chosen = sm_macbookpro_defaults ;␊ |
722 | }␊ |
723 | else if (strstr (str, "MacBook"))␊ |
724 | {␊ |
725 | sm_chosen = sm_macbook_defaults ;␊ |
726 | }␊ |
727 | else if (!strcmp ("iMac12,1", str))␊ |
728 | {␊ |
729 | sm_chosen = sm_imac_sandy_defaults ;␊ |
730 | }␊ |
731 | else if (!strcmp ("iMac11,1", str))␊ |
732 | {␊ |
733 | sm_chosen = sm_imac_core_defaults ;␊ |
734 | }␊ |
735 | else if (strstr (str, "iMac"))␊ |
736 | {␊ |
737 | sm_chosen = sm_imac_defaults ;␊ |
738 | }␊ |
739 | else if (strstr (str, "Macmini"))␊ |
740 | {␊ |
741 | sm_chosen = sm_macmini_defaults ;␊ |
742 | }␊ |
743 | else if (strstr (str, "Xserve"))␊ |
744 | {␊ |
745 | sm_chosen = sm_xserve_defaults ;␊ |
746 | }␊ |
747 | else ␊ |
748 | {␊ |
749 | sm_chosen = sm_defaults ;␊ |
750 | } ␊ |
751 | } ␊ |
752 | else ␊ |
753 | sm_chosen = sm_defaults; ␊ |
754 | } ␊ |
755 | ␊ |
756 | bzero (fake_serial,sizeof(fake_serial)); ␊ |
757 | ␊ |
758 | bool randomSerial = false;␊ |
759 | getBoolForKey(kSMBIOSRandomSerial, &randomSerial, &bootInfo->bootConfig) ;␊ |
760 | ␊ |
761 | if ( randomSerial ) // useless␊ |
762 | strlcpy (fake_serial,sm_get_random_country(), strlen(sm_get_random_country())+1);␊ |
763 | else␊ |
764 | strlcpy (fake_serial,sm_search_str(sm_chosen, "SMserialProductCountry"), strlen(sm_search_str(sm_chosen, "SMserialProductCountry"))+1);␊ |
765 | ␊ |
766 | if ( randomSerial ) // useless␊ |
767 | strcat (fake_serial,sm_get_random_year());␊ |
768 | else␊ |
769 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialYear"));␊ |
770 | ␊ |
771 | if ( randomSerial ) // useless␊ |
772 | strcat (fake_serial,sm_get_random_week());␊ |
773 | else␊ |
774 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialWeek")); ␊ |
775 | ␊ |
776 | if ( randomSerial )␊ |
777 | strcat (fake_serial,sm_get_random_productNumber());␊ |
778 | else␊ |
779 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialProductNumber"));␊ |
780 | ␊ |
781 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialModel"));␊ |
782 | ␊ |
783 | if ( randomSerial )␊ |
784 | msglog ("fake_serial: %s\n",fake_serial); ␊ |
785 | ␊ |
786 | defaultBIOSInfo.version␉␉␉= sm_search_str(sm_chosen, "SMbiosversion");␊ |
787 | defaultBIOSInfo.releaseDate␉␉= sm_search_str(sm_chosen, "SMbiosdate"); ␊ |
788 | defaultBIOSInfo.vendor␉␉␉= sm_search_str(sm_chosen, "SMbiosvendor");␊ |
789 | ␉␉␊ |
790 | defaultSystemInfo.productName␉= sm_search_str(sm_chosen, "SMproductname");␊ |
791 | defaultSystemInfo.family␉␉= sm_search_str(sm_chosen, "SMfamily");␊ |
792 | defaultSystemInfo.manufacturer␉= sm_search_str(sm_chosen, "SMboardmanufacter");␊ |
793 | defaultSystemInfo.version␉␉= sm_search_str(sm_chosen, "SMsystemversion");␊ |
794 | defaultSystemInfo.serialNumber␉= fake_serial;␊ |
795 | ␉␉␊ |
796 | defaultBaseBoard.manufacturer␉= sm_search_str(sm_chosen, "SMboardmanufacter");␊ |
797 | defaultBaseBoard.product␉␉= sm_search_str(sm_chosen, "SMboardproduct");␊ |
798 | ␊ |
799 | ␉␉setDefSMB = false;␊ |
800 | ␉}␉␊ |
801 | }␊ |
802 | ␊ |
803 | /* Used for SM*_N smbios.plist keys */␊ |
804 | static bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
805 | {␊ |
806 | ␉static int idx = -1;␊ |
807 | ␉static int current = -1;␊ |
808 | ␉int len;␊ |
809 | ␉char key[24];␊ |
810 | ␊ |
811 | ␉if (current != structHeader->handle)␊ |
812 | ␉{␊ |
813 | ␉␉idx++;␊ |
814 | ␉␉current = structHeader->handle;␊ |
815 | ␉}␊ |
816 | ␊ |
817 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
818 | ␊ |
819 | ␉if (value)␊ |
820 | ␉{␊ |
821 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
822 | ␉␉␉return true;␊ |
823 | ␉}␊ |
824 | ␉else␊ |
825 | ␉{␊ |
826 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
827 | ␉␉␉return true;␊ |
828 | ␉}␊ |
829 | ␉␊ |
830 | ␉return false;␊ |
831 | }␊ |
832 | ␊ |
833 | const char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
834 | {␊ |
835 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
836 | ␊ |
837 | ␉if (!field)␊ |
838 | {␊ |
839 | ␉␉//return (char *)0;␊ |
840 | return NULL;␊ |
841 | }␊ |
842 | ␊ |
843 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
844 | field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
845 | ␊ |
846 | ␉return (char *)stringPtr;␊ |
847 | }␊ |
848 | ␊ |
849 | static void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
850 | {␊ |
851 | ␉int strSize;␊ |
852 | ␊ |
853 | ␉if (!field)␊ |
854 | {␊ |
855 | ␊ |
856 | ␉␉return;␊ |
857 | }␊ |
858 | ␉if (!string)␊ |
859 | ␉{␊ |
860 | ␉␉*field = 0;␊ |
861 | ␉␉return;␊ |
862 | ␉}␊ |
863 | ␉␊ |
864 | ␉strSize = strlen(string);␊ |
865 | ␉␊ |
866 | ␉// remove any spaces found at the end␊ |
867 | while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
868 | ␉␉strSize--;␊ |
869 | ␉␊ |
870 | ␊ |
871 | ␉if (strSize == 0)␊ |
872 | ␉{␊ |
873 | ␉␉*field = 0;␊ |
874 | ␉␉return;␊ |
875 | ␉}␊ |
876 | ␉␊ |
877 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
878 | ␊ |
879 | ␉*field = stringIndex;␊ |
880 | ␉␊ |
881 | ␉stringIndex++;␊ |
882 | ␉stringsSize += strSize + 1;␊ |
883 | }␊ |
884 | ␊ |
885 | static bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
886 | {␊ |
887 | ␉const char *string = 0;␊ |
888 | ␉int len;␊ |
889 | ␉bool parsed;␊ |
890 | ␉int val;␊ |
891 | ␊ |
892 | ␉if (numOfSetters <= idx)␊ |
893 | ␉␉return false;␊ |
894 | ␉␊ |
895 | ␉switch (SMBSetters[idx].valueType)␊ |
896 | ␉{␊ |
897 | ␉␉case kSMBString:␊ |
898 | {␊ |
899 | bool randomSerial = false; ␊ |
900 | getBoolForKey(kSMBIOSRandomSerial, &randomSerial, &bootInfo->bootConfig);␊ |
901 | ␊ |
902 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
903 | ␉␉␉{␊ |
904 | if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue) && randomSerial && (!strcmp ("SMserial", SMBSetters[idx].keyString)))␊ |
905 | {␊ |
906 | string = *(SMBSetters[idx].defaultValue);␊ |
907 | break;␊ |
908 | }␊ |
909 | else if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
910 | ␉␉␉␉␉break;␊ |
911 | ␉␉␉␉else␊ |
912 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
913 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
914 | ␉␉␉␉␉␉␉break;␊ |
915 | ␉␉␉}␊ |
916 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
917 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
918 | ␉␉␉␉␉break;␊ |
919 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
920 | ␉␉␉{␊ |
921 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
922 | ␉␉␉␉break;␊ |
923 | ␉␉␉}␊ |
924 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
925 | ␉␉␉break;␊ |
926 | ␉␉}␉␊ |
927 | ␉␉case kSMBByte:␊ |
928 | ␉␉case kSMBWord:␊ |
929 | ␉␉case kSMBDWord:␊ |
930 | ␉␉␉//case kSMBQWord:␊ |
931 | ␉␉␉/*if (SMBSetters[idx].keyString)␊ |
932 | {␊ |
933 | if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
934 | return true;␊ |
935 | else␊ |
936 | if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
937 | if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
938 | return true;␊ |
939 | }*/␊ |
940 | if (SMBSetters[idx].keyString)␊ |
941 | ␉␉␉{␊ |
942 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
943 | ␉␉␉␉if (!parsed)␊ |
944 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
945 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
946 | ␉␉␉␉if (parsed)␊ |
947 | ␉␉␉␉{␊ |
948 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
949 | ␉␉␉␉␉{␊ |
950 | ␉␉␉␉␉␉case kSMBByte:␊ |
951 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
952 | ␉␉␉␉␉␉␉break;␊ |
953 | ␉␉␉␉␉␉case kSMBWord:␊ |
954 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
955 | ␉␉␉␉␉␉␉break;␊ |
956 | ␉␉␉␉␉␉case kSMBDWord:␊ |
957 | ␉␉␉␉␉␉default:␊ |
958 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
959 | ␉␉␉␉␉␉␉break;␊ |
960 | ␉␉␉␉␉}␊ |
961 | ␉␉␉␉␉return true;␊ |
962 | ␉␉␉␉}␊ |
963 | }␊ |
964 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
965 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
966 | ␉␉␉␉␉return true;␊ |
967 | #if 0␊ |
968 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
969 | ␉␉␉{␊ |
970 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
971 | ␉␉␉␉return true;␊ |
972 | ␉␉␉}␊ |
973 | #endif␊ |
974 | ␉␉␉break;␊ |
975 | ␉}␊ |
976 | ␉␊ |
977 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
978 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
979 | ␊ |
980 | ␉return true;␊ |
981 | }␊ |
982 | //-------------------------------------------------------------------------------------------------------------------------␊ |
983 | // Apple Specific␊ |
984 | //-------------------------------------------------------------------------------------------------------------------------␊ |
985 | static void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
986 | {␊ |
987 | ␉return;␊ |
988 | }␊ |
989 | ␊ |
990 | static void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
991 | {␊ |
992 | ␉/* SPD data from Platform->RAM.spd */␊ |
993 | ␉return;␊ |
994 | }␊ |
995 | ␊ |
996 | static void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
997 | {␊ |
998 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
999 | ␉␊ |
1000 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
1001 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
1002 | ␉p->header.handle␉= handle++;␊ |
1003 | ␊ |
1004 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
1005 | ␊ |
1006 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
1007 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
1008 | ␉structureCount++;␊ |
1009 | }␊ |
1010 | ␊ |
1011 | static void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
1012 | {␊ |
1013 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
1014 | ␊ |
1015 | ␉switch (Platform->CPU.Family) ␊ |
1016 | ␉{␊ |
1017 | ␉␉case 0x06:␊ |
1018 | ␉␉{␊ |
1019 | ␉␉␉switch (Platform->CPU.Model)␊ |
1020 | ␉␉␉{␊ |
1021 | ␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz␊ |
1022 | ␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
1023 | ␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
1024 | ␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
1025 | ␉␉␉␉case CPUID_MODEL_NEHALEM:␉␉// Intel Core i7 LGA1366 (45nm)␊ |
1026 | ␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
1027 | ␉␉␉␉case CPUID_MODEL_WESTMERE:␉// Intel Core i7 LGA1366 (32nm) 6 Core␊ |
1028 | ␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
1029 | ␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
1030 | ␉␉␉␉case CPUID_MODEL_JAKETOWN: ␊ |
1031 | ␉␉␉␉␉break;␊ |
1032 | ␉␉␉␉␉␊ |
1033 | ␉␉␉␉default:␊ |
1034 | ␉␉␉␉␉return;␊ |
1035 | ␉␉␉}␊ |
1036 | ␉␉}␊ |
1037 | ␉}␊ |
1038 | ␉␊ |
1039 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
1040 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
1041 | ␉p->header.handle␉= handle++;␊ |
1042 | ␊ |
1043 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
1044 | ␊ |
1045 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
1046 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
1047 | ␉structureCount++;␊ |
1048 | }␊ |
1049 | ␊ |
1050 | //-------------------------------------------------------------------------------------------------------------------------␊ |
1051 | // EndOfTable␊ |
1052 | //-------------------------------------------------------------------------------------------------------------------------␊ |
1053 | static void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
1054 | {␊ |
1055 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
1056 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
1057 | ␉structPtr->new->handle␉= handle++;␊ |
1058 | ␊ |
1059 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
1060 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
1061 | ␉structureCount++;␊ |
1062 | }␊ |
1063 | ␊ |
1064 | static void setSMBStruct(SMBStructPtrs *structPtr)␊ |
1065 | {␊ |
1066 | ␉bool setterFound = false;␊ |
1067 | ␊ |
1068 | ␉uint8_t *ptr;␊ |
1069 | ␉SMBWord structSize;␊ |
1070 | ␉int i;␊ |
1071 | ␊ |
1072 | ␉stringIndex = 1;␊ |
1073 | ␉stringsSize = 0;␊ |
1074 | ␊ |
1075 | ␉if (handle < structPtr->orig->handle)␊ |
1076 | ␉␉handle = structPtr->orig->handle;␊ |
1077 | ␊ |
1078 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
1079 | ␊ |
1080 | ␉for (i = 0; i < numOfSetters; i++)␊ |
1081 | /*if (structPtr->orig->type == SMBSetters[i].type)␊ |
1082 | {␊ |
1083 | if (SMBSetters[i].fieldOffset > structPtr->orig->length)␊ |
1084 | continue;*/␊ |
1085 | if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
1086 | {␊ |
1087 | ␉␉␉setterFound = true;␊ |
1088 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
1089 | ␉␉}␊ |
1090 | ␊ |
1091 | ␉if (setterFound)␊ |
1092 | ␉{␊ |
1093 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
1094 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1095 | ␊ |
1096 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1097 | ␉␉␉ptr += 2;␊ |
1098 | ␊ |
1099 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
1100 | ␉}␊ |
1101 | ␉else␊ |
1102 | ␉{␊ |
1103 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
1104 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1105 | ␊ |
1106 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1107 | ␉␉␉ptr += 2;␊ |
1108 | ␉␉␊ |
1109 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
1110 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
1111 | ␉}␊ |
1112 | ␊ |
1113 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
1114 | ␊ |
1115 | ␉tableLength += structSize;␊ |
1116 | ␊ |
1117 | ␉if (structSize > maxStructSize)␊ |
1118 | ␉␉maxStructSize = structSize;␊ |
1119 | ␊ |
1120 | ␉structureCount++;␊ |
1121 | ␊ |
1122 | }␊ |
1123 | ␊ |
1124 | static void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
1125 | {␊ |
1126 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
1127 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
1128 | ␊ |
1129 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
1130 | ␉{␊ |
1131 | ␉␉switch (structPtr->orig->type)␊ |
1132 | ␉␉{␊ |
1133 | /* Skip all Apple Specific Structures */␊ |
1134 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
1135 | ␉␉␉case kSMBTypeMemorySPD:␊ |
1136 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
1137 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
1138 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
1139 | ␉␉␉case kSMBTypeEndOfTable:␊ |
1140 | ␉␉␉␉break;␊ |
1141 | ␊ |
1142 | ␉␉␉default:␊ |
1143 | {␊ |
1144 | ␉␉␉␉/* Add */␊ |
1145 | ␉␉␉␉setSMBStruct(structPtr);␊ |
1146 | ␉␉␉␉break;␊ |
1147 | }␊ |
1148 | ␉␉}␊ |
1149 | ␊ |
1150 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
1151 | ␊ |
1152 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1153 | ␊ |
1154 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1155 | ␉␉␉ptr += 2;␊ |
1156 | ␊ |
1157 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
1158 | ␉}␊ |
1159 | ␊ |
1160 | ␊ |
1161 | ␉addSMBFirmwareVolume(structPtr);␊ |
1162 | ␊ |
1163 | ␉addSMBMemorySPD(structPtr);␊ |
1164 | ␊ |
1165 | ␉addSMBOemProcessorType(structPtr);␊ |
1166 | ␊ |
1167 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
1168 | ␊ |
1169 | ␉addSMBEndOfTable(structPtr);␊ |
1170 | ␊ |
1171 | ␊ |
1172 | }␊ |
1173 | ␊ |
1174 | SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps)␊ |
1175 | {␊ |
1176 | ␉SMBStructPtrs *structPtr;␊ |
1177 | ␉uint8_t *buffer;␊ |
1178 | ␉bool setSMB = true;␊ |
1179 | ␊ |
1180 | ␉if (!origeps)␊ |
1181 | ␉␉return NULL;␊ |
1182 | ␊ |
1183 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
1184 | ␉if (!structPtr)␊ |
1185 | ␉␉return NULL;␊ |
1186 | ␉␊ |
1187 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
1188 | ␉if (!buffer)␊ |
1189 | ␉␉return NULL;␊ |
1190 | ␉␊ |
1191 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
1192 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
1193 | ␊ |
1194 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);␊ |
1195 | ␉if (setSMB)␊ |
1196 | ␉␉setDefaultSMBData();␊ |
1197 | ␊ |
1198 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
1199 | ␉␊ |
1200 | ␉SMBEntryPoint *neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
1201 | ␉if (!neweps)␊ |
1202 | ␉␉return NULL;␊ |
1203 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
1204 | ␊ |
1205 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
1206 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
1207 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
1208 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
1209 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
1210 | ␉neweps->majorVersion␉␉= 2;␊ |
1211 | ␉neweps->minorVersion␉␉= 4;␊ |
1212 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
1213 | ␉neweps->entryPointRevision␉= 0;␊ |
1214 | ␊ |
1215 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
1216 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
1217 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
1218 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
1219 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
1220 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
1221 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
1222 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
1223 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
1224 | ␊ |
1225 | ␉if (!neweps->dmi.tableAddress)␊ |
1226 | ␉␉return NULL;␊ |
1227 | ␊ |
1228 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
1229 | ␊ |
1230 | ␉neweps->dmi.checksum␉␉= 0;␊ |
1231 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
1232 | ␊ |
1233 | ␉neweps->checksum␉␉␉= 0;␊ |
1234 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
1235 | ␊ |
1236 | ␉//free(buffer);␊ |
1237 | ␉decodeSMBIOSTable(neweps);␊ |
1238 | ␊ |
1239 | return neweps;␊ |
1240 | }␊ |
1241 | ␊ |
1242 | /* Collect any information needed later */␊ |
1243 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
1244 | {␊ |
1245 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
1246 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
1247 | ␊ |
1248 | ␉int dimmnbr = 0;␊ |
1249 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
1250 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
1251 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
1252 | ␊ |
1253 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
1254 | ␉{␊ |
1255 | ␉␉switch (structHeader->type)␊ |
1256 | ␉␉{␊ |
1257 | ␉␉␉case kSMBTypeSystemInformation:␊ |
1258 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
1259 | ␉␉␉␉break;␊ |
1260 | ␊ |
1261 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
1262 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
1263 | ␉␉␉␉break;␊ |
1264 | ␊ |
1265 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
1266 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
1267 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
1268 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
1269 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
1270 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
1271 | ␉␉␉␉dimmnbr++;␊ |
1272 | ␉␉␉␉break;␊ |
1273 | ␉␉␉default:␊ |
1274 | ␉␉␉␉break;␊ |
1275 | ␉␉}␊ |
1276 | ␊ |
1277 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
1278 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
1279 | ␊ |
1280 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
1281 | ␉␉␉structPtr += 2;␊ |
1282 | ␊ |
1283 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
1284 | ␉}␊ |
1285 | }␊ |
1286 | ␊ |
1287 | |