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