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 | ␊ |
539 | rand_sn1 = arc4random_unirange(0,35);␊ |
540 | rand_sn2 = arc4random_unirange(0,35);␊ |
541 | rand_sn3 = arc4random_unirange(0,35);␊ |
542 | ␊ |
543 | // Append all charaters to the string ␊ |
544 | char tmp[2];␊ |
545 | bzero(tmp,sizeof(tmp));␊ |
546 | snprintf(tmp, sizeof(tmp),"%c",sn_gen_pn_str[rand_sn1]);␊ |
547 | strlcpy (str, tmp, sizeof(str));␊ |
548 | ␊ |
549 | snprintf(tmp, sizeof(tmp),"%c",sn_gen_pn_str[rand_sn2]);␊ |
550 | strcat (str, tmp);␊ |
551 | ␊ |
552 | snprintf(tmp, sizeof(tmp),"%c",sn_gen_pn_str[rand_sn3]);␊ |
553 | strcat (str, tmp);␊ |
554 | ␊ |
555 | DBG ("fake_productNumber: %s\n",str);␊ |
556 | ␊ |
557 | }␊ |
558 | return str;␊ |
559 | }␊ |
560 | ␊ |
561 | const char* sm_get_random_week(void)␊ |
562 | {␊ |
563 | static char str[4] = {0x00,0x00,0x00,0x00};␊ |
564 | if(str[0] == 0)␊ |
565 | { ␊ |
566 | // Get randomized characters␊ |
567 | int rand_week ;␊ |
568 | rand_week = arc4random_unirange(0,47);␊ |
569 | ␊ |
570 | // Append all charaters to the string ␊ |
571 | char tmp[3];␊ |
572 | bzero(tmp,sizeof(tmp));␊ |
573 | ␊ |
574 | if (rand_week < 10) {␊ |
575 | snprintf(tmp, sizeof(tmp),"0%d",rand_week);␊ |
576 | strlcpy (str, tmp, sizeof(str));␊ |
577 | } else if (rand_week < 100) { // avoid overflow in case random return a number >= 100␊ |
578 | snprintf(tmp, sizeof(tmp),"%d",rand_week);␊ |
579 | strlcpy (str, tmp, sizeof(str));␊ |
580 | } ␊ |
581 | ␊ |
582 | DBG ("fake_week: %s\n",str);␊ |
583 | ␊ |
584 | }␊ |
585 | return str;␊ |
586 | }␊ |
587 | ␊ |
588 | const char* sm_get_random_year(void)␊ |
589 | {␊ |
590 | static char str[2] = {0x00,0x00};␊ |
591 | if(str[0] == 0)␊ |
592 | { ␊ |
593 | // Get randomized characters␊ |
594 | int rand_year ;␊ |
595 | ␊ |
596 | rand_year = arc4random_unirange(0,9);␊ |
597 | ␉␉␊ |
598 | // Append all charaters to the string ␊ |
599 | char tmp[2];␊ |
600 | bzero(tmp,sizeof(tmp));␊ |
601 | ␊ |
602 | if (rand_year < 10) {␊ |
603 | snprintf(tmp, sizeof(tmp),"%d",rand_year);␊ |
604 | strlcpy (str, tmp, sizeof(str));␊ |
605 | }␊ |
606 | ␊ |
607 | DBG ("fake_year: %s\n",str);␊ |
608 | ␊ |
609 | }␊ |
610 | return str;␊ |
611 | }␊ |
612 | ␊ |
613 | const char* sm_get_random_country(void)␊ |
614 | {␊ |
615 | static char str[3] = {0x00,0x00,0x00};␊ |
616 | if(str[0] == 0)␊ |
617 | { ␊ |
618 | ␊ |
619 | // Get randomized characters␊ |
620 | int rand_country ;␊ |
621 | ␊ |
622 | rand_country = arc4random_unirange(0,(sizeof(sm_country_list) / sizeof(sm_country_list[0]))-1);␊ |
623 | ␉␉␊ |
624 | strlcpy (str, sm_country_list[rand_country].code,strlen(sm_country_list[rand_country].code)+1);␊ |
625 | ␊ |
626 | DBG ("fake_country: %s (%s)\n",str,sm_country_list[rand_country].info);␊ |
627 | ␊ |
628 | }␊ |
629 | return str;␊ |
630 | }␊ |
631 | ␊ |
632 | static void setDefaultSMBData(void)␊ |
633 | {␊ |
634 | ␉static bool setDefSMB = true;␊ |
635 | ␉␊ |
636 | ␉if (setDefSMB) {␉␉␊ |
637 | ␉␉␊ |
638 | const SMStrEntryPair*␉sm_defaults;␊ |
639 | const SMStrEntryPair*␉sm_chosen;␊ |
640 | ␊ |
641 | if (get_env(envIsServer))␊ |
642 | {␊ |
643 | sm_defaults=sm_xserve_defaults;␊ |
644 | } else if (get_env(envIsMobile)) {␊ |
645 | if (get_env(envNoCores) > 1) {␊ |
646 | sm_defaults=sm_macbookpro_defaults;␊ |
647 | } else {␊ |
648 | sm_defaults=sm_macbook_defaults;␊ |
649 | }␊ |
650 | } else {␊ |
651 | switch (get_env(envNoCores)) ␊ |
652 | {␊ |
653 | case 1: ␊ |
654 | sm_defaults=sm_macmini_defaults; ␊ |
655 | break;␊ |
656 | case 2:␊ |
657 | sm_defaults=sm_imac_defaults;␊ |
658 | break;␊ |
659 | default:␊ |
660 | {␊ |
661 | switch (get_env(envFamily)) ␊ |
662 | {␊ |
663 | case 0x06:␊ |
664 | {␊ |
665 | switch (get_env(envModel))␊ |
666 | {␊ |
667 | case CPUID_MODEL_FIELDS: // Intel Core i5, i7 LGA1156 (45nm)␊ |
668 | case CPUID_MODEL_DALES: // Intel Core i5, i7 LGA1156 (45nm) ???␊ |
669 | case CPUID_MODEL_DALES_32NM: // Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
670 | case 0x19: // Intel Core i5 650 @3.20 Ghz ␊ |
671 | sm_defaults=sm_imac_core_defaults; ␊ |
672 | break;␊ |
673 | ␊ |
674 | case CPUID_MODEL_SANDYBRIDGE:␊ |
675 | case CPUID_MODEL_JAKETOWN:␊ |
676 | sm_defaults=sm_imac_sandy_defaults;␊ |
677 | break;␊ |
678 | ␊ |
679 | case CPUID_MODEL_NEHALEM: ␊ |
680 | case CPUID_MODEL_NEHALEM_EX:␊ |
681 | sm_defaults=sm_macpro_core_defaults; ␊ |
682 | break;␊ |
683 | ␊ |
684 | case CPUID_MODEL_WESTMERE: ␊ |
685 | case CPUID_MODEL_WESTMERE_EX:␊ |
686 | sm_defaults=sm_macpro_westmere_defaults; ␊ |
687 | break;␊ |
688 | ␊ |
689 | default:␊ |
690 | sm_defaults=sm_macpro_defaults; ␊ |
691 | break;␊ |
692 | }␊ |
693 | break;␊ |
694 | }␊ |
695 | default:␊ |
696 | sm_defaults=sm_macpro_defaults; ␊ |
697 | break;␊ |
698 | }␊ |
699 | break;␊ |
700 | }␊ |
701 | }␊ |
702 | }␊ |
703 | ␊ |
704 | {␊ |
705 | const char␉*str;␊ |
706 | int␉␉size;␊ |
707 | ␊ |
708 | if (getValueForKey("SMproductname", &str, &size, DEFAULT_SMBIOS_CONFIG))␊ |
709 | { ␊ |
710 | if (strstr (str, "MacPro5"))␊ |
711 | {␊ |
712 | sm_chosen = sm_macpro_westmere_defaults ;␊ |
713 | }␊ |
714 | else if (strstr (str, "MacPro4"))␊ |
715 | {␊ |
716 | sm_chosen = sm_macpro_core_defaults ;␊ |
717 | }␊ |
718 | else if (strstr (str, "MacPro"))␊ |
719 | {␊ |
720 | sm_chosen = sm_macpro_defaults ;␊ |
721 | }␊ |
722 | else if (strstr (str,"MacBookPro"))␊ |
723 | {␊ |
724 | sm_chosen = sm_macbookpro_defaults ;␊ |
725 | }␊ |
726 | else if (strstr (str, "MacBook"))␊ |
727 | {␊ |
728 | sm_chosen = sm_macbook_defaults ;␊ |
729 | }␊ |
730 | else if (!strcmp ("iMac12,1", str))␊ |
731 | {␊ |
732 | sm_chosen = sm_imac_sandy_defaults ;␊ |
733 | }␊ |
734 | else if (!strcmp ("iMac11,1", str))␊ |
735 | {␊ |
736 | sm_chosen = sm_imac_core_defaults ;␊ |
737 | }␊ |
738 | else if (strstr (str, "iMac"))␊ |
739 | {␊ |
740 | sm_chosen = sm_imac_defaults ;␊ |
741 | }␊ |
742 | else if (strstr (str, "Macmini"))␊ |
743 | {␊ |
744 | sm_chosen = sm_macmini_defaults ;␊ |
745 | }␊ |
746 | else if (strstr (str, "Xserve"))␊ |
747 | {␊ |
748 | sm_chosen = sm_xserve_defaults ;␊ |
749 | }␊ |
750 | else ␊ |
751 | {␊ |
752 | sm_chosen = sm_defaults ;␊ |
753 | } ␊ |
754 | } ␊ |
755 | else ␊ |
756 | sm_chosen = sm_defaults; ␊ |
757 | } ␊ |
758 | ␊ |
759 | bzero (fake_serial,sizeof(fake_serial)); ␊ |
760 | ␊ |
761 | bool randomSerial = false;␊ |
762 | getBoolForKey(kSMBIOSRandomSerial, &randomSerial, DEFAULT_BOOT_CONFIG) ;␊ |
763 | ␊ |
764 | if ( randomSerial ) // useless␊ |
765 | strlcpy (fake_serial,sm_get_random_country(), strlen(sm_get_random_country())+1);␊ |
766 | else␊ |
767 | strlcpy (fake_serial,sm_search_str(sm_chosen, "SMserialProductCountry"), strlen(sm_search_str(sm_chosen, "SMserialProductCountry"))+1);␊ |
768 | ␊ |
769 | if ( randomSerial ) // useless␊ |
770 | strcat (fake_serial,sm_get_random_year());␊ |
771 | else␊ |
772 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialYear"));␊ |
773 | ␊ |
774 | if ( randomSerial ) // useless␊ |
775 | strcat (fake_serial,sm_get_random_week());␊ |
776 | else␊ |
777 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialWeek")); ␊ |
778 | ␊ |
779 | if ( randomSerial )␊ |
780 | strcat (fake_serial,sm_get_random_productNumber());␊ |
781 | else␊ |
782 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialProductNumber"));␊ |
783 | ␊ |
784 | strcat (fake_serial,sm_search_str(sm_chosen, "SMserialModel"));␊ |
785 | ␊ |
786 | if ( randomSerial )␊ |
787 | msglog ("fake_serial: %s\n",fake_serial); ␊ |
788 | ␊ |
789 | defaultBIOSInfo.version␉␉␉= sm_search_str(sm_chosen, "SMbiosversion");␊ |
790 | defaultBIOSInfo.releaseDate␉␉= sm_search_str(sm_chosen, "SMbiosdate"); ␊ |
791 | defaultBIOSInfo.vendor␉␉␉= sm_search_str(sm_chosen, "SMbiosvendor");␊ |
792 | ␉␉␊ |
793 | defaultSystemInfo.productName␉= sm_search_str(sm_chosen, "SMproductname");␊ |
794 | defaultSystemInfo.family␉␉= sm_search_str(sm_chosen, "SMfamily");␊ |
795 | defaultSystemInfo.manufacturer␉= sm_search_str(sm_chosen, "SMboardmanufacter");␊ |
796 | defaultSystemInfo.version␉␉= sm_search_str(sm_chosen, "SMsystemversion");␊ |
797 | defaultSystemInfo.serialNumber␉= fake_serial;␊ |
798 | ␉␉␊ |
799 | defaultBaseBoard.manufacturer␉= sm_search_str(sm_chosen, "SMboardmanufacter");␊ |
800 | defaultBaseBoard.product␉␉= sm_search_str(sm_chosen, "SMboardproduct");␊ |
801 | ␊ |
802 | ␉␉setDefSMB = false;␊ |
803 | ␉}␉␊ |
804 | }␊ |
805 | ␊ |
806 | /* Used for SM*_N smbios.plist keys */␊ |
807 | static bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
808 | {␊ |
809 | ␉static int idx = -1;␊ |
810 | ␉static int current = -1;␊ |
811 | ␉int len;␊ |
812 | ␉char key[24];␊ |
813 | ␊ |
814 | ␉if (current != structHeader->handle)␊ |
815 | ␉{␊ |
816 | ␉␉idx++;␊ |
817 | ␉␉current = structHeader->handle;␊ |
818 | ␉}␊ |
819 | ␊ |
820 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
821 | ␊ |
822 | ␉if (value)␊ |
823 | ␉{␊ |
824 | ␉␉if (getIntForKey(key, (int *)&(value->dword), DEFAULT_SMBIOS_CONFIG))␊ |
825 | ␉␉␉return true;␊ |
826 | ␉}␊ |
827 | ␉else␊ |
828 | ␉{␊ |
829 | ␉␉if (getValueForKey(key, string, &len, DEFAULT_SMBIOS_CONFIG))␊ |
830 | ␉␉␉return true;␊ |
831 | ␉}␊ |
832 | ␉␊ |
833 | ␉return false;␊ |
834 | }␊ |
835 | ␊ |
836 | const char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
837 | {␊ |
838 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
839 | ␊ |
840 | ␉if (!field)␊ |
841 | {␊ |
842 | ␉␉//return (char *)0;␊ |
843 | return NULL;␊ |
844 | }␊ |
845 | ␊ |
846 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
847 | field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
848 | ␊ |
849 | ␉return (char *)stringPtr;␊ |
850 | }␊ |
851 | ␊ |
852 | static void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
853 | {␊ |
854 | ␉int strSize;␊ |
855 | ␊ |
856 | ␉if (!field)␊ |
857 | {␊ |
858 | ␊ |
859 | ␉␉return;␊ |
860 | }␊ |
861 | ␉if (!string)␊ |
862 | ␉{␊ |
863 | ␉␉*field = 0;␊ |
864 | ␉␉return;␊ |
865 | ␉}␊ |
866 | ␉␊ |
867 | ␉strSize = strlen(string);␊ |
868 | ␉␊ |
869 | ␉// remove any spaces found at the end␊ |
870 | while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
871 | ␉␉strSize--;␊ |
872 | ␉␊ |
873 | ␊ |
874 | ␉if (strSize == 0)␊ |
875 | ␉{␊ |
876 | ␉␉*field = 0;␊ |
877 | ␉␉return;␊ |
878 | ␉}␊ |
879 | ␉␊ |
880 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
881 | ␊ |
882 | ␉*field = stringIndex;␊ |
883 | ␉␊ |
884 | ␉stringIndex++;␊ |
885 | ␉stringsSize += strSize + 1;␊ |
886 | }␊ |
887 | ␊ |
888 | static bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
889 | {␊ |
890 | ␉const char *string = 0;␊ |
891 | ␉int len;␊ |
892 | ␉bool parsed;␊ |
893 | ␉int val;␊ |
894 | ␊ |
895 | ␉if (numOfSetters <= idx)␊ |
896 | ␉␉return false;␊ |
897 | ␉␊ |
898 | ␉switch (SMBSetters[idx].valueType)␊ |
899 | ␉{␊ |
900 | ␉␉case kSMBString:␊ |
901 | {␊ |
902 | bool randomSerial = false; ␊ |
903 | getBoolForKey(kSMBIOSRandomSerial, &randomSerial, DEFAULT_BOOT_CONFIG);␊ |
904 | ␊ |
905 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
906 | ␉␉␉{␊ |
907 | if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue) && randomSerial && (!strcmp ("SMserial", SMBSetters[idx].keyString)))␊ |
908 | {␊ |
909 | string = *(SMBSetters[idx].defaultValue);␊ |
910 | break;␊ |
911 | }␊ |
912 | else if (getValueForKey(SMBSetters[idx].keyString, &string, &len, DEFAULT_SMBIOS_CONFIG))␊ |
913 | ␉␉␉␉␉break;␊ |
914 | ␉␉␉␉else␊ |
915 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
916 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
917 | ␉␉␉␉␉␉␉break;␊ |
918 | ␉␉␉}␊ |
919 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
920 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
921 | ␉␉␉␉␉break;␊ |
922 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
923 | ␉␉␉{␊ |
924 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
925 | ␉␉␉␉break;␊ |
926 | ␉␉␉}␊ |
927 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
928 | ␉␉␉break;␊ |
929 | ␉␉}␉␊ |
930 | ␉␉case kSMBByte:␊ |
931 | ␉␉case kSMBWord:␊ |
932 | ␉␉case kSMBDWord:␊ |
933 | ␉␉␉//case kSMBQWord:␊ |
934 | ␉␉␉/*if (SMBSetters[idx].keyString)␊ |
935 | {␊ |
936 | if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), DEFAULT_SMBIOS_CONFIG))␊ |
937 | return true;␊ |
938 | else␊ |
939 | if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
940 | if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
941 | return true;␊ |
942 | }*/␊ |
943 | if (SMBSetters[idx].keyString)␊ |
944 | ␉␉␉{␊ |
945 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, DEFAULT_SMBIOS_CONFIG);␊ |
946 | ␉␉␉␉if (!parsed)␊ |
947 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
948 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
949 | ␉␉␉␉if (parsed)␊ |
950 | ␉␉␉␉{␊ |
951 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
952 | ␉␉␉␉␉{␊ |
953 | ␉␉␉␉␉␉case kSMBByte:␊ |
954 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
955 | ␉␉␉␉␉␉␉break;␊ |
956 | ␉␉␉␉␉␉case kSMBWord:␊ |
957 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
958 | ␉␉␉␉␉␉␉break;␊ |
959 | ␉␉␉␉␉␉case kSMBDWord:␊ |
960 | ␉␉␉␉␉␉default:␊ |
961 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
962 | ␉␉␉␉␉␉␉break;␊ |
963 | ␉␉␉␉␉}␊ |
964 | ␉␉␉␉␉return true;␊ |
965 | ␉␉␉␉}␊ |
966 | }␊ |
967 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
968 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
969 | ␉␉␉␉␉return true;␊ |
970 | #if 0␊ |
971 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
972 | ␉␉␉{␊ |
973 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
974 | ␉␉␉␉return true;␊ |
975 | ␉␉␉}␊ |
976 | #endif␊ |
977 | ␉␉␉break;␊ |
978 | ␉}␊ |
979 | ␉␊ |
980 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
981 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
982 | ␊ |
983 | ␉return true;␊ |
984 | }␊ |
985 | //-------------------------------------------------------------------------------------------------------------------------␊ |
986 | // Apple Specific␊ |
987 | //-------------------------------------------------------------------------------------------------------------------------␊ |
988 | static void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
989 | {␊ |
990 | ␉return;␊ |
991 | }␊ |
992 | ␊ |
993 | static void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
994 | {␊ |
995 | ␉/* SPD data from Platform->RAM.spd */␊ |
996 | ␉return;␊ |
997 | }␊ |
998 | ␊ |
999 | static void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
1000 | {␊ |
1001 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
1002 | ␉␊ |
1003 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
1004 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
1005 | ␉p->header.handle␉= handle++;␊ |
1006 | ␊ |
1007 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
1008 | ␊ |
1009 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
1010 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
1011 | ␉structureCount++;␊ |
1012 | }␊ |
1013 | ␊ |
1014 | static void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
1015 | {␊ |
1016 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
1017 | ␊ |
1018 | ␉switch (get_env(envFamily)) ␊ |
1019 | ␉{␊ |
1020 | ␉␉case 0x06:␊ |
1021 | ␉␉{␊ |
1022 | ␉␉␉switch (get_env(envModel))␊ |
1023 | ␉␉␉{␊ |
1024 | ␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz␊ |
1025 | ␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
1026 | ␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
1027 | ␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
1028 | ␉␉␉␉case CPUID_MODEL_NEHALEM:␉␉// Intel Core i7 LGA1366 (45nm)␊ |
1029 | ␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
1030 | ␉␉␉␉case CPUID_MODEL_WESTMERE:␉// Intel Core i7 LGA1366 (32nm) 6 Core␊ |
1031 | ␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
1032 | ␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
1033 | ␉␉␉␉case CPUID_MODEL_JAKETOWN: ␊ |
1034 | ␉␉␉␉␉break;␊ |
1035 | ␉␉␉␉␉␊ |
1036 | ␉␉␉␉default:␊ |
1037 | ␉␉␉␉␉return;␊ |
1038 | ␉␉␉}␊ |
1039 | ␉␉}␊ |
1040 | ␉}␊ |
1041 | ␉␊ |
1042 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
1043 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
1044 | ␉p->header.handle␉= handle++;␊ |
1045 | ␊ |
1046 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
1047 | ␊ |
1048 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
1049 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
1050 | ␉structureCount++;␊ |
1051 | }␊ |
1052 | ␊ |
1053 | //-------------------------------------------------------------------------------------------------------------------------␊ |
1054 | // EndOfTable␊ |
1055 | //-------------------------------------------------------------------------------------------------------------------------␊ |
1056 | static void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
1057 | {␊ |
1058 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
1059 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
1060 | ␉structPtr->new->handle␉= handle++;␊ |
1061 | ␊ |
1062 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
1063 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
1064 | ␉structureCount++;␊ |
1065 | }␊ |
1066 | ␊ |
1067 | static void setSMBStruct(SMBStructPtrs *structPtr)␊ |
1068 | {␊ |
1069 | ␉bool setterFound = false;␊ |
1070 | ␊ |
1071 | ␉uint8_t *ptr;␊ |
1072 | ␉SMBWord structSize;␊ |
1073 | ␉int i;␊ |
1074 | ␊ |
1075 | ␉stringIndex = 1;␊ |
1076 | ␉stringsSize = 0;␊ |
1077 | ␊ |
1078 | ␉if (handle < structPtr->orig->handle)␊ |
1079 | ␉␉handle = structPtr->orig->handle;␊ |
1080 | ␊ |
1081 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
1082 | ␊ |
1083 | ␉for (i = 0; i < numOfSetters; i++)␊ |
1084 | /*if (structPtr->orig->type == SMBSetters[i].type)␊ |
1085 | {␊ |
1086 | if (SMBSetters[i].fieldOffset > structPtr->orig->length)␊ |
1087 | continue;*/␊ |
1088 | if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
1089 | {␊ |
1090 | ␉␉␉setterFound = true;␊ |
1091 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
1092 | ␉␉}␊ |
1093 | ␊ |
1094 | ␉if (setterFound)␊ |
1095 | ␉{␊ |
1096 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
1097 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1098 | ␊ |
1099 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1100 | ␉␉␉ptr += 2;␊ |
1101 | ␊ |
1102 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
1103 | ␉}␊ |
1104 | ␉else␊ |
1105 | ␉{␊ |
1106 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
1107 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1108 | ␊ |
1109 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1110 | ␉␉␉ptr += 2;␊ |
1111 | ␉␉␊ |
1112 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
1113 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
1114 | ␉}␊ |
1115 | ␊ |
1116 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
1117 | ␊ |
1118 | ␉tableLength += structSize;␊ |
1119 | ␊ |
1120 | ␉if (structSize > maxStructSize)␊ |
1121 | ␉␉maxStructSize = structSize;␊ |
1122 | ␊ |
1123 | ␉structureCount++;␊ |
1124 | ␊ |
1125 | }␊ |
1126 | ␊ |
1127 | static void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
1128 | {␊ |
1129 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
1130 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
1131 | ␊ |
1132 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
1133 | ␉{␊ |
1134 | ␉␉switch (structPtr->orig->type)␊ |
1135 | ␉␉{␊ |
1136 | /* Skip all Apple Specific Structures */␊ |
1137 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
1138 | ␉␉␉case kSMBTypeMemorySPD:␊ |
1139 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
1140 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
1141 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
1142 | ␉␉␉case kSMBTypeEndOfTable:␊ |
1143 | ␉␉␉␉break;␊ |
1144 | ␊ |
1145 | ␉␉␉default:␊ |
1146 | {␊ |
1147 | ␉␉␉␉/* Add */␊ |
1148 | ␉␉␉␉setSMBStruct(structPtr);␊ |
1149 | ␉␉␉␉break;␊ |
1150 | }␊ |
1151 | ␉␉}␊ |
1152 | ␊ |
1153 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
1154 | ␊ |
1155 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
1156 | ␊ |
1157 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
1158 | ␉␉␉ptr += 2;␊ |
1159 | ␊ |
1160 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
1161 | ␉}␊ |
1162 | ␊ |
1163 | ␊ |
1164 | ␉addSMBFirmwareVolume(structPtr);␊ |
1165 | ␊ |
1166 | ␉addSMBMemorySPD(structPtr);␊ |
1167 | ␊ |
1168 | ␉addSMBOemProcessorType(structPtr);␊ |
1169 | ␊ |
1170 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
1171 | ␊ |
1172 | ␉addSMBEndOfTable(structPtr);␊ |
1173 | ␊ |
1174 | ␊ |
1175 | }␊ |
1176 | ␊ |
1177 | SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps)␊ |
1178 | {␊ |
1179 | ␉SMBStructPtrs *structPtr;␊ |
1180 | ␉uint8_t *buffer;␊ |
1181 | ␉bool setSMB = true;␊ |
1182 | ␊ |
1183 | ␉if (!origeps)␊ |
1184 | ␉␉return NULL;␊ |
1185 | ␊ |
1186 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
1187 | ␉if (!structPtr)␊ |
1188 | ␉␉return NULL;␊ |
1189 | ␉␊ |
1190 | ␉buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);␊ |
1191 | ␉if (!buffer)␊ |
1192 | {␊ |
1193 | free(structPtr);␊ |
1194 | ␉␉return NULL;␊ |
1195 | }␊ |
1196 | ␉␊ |
1197 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
1198 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
1199 | ␊ |
1200 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, DEFAULT_BOOT_CONFIG);␊ |
1201 | ␉if (setSMB)␊ |
1202 | ␉␉setDefaultSMBData();␊ |
1203 | ␊ |
1204 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
1205 | ␉␊ |
1206 | ␉SMBEntryPoint *neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
1207 | ␉if (!neweps)␊ |
1208 | {␊ |
1209 | free(buffer);␊ |
1210 | free(structPtr);␊ |
1211 | ␉␉return NULL;␊ |
1212 | }␊ |
1213 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
1214 | ␊ |
1215 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
1216 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
1217 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
1218 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
1219 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
1220 | ␉neweps->majorVersion␉␉= 2;␊ |
1221 | ␉neweps->minorVersion␉␉= 4;␊ |
1222 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
1223 | ␉neweps->entryPointRevision␉= 0;␊ |
1224 | ␊ |
1225 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
1226 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
1227 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
1228 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
1229 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
1230 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
1231 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
1232 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
1233 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
1234 | ␊ |
1235 | ␉if (!neweps->dmi.tableAddress)␊ |
1236 | {␊ |
1237 | free(buffer);␊ |
1238 | free(structPtr);␊ |
1239 | ␉␉return NULL;␊ |
1240 | } ␊ |
1241 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
1242 | ␊ |
1243 | ␉neweps->dmi.checksum␉␉= 0;␊ |
1244 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
1245 | ␊ |
1246 | ␉neweps->checksum␉␉␉= 0;␊ |
1247 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
1248 | ␊ |
1249 | ␉free(buffer);␊ |
1250 | free(structPtr);␊ |
1251 | ␊ |
1252 | ␉decodeSMBIOSTable(neweps);␊ |
1253 | ␊ |
1254 | return neweps;␊ |
1255 | }␊ |
1256 | ␊ |
1257 | /* Collect any information needed later */␊ |
1258 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
1259 | {␊ |
1260 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
1261 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
1262 | ␊ |
1263 | ␉int dimmnbr = 0;␊ |
1264 | int␉␉␉MaxMemorySlots = 0;␉␉// number of memory slots polulated by SMBIOS␊ |
1265 | int␉␉␉CntMemorySlots = 0;␉␉// number of memory slots counted␊ |
1266 | int␉␉␉MemoryModules = 0;␊ |
1267 | ␊ |
1268 | ␊ |
1269 | static RamSlotInfo_t RamDimm[MAX_RAM_SLOTS];␊ |
1270 | ␊ |
1271 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
1272 | ␉{␊ |
1273 | ␉␉switch (structHeader->type)␊ |
1274 | ␉␉{␊ |
1275 | ␉␉␉case kSMBTypeSystemInformation:␊ |
1276 | safe_set_env(envUUID,(uint32_t)((SMBSystemInformation *)structHeader)->uuid);␊ |
1277 | ␉␉␉␉break;␊ |
1278 | ␊ |
1279 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
1280 | ␉␉␉␉MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
1281 | ␉␉␉␉break;␊ |
1282 | ␊ |
1283 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
1284 | ␉␉␉␉CntMemorySlots++;␊ |
1285 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
1286 | ␉␉␉␉␉MemoryModules++;␊ |
1287 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
1288 | ␊ |
1289 | ␉␉␉␉␉RamDimm[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
1290 | ␉␉␉␉dimmnbr++;␊ |
1291 | ␉␉␉␉break;␊ |
1292 | ␉␉␉default:␊ |
1293 | ␉␉␉␉break;␊ |
1294 | ␉␉}␊ |
1295 | ␊ |
1296 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
1297 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
1298 | ␊ |
1299 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
1300 | ␉␉␉structPtr += 2;␊ |
1301 | ␊ |
1302 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
1303 | ␉}␊ |
1304 | safe_set_env(envDMIMaxMemorySlots, MaxMemorySlots);␊ |
1305 | safe_set_env(envDMICntMemorySlots, CntMemorySlots);␊ |
1306 | safe_set_env(envDMIMemModules, MemoryModules);␊ |
1307 | safe_set_env_copy(envRamDimm, RamDimm, sizeof(RamDimm));␊ |
1308 | ␊ |
1309 | ␊ |
1310 | }␊ |
1311 | ␊ |
1312 | |