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