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