Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsaio/smbios.c

1/*
2 * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project
3 *
4 * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.
5 *
6 */
7
8
9#include "boot.h"
10#include "bootstruct.h"
11#include "smbios_getters.h"
12// Bungo
13#include "convert.h"
14
15#ifndef DEBUG_SMBIOS
16#define DEBUG_SMBIOS 0
17#endif
18
19#if DEBUG_SMBIOS
20#define DBG(x...)printf(x)
21#else
22#define DBG(x...)msglog(x)
23#endif
24
25#define SMBPlist&bootInfo->smbiosConfig
26/* ASSUMPTION: 16KB should be enough for the whole thing */
27#define SMB_ALLOC_SIZE16384
28
29
30//-------------------------------------------------------------------------------------------------------------------------
31// SMBIOS Plist Keys
32//-------------------------------------------------------------------------------------------------------------------------
33
34/* =======================
35 BIOS Information (Type 0)
36 ========================= */
37#define kSMBBIOSInformationVendorKey "SMbiosvendor" // Apple Inc.
38#define kSMBBIOSInformationVersionKey "SMbiosversion" // MP31.88Z.006C.B05.0802291410
39#define kSMBBIOSInformationReleaseDateKey "SMbiosdate" // 02/29/08
40// Bungo
41#define kSMBBIOSInformationReleaseKey "SMbiosrelease" // BIOS Revision
42// example: BIOS Revision: 1.23 --> 2 bytes: Major=0x01, Minor=0x17 --> after swap: 0x1701hex = 5889dec (SMBIOS_spec_DSP0134_2.7.1)
43
44/* =========================
45 System Information (Type 1)
46 =========================== */
47#define kSMBSystemInformationManufacturerKey "SMmanufacturer" // Apple Inc.
48#define kSMBSystemInformationProductNameKey "SMproductname" // MacPro3,1
49#define kSMBSystemInformationVersionKey "SMsystemversion" // 1.0
50#define kSMBSystemInformationSerialNumberKey "SMserial" // Serial number
51//Bungo
52#define kSMBSystemInformationUUIDKey "SMsystemuuid" // ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'
53#define kSMBSystemInformationSKUNumberKey "SMskunumber" // System SKU#
54
55#define kSMBSystemInformationFamilyKey "SMfamily" // MacPro
56
57/* =========================================
58 Base Board (or Module) Information (Type 2)
59 =========================================== */
60#define kSMBBaseBoardManufacturerKey "SMboardmanufacturer" // Apple Inc.
61#define kSMBBaseBoardProductKey "SMboardproduct" // Mac-F2268DC8
62// Bungo
63#define kSMBBaseBoardVersionKey "SMboardversion" // MacPro3,1
64#define kSMBBaseBoardSerialNumberKey "SMboardserial" // C02140302D5DMT31M
65#define kSMBBaseBoardAssetTagKey "SMboardassettag" // Base Board Asset Tag# Bungo: renamed folowing convention
66#define kSMBBaseBoardLocationInChassisKey "SMboardlocation" // Part Component
67
68// ErmaC BoardType 0x0a(10) or 0x0b(11) MacPro Family
69#define kSMBBaseBoardTypeKey "SMboardtype" // 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
70
71// Bungo
72/* =======================
73 System Enclosure (Type 3)
74 ========================= */
75#define kSMBSystemEnclosureManufacturerKey "SMchassismanufacturer" // Apple Inc.
76#define kSMBSystemEnclosureTypeKey "SMchassistype" // 7 Desktop
77#define kSMBSystemEnclosureVersionKey "SMchassisversion" // Mac-F42C88C8
78#define kSMBSystemEnclosureSerialNumberKey "SMchassisserial" // Serial number
79#define kSMBSystemEnclosureAssetTagKey "SMchassisassettag" // Pro-Enclosure Bungo: renamed folowing convention
80
81/* ============================
82 Processor Information (Type 4)
83 ============================== */
84// Bungo:
85#define kSMBProcessorInformationSocketKey "SMcpusocket"
86#define kSMBProcessorInformationManufacturerKey "SMcpumanufacturer"
87#define kSMBProcessorInformationVersionKey "SMcpuversion"
88//
89#define kSMBProcessorInformationExternalClockKey"SMexternalclock"
90#define kSMBProcessorInformationMaximalClockKey"SMmaximalclock"
91// Bungo:
92#define kSMBProcessorInformationCurrentClockKey "SMcurrentclock"
93#define kSMBProcessorInformationUpgradeKey "SMcpuupgrade"
94#define kSMBProcessorInformationSerialNumberKey "SMcpuserial"
95#define kSMBProcessorInformationAssetTagKey "SMcpuassettag" // Bungo: renamed folowing convention
96#define kSMBProcessorInformationPartNumberKey "SMcpupartnumber"
97
98/* =====================
99 Memory Device (Type 17)
100 ======================= */
101#define kSMBMemoryDeviceDeviceLocatorKey "SMmemdevloc" //
102#define kSMBMemoryDeviceBankLocatorKey "SMmembankloc" //
103#define kSMBMemoryDeviceMemoryTypeKey "SMmemtype" //
104#define kSMBMemoryDeviceMemorySpeedKey "SMmemspeed" //
105#define kSMBMemoryDeviceManufacturerKey "SMmemmanufacturer" //
106#define kSMBMemoryDeviceSerialNumberKey "SMmemserial" //
107#define kSMBMemoryDevicePartNumberKey "SMmempart" //
108// Bungo:
109#define kSMBMemoryDeviceAssetTagKey "SMmemassettag" //
110
111/* ===========================================
112 Memory SPD Data (Apple Specific - Type 130)
113 ============================================= */
114
115/* ============================================
116 OEM Processor Type (Apple Specific - Type 131)
117 ============================================== */
118#define kSMBOemProcessorTypeKey "SMoemcputype" // Bungo: renamed from SMcputype
119
120/* =================================================
121 OEM Processor Bus Speed (Apple Specific - Type 132)
122 =================================================== */
123#define kSMBOemProcessorBusSpeedKey "SMoemcpubusspeed" // Bungo: renamed from SMbusspeed
124
125/* ==============================================
126 OEM Platform Feature (Apple Specific - Type 133)
127 ================================================ */
128//#define kSMBOemPlatformFeatureKey
129
130/* ==================================================*/
131#define getFieldOffset(struct, field)((uint8_t)(uint32_t)&(((struct *)0)->field))
132
133typedef struct
134{
135SMBStructHeader *orig;
136SMBStructHeader *new;
137} SMBStructPtrs;
138
139/* =======================
140 BIOS Information (Type 0)
141 ========================= */
142typedef struct
143{
144char *vendor;
145char *version;
146char *releaseDate;
147uint16_t release; // Bungo
148} defaultBIOSInfo_t;
149
150defaultBIOSInfo_t defaultBIOSInfo;
151
152/* =========================
153 System Information (Type 1)
154 =========================== */
155typedef struct
156{
157char *manufacturer;
158char *productName;
159char *version;
160char *serialNumber;
161char *skuNumber;// ErmaC
162char *family;
163} defaultSystemInfo_t;
164
165defaultSystemInfo_t defaultSystemInfo;
166
167/* =========================================
168 Base Board (or Module) Information (Type 2)
169 =========================================== */
170typedef struct
171{
172char *manufacturer;
173char *product;
174char *version;// Bungo
175char *serialNumber;// ErmaC
176char *assetTag;// ErmaC Bungo: renamed folowing convention
177char *locationInChassis;// ErmaC
178uint8_t boardType;// ErmaC
179} defaultBaseBoard_t;
180
181defaultBaseBoard_t defaultBaseBoard;
182
183// Bungo
184typedef struct {
185char*manufacturer;
186uint8_tchassisType;
187char*version;
188char*serialNumber;
189char*assetTag; // Bungo: renamed folowing convention
190char*skuNumber;
191} defaultChassis_t;
192
193defaultChassis_t defaultChassis;
194
195typedef struct
196{
197uint8_ttype;
198SMBValueTypevalueType;
199uint8_tfieldOffset;
200char*keyString;
201bool(*getSMBValue)(returnType *);
202char**defaultValue;
203} SMBValueSetter;
204
205SMBValueSetter SMBSetters[] =
206{
207/* =======================
208 BIOS Information (Type 0)
209 ========================= */
210{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, vendor),
211kSMBBIOSInformationVendorKey, NULL, &defaultBIOSInfo.vendor }, // SMbiosvendor - Apple Inc.
212
213{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, version),
214kSMBBIOSInformationVersionKey, NULL, &defaultBIOSInfo.version }, // SMbiosversion - MP31.88Z.006C.B05.0802291410
215
216{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, releaseDate),
217kSMBBIOSInformationReleaseDateKey, NULL, &defaultBIOSInfo.releaseDate }, // SMbiosdate - 02/29/08
218
219// Bungo
220{ kSMBTypeBIOSInformation, kSMBWord, getFieldOffset(SMBBIOSInformation, releaseMajor),
221kSMBBIOSInformationReleaseKey, NULL,(char **)&defaultBIOSInfo.release }, // SMbiosrelease - 0.1 (256)
222
223/* =========================
224 System Information (Type 1)
225 =========================== */
226{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, manufacturer),
227kSMBSystemInformationManufacturerKey, NULL,&defaultSystemInfo.manufacturer}, // SMmanufacturer - Apple Inc.
228
229{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, productName),
230kSMBSystemInformationProductNameKey, NULL, &defaultSystemInfo.productName }, // SMproductname - MacPro3,1
231
232{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, version),
233kSMBSystemInformationVersionKey, NULL, &defaultSystemInfo.version }, // SMsystemversion - 1.0
234
235{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, serialNumber),
236kSMBSystemInformationSerialNumberKey, NULL, &defaultSystemInfo.serialNumber }, // SMserial - Serial number
237/* Bungo:
238{kSMBTypeSystemInformation,kSMBByte,getFieldOffset(SMBSystemInformation, uuid),
239kSMBSystemInformationUUIDKey, NULL, NULL}, // SMsystemuuid
240
241{kSMBTypeSystemInformation,kSMBByte,getFieldOffset(SMBSystemInformation, wakeupReason),
242NULL, NULL, NULL}, // reason for system wakeup
243*/
244
245// Bungo
246{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, skuNumber),
247kSMBSystemInformationSKUNumberKey, NULL, &defaultSystemInfo.skuNumber}, // SMskunumber - System SKU#
248
249{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, family),
250kSMBSystemInformationFamilyKey,NULL,&defaultSystemInfo.family}, // SMfamily - MacPro
251
252
253/* =========================================
254 Base Board (or Module) Information (Type 2)
255 =========================================== */
256{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, manufacturer),
257kSMBBaseBoardManufacturerKey, NULL, &defaultBaseBoard.manufacturer }, // SMboardmanufacturer - Apple Inc.
258
259{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, product),
260kSMBBaseBoardProductKey, NULL, &defaultBaseBoard.product }, // SMboardproduct - Mac-F2268DC8
261
262// Bungo
263{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, version),
264kSMBBaseBoardVersionKey, NULL, &defaultBaseBoard.version }, // SMboardversion - MacPro3,1
265
266{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, serialNumber),
267kSMBBaseBoardSerialNumberKey, NULL, &defaultBaseBoard.serialNumber }, // SMboardserial - C02140302D5DMT31M
268
269{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTag),
270kSMBBaseBoardAssetTagKey, NULL, &defaultBaseBoard.assetTag }, // SMboardassetag - Base Board Asset Tag#
271
272{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, locationInChassis),
273kSMBBaseBoardLocationInChassisKey, NULL, &defaultBaseBoard.locationInChassis }, // SMboardlocation - Part Component
274
275{kSMBTypeBaseBoard,kSMBByte,getFieldOffset(SMBBaseBoard, boardType),
276kSMBBaseBoardTypeKey,NULL, (char **)&defaultBaseBoard.boardType }, // SMboardtype - 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
277
278/*{kSMBTypeBaseBoard,kSMBByte, getFieldOffset(SMBBaseBoard, numberOfContainedHandles),
279NULL , NULL, NULL }, // numberOfContainedHandles = 0
280*/
281//
282
283// Bungo
284/* =======================
285 System Enclosure (Type 3)
286 ========================= */
287{kSMBTypeSystemEnclosure,kSMBString,getFieldOffset(SMBSystemEnclosure, manufacturer),
288kSMBSystemEnclosureManufacturerKey, NULL,&defaultChassis.manufacturer }, // SMchassismanufacturer - Apple Inc.
289
290{kSMBTypeSystemEnclosure, kSMBByte,getFieldOffset(SMBSystemEnclosure, chassisType),
291kSMBSystemEnclosureTypeKey, NULL, (char **)&defaultChassis.chassisType}, // SMchassistype - 7
292
293{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, version),
294kSMBSystemEnclosureVersionKey, NULL, &defaultChassis.version }, // SMchassisversion - Mac-F42C88C8
295
296{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, serialNumber),
297kSMBSystemEnclosureSerialNumberKey, NULL, &defaultChassis.serialNumber }, // SMchassisserial
298
299{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTag),
300kSMBSystemEnclosureAssetTagKey, NULL, &defaultChassis.assetTag }, // SMchassisassettag - Pro Enclosure
301
302/*
303{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, skuNumber),
304NULL, NULL, &defaultChassis.skuNumber },
305*/
306
307/* ============================
308 Processor Information (Type 4)
309 ============================== */
310{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, socketDesignation),
311kSMBProcessorInformationSocketKey, NULL, NULL}, // SMcpusocket -
312
313{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, manufacturer),
314kSMBProcessorInformationManufacturerKey, NULL, NULL}, // SMcpumanufacturer - Intel(R) Corporation
315
316{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, processorVersion),
317kSMBProcessorInformationVersionKey, NULL, NULL}, // SMcpuversion
318
319{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, externalClock),
320kSMBProcessorInformationExternalClockKey, getProcessorInformationExternalClock,NULL}, // SMcpuexternalclock
321
322{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, maximumClock),
323kSMBProcessorInformationMaximalClockKey, getProcessorInformationMaximumClock,NULL}, // SMcpumaximumclock
324// Bungo
325{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, currentClock),
326kSMBProcessorInformationCurrentClockKey, NULL, NULL}, // SMcpucurrentspeed
327
328{kSMBTypeProcessorInformation,kSMBByte,getFieldOffset(SMBProcessorInformation, processorUpgrade),
329kSMBProcessorInformationUpgradeKey, NULL, NULL}, // SMcpuupgrade
330//
331
332{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),
333kSMBProcessorInformationSerialNumberKey, NULL, NULL},
334
335// Bungo
336{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),
337kSMBProcessorInformationAssetTagKey, NULL, NULL}, // SMcpuassettag
338//
339
340{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),
341kSMBProcessorInformationPartNumberKey, NULL, NULL},
342
343/* =====================
344 Memory Device (Type 17)
345 ======================= */
346{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, deviceLocator),
347kSMBMemoryDeviceDeviceLocatorKey, NULL, NULL},
348
349{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, bankLocator),
350kSMBMemoryDeviceBankLocatorKey, NULL, NULL},
351
352{kSMBTypeMemoryDevice,kSMBByte,getFieldOffset(SMBMemoryDevice, memoryType),
353kSMBMemoryDeviceMemoryTypeKey, getSMBMemoryDeviceMemoryType,NULL},
354
355{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, memorySpeed),
356kSMBMemoryDeviceMemorySpeedKey, getSMBMemoryDeviceMemorySpeed,NULL},
357
358{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, manufacturer),
359kSMBMemoryDeviceManufacturerKey, getSMBMemoryDeviceManufacturer, NULL},
360
361{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, serialNumber),
362kSMBMemoryDeviceSerialNumberKey, getSMBMemoryDeviceSerialNumber, NULL},
363
364{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, assetTag),
365kSMBMemoryDeviceAssetTagKey, NULL, NULL},
366
367{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, errorHandle),
368NULL, getSMBMemoryDeviceMemoryErrorHandle, NULL},
369
370{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),
371kSMBMemoryDevicePartNumberKey, getSMBMemoryDevicePartNumber, NULL},
372
373//-------------------------------------------------------------------------------------------------------------------------
374// Apple Specific
375//-------------------------------------------------------------------------------------------------------------------------
376// OEM Processor Type (Apple Specific - Type 131)
377{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
378getSMBOemProcessorType,NULL},
379
380// OEM Processor Bus Speed (Apple Specific - Type 132)
381{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
382getSMBOemProcessorBusSpeed,NULL}
383
384// OEM Platform Feature (Apple Specific - Type 133)
385/*
386{kSMBTypeOemPlatformFeature,kSMBWord,getFieldOffset(SMBOemPlatformFeature, PlatformFeature),kSMBOemPlatformFeatureKey,
387getSMBOemPlatformFeature,NULL}
388*/
389};
390
391int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
392
393
394SMBEntryPoint *origeps= 0;
395SMBEntryPoint *neweps= 0;
396
397static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
398static uint8_t stringsSize;// add string size
399
400static SMBWord tableLength= 0;
401static SMBWord handle= 0;
402static SMBWord maxStructSize= 0;
403static SMBWord structureCount= 0;
404
405//-------------------------------------------------------------------------------------------------------------------------
406// Default SMBIOS Data
407//-------------------------------------------------------------------------------------------------------------------------
408/* Rewrite: use a struct */
409
410// Bungo: suggest to not mixing data from different Mac models, use real Mac SMBIOS dumps
411
412#define kDefaultVendorManufacturer"Apple Inc."
413//#define kDefaultBIOSReleaseDate"11/06/2009"
414#define kDefaultSerialNumber"SOMESRLNMBR"
415//Bungo
416#define kDefaultSkuNumber"Default SKU#"
417#define kDefaultAssetTag"Default Asset Tag#"
418//#define kDefaultBoardType"10" // 0xA
419//#define kDefaultBoardProcessorType"11" // 0xB
420#define kDefaultSystemVersion"1.0"
421#define kDefaultBIOSRelease256 // 256 = 0x0100 -> swap bytes: 0x0001 -> Release: 0.1 (see SMBIOS spec. table Type 0)
422//#define kDefaultLocatioInChassis"Part Component"
423//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
424
425//=========== Mac mini ===========
426#define kDefaultMacMiniFamily"Mac mini"
427//#define kDefaultMacMiniBoardAssetTagNumber"Mini-Aluminum"
428
429#define kDefaultMacMini"Macmini2,1"
430#define kDefaultMacMiniBIOSVersion" MM21.88Z.009A.B00.0706281359"
431#define kDefaultMacMiniBIOSReleaseDate"06/28/07"
432#define kDefaultMacMiniBoardProduct"Mac-F4208EAA"
433
434// MacMini5,1 Mac-8ED6AF5B48C039E1 - MM51.88Z.0077.B0F.1110201309
435// MacMini5,2 Mac-4BC72D62AD45599E
436// MacMini5,3
437//#define kDefaultMacMini"Macmini5,3"
438//#define kDefaultMacMiniBIOSVersion" MM51.88Z.0077.B10.1201241549"
439//#define kDefaultMacMiniBoardProduct"Mac-F65AE981FFA204ED"
440//#define kDefaultMacMiniBIOSReleaseDate"01/24/2012"
441
442// MacMini 6,1 - Mac-F65AE981FFA204ED
443// MacMini 6,2
444//#define kDefaultMacMini62"Macmini6,2"
445//#define kDefaultMacMini62BIOSVersion" MM61.88Z.0106.B00.1208091121"
446//#define kDefaultMacMini62BoardProduct"Mac-F65AE981FFA204ED"
447//#define kDefaultMacMini62BIOSReleaseDate"10/14/2012"
448
449//=========== MacBook ===========
450#define kDefaultMacBookFamily"MacBook"
451//#define kDefaultMacBookBoardAssetTagNumber"MacBook-Black"
452
453#define kDefaultMacBook"MacBook4,1"
454#define kDefaultMacBookBIOSVersion" MB41.88Z.00C1.B00.0802091535"
455#define kDefaultMacBookBIOSReleaseDate"02/09/08"
456#define kDefaultMacBookBoardProduct"Mac-F22788A9"
457
458//=========== MacBookAir ===========
459#define kDefaultMacBookAirFamily"MacBook Air"
460
461// MacBookAir4,1 - Mac-C08A6BB70A942AC2
462// MacBookAir4,2 - Mac-742912EFDBEE19B3
463#define kDefaultMacBookAir"MacBookAir5,2"
464#define kDefaultMacBookAirBIOSVersion" MBA51.88Z.00EF.B00.1205221442"
465#define kDefaultMacBookAirBIOSReleaseDate"05/10/12"
466#define kDefaultMacBookBoardAirProduct"Mac-2E6FAB96566FE58C"
467
468// MacBookAir6,1 - Mac-35C1E88140C3E6CF - MBA61.88Z.0099.B04.1309271229
469// MacBookAir6,2 - Mac-7DF21CB3ED6977E5 - MBA62.88Z.00EF.B00.1205221442
470
471//=========== MacBookPro ===========
472#define kDefaultMacBookProFamily"MacBook Pro"
473//#define kDefaultMacBookProBoardAssetTagNumber"MacBook-Aluminum"
474
475#define kDefaultMacBookPro"MacBookPro4,1"
476#define kDefaultMacBookProBIOSVersion" MBP41.88Z.00C1.B03.0802271651"
477#define kDefaultMacBookProBIOSReleaseDate"02/27/08"
478#define kDefaultMacBookProBoardProduct"Mac-F42C89C8"
479
480//#define kDefaultMacBookPro"MacBookPro8,1"
481//#define kDefaultMacBookProBIOSVersion" MBP81.88Z.0047.B24.1110141131"
482//#define kDefaultMacBookProBoardProduct"Mac-94245B3640C91C81"
483//#define kDefaultMacBookProBIOSReleaseDate"10/14/11"
484
485// MacBookPro8,2 - Mac_94245A3940C91C80
486// MacBookPro8,3 - Mac-942459F5819B171B
487
488// MacBookPro10,2
489//#define kDefaultMacBookProIvy"MacBookPro10,2"
490//#define kDefaultMacBookProIvyBIOSVersion" MBP102.88Z.0106.B01.1208311637"
491//#define kDefaultMacBookProIvyBoardProduct"Mac-AFD8A9D944EA4843"
492//#define kDefaultMacBookProIvyBIOSReleaseDate"10/02/2012"
493
494// MacBookPro11,2 - Mac-3CBD00234E554E41 - MBP112.88Z.0138.B03.1310291227
495// MacBookPro11,3 - Mac-2BD1B31983FE1663 - MBP112.88Z.0138.B02.1310181745
496
497//=========== iMac ===========
498#define kDefaultiMacFamily"iMac"
499//#define kDefaultiMacBoardAssetTagNumber"iMac-Aluminum"
500
501#define kDefaultiMac"iMac8,1"
502#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
503#define kDefaultiMacBIOSReleaseDate"02/09/08"
504#define kDefaultiMacBoardProduct"Mac-F227BEC8"
505
506// iMac10,1
507// iMac11,1 core i3/i5/i7
508#define kDefaultiMacNehalem"iMac11,1"
509#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B02.1003171314"
510#define kDefaultiMacNehalemBIOSReleaseDate"03/30/10"
511#define kDefaultiMacNehalemBoardProduct"Mac-F2268DAE"
512// iMac11,2
513// iMac11,3
514
515// iMac12,1
516#define kDefaultiMacSandy"iMac12,1"
517#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B00.1102091756"
518#define kDefaultiMacSandyBIOSReleaseDate"01/02/08"
519#define kDefaultiMacSandyBoardProduct"Mac-942B5BF58194151B"
520// iMac12,2 Mac-942B59F58194171B
521//#define kDefaultiMacSandy"iMac12,2"
522//#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B1D.1110171110"
523//#define kDefaultiMacSandyBIOSReleaseDate"10/17/11"
524//#define kDefaultiMacSandyBoardProduct"Mac-942B59F58194171B"
525
526// iMac13,2
527//#define kDefaultiMacIvy"iMac13,2"
528//#define kDefaultiMacIvyBIOSVersion" IM131.88Z.00CE.B00.1203281326"
529//#define kDefaultiMacIvyBIOSReleaseDate"03/28/2012"
530//#define kDefaultiMacIvyBoardProduct"Mac-FC02E91DDD3FA6A4"
531
532//=========== MacPro ===========
533#define kDefaultMacProFamily"Mac Pro"
534//#define KDefauktMacProBoardAssetTagNumber"Pro-Enclosure"
535//#define kDefaultMacProBoardType"0xB" // 11
536
537#define kDefaultMacPro"MacPro3,1"
538#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
539#define kDefaultMacProBIOSReleaseDate"08/03/2010"
540//#define kDefaultMacProSystemVersion"1.3"
541#define kDefaultMacProBoardProduct"Mac-F42C88C8"
542//#define KDefaultMacProBoardSerialNumber"J593902RA4MFE"
543
544// Mac Pro 4,1 core i7/Xeon
545#define kDefaultMacProNehalem"MacPro4,1"
546#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B07.0910130729"
547#define kDefaultMacProNehalemBIOSReleaseDate"10/13/09"
548//#define kDefaultMacProNehalemSystemVersion"1.4"
549#define kDefaultMacProNehalemBoardProduct"Mac-F221BEC8"
550//#define KDefaultMacProNehalemBoardSerialNumber"J593004RB1LUE"
551
552// Mac Pro 5,1 core i7/Xeon
553#define kDefaultMacProWestmere"MacPro5,1"
554#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B03.1010071432"
555#define kDefaultMacProWestmereBIOSReleaseDate"10/07/10"
556//#define kDefaultMacProWestmereSystemVersion"1.2"
557#define kDefaultMacProWestmereBoardProduct"Mac-F221BEC8"
558//#define KDefaultMacProWestmereBoardSerialNumber"J522700H7BH8C"
559
560// Mac Pro 6,1
561#define kDefaultMacProHaswell"MacPro6,1"
562#define kDefaultMacProHaswellBIOSVersion" MP61.88Z.0116.B04.1312061508"
563#define kDefaultMacProHaswellBIOSReleaseDate"12/06/2013"
564//#define kDefaultMacProHaswellSystemVersion"1.?"
565#define kDefaultMacProHaswellBoardProduct"Mac-F60DEB81FF30ACF6"
566//#define KDefaultMacProHaswellBoardSerialNumber"?????????????"
567
568//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
569// J593902RA4MFE 3,1
570// J5031046RCZJA 5,1
571// J521101A5CZJC 3,1
572// J593004RB1LUE MacPro4,1
573// J513401PZBH8C 5,1
574// J590802LC4ACB 3,1
575// J594900AH1LUE 4,1
576// J512500HZBH8C 5,1
577// J522700H7BH8C MacPro5,1
578
579/* ============================================ */
580
581bool useSMBIOSdefaults = true; // Bungo
582
583SMBByte PlatformType= 3; // Bungo: same as Platfom.Type in platform.h
584
585/* Rewrite this function */
586void setDefaultSMBData(void) // Bungo: setting data from real Macs
587{
588defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
589defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
590
591defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
592defaultSystemInfo.version = kDefaultSystemVersion;
593defaultSystemInfo.serialNumber = kDefaultSerialNumber;
594defaultSystemInfo.skuNumber = kDefaultSkuNumber; // Bungo
595
596defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
597defaultBaseBoard.serialNumber = kDefaultSerialNumber;
598defaultBaseBoard.assetTag = kDefaultAssetTag;
599
600defaultChassis.manufacturer = kDefaultVendorManufacturer;
601defaultChassis.serialNumber = kDefaultSerialNumber;
602defaultChassis.assetTag = kDefaultAssetTag;
603defaultChassis.skuNumber = kDefaultSkuNumber;
604
605 // if (platformCPUFeature(CPU_FEATURE_MOBILE)) Bungo: doesn't recognise correctly
606if (PlatformType == 2) // this method works
607{
608if (Platform.CPU.NoCores > 1) {
609defaultSystemInfo.productName = kDefaultMacBookPro;
610defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
611defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
612defaultSystemInfo.family = kDefaultMacBookProFamily;
613defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
614defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
615defaultChassis.chassisType = kSMBchassisUnknown;
616} else {
617defaultSystemInfo.productName = kDefaultMacBook;
618defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
619defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
620defaultSystemInfo.family = kDefaultMacBookFamily;
621defaultBaseBoard.product = kDefaultMacBookBoardProduct;
622defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
623defaultChassis.chassisType = kSMBchassisUnknown;
624}
625} else {
626switch (Platform.CPU.NoCores)
627{
628case 1:
629defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
630defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
631defaultSystemInfo.productName = kDefaultMacMini;
632defaultSystemInfo.family = kDefaultMacMiniFamily;
633defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
634defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
635defaultChassis.chassisType = kSMBchassisLPDesktop;
636break;
637
638case 2:
639defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
640defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
641defaultSystemInfo.productName = kDefaultiMac;
642defaultSystemInfo.family = kDefaultiMacFamily;
643defaultBaseBoard.product = kDefaultiMacBoardProduct;
644defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
645defaultChassis.chassisType = kSMBchassisAllInOne;
646break;
647default:
648{
649switch (Platform.CPU.Family)
650{
651case 0x06:
652{
653switch (Platform.CPU.Model)
654{
655case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
656case CPU_MODEL_DALES:
657case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
658defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
659defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
660defaultSystemInfo.productName= kDefaultiMacNehalem;
661defaultSystemInfo.family= kDefaultiMacFamily;
662defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
663defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
664defaultChassis.chassisType = kSMBchassisAllInOne;
665break;
666
667case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
668case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
669case CPU_MODEL_IVYBRIDGE_XEON:
670defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
671defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
672defaultSystemInfo.productName= kDefaultiMacSandy;
673defaultSystemInfo.family = kDefaultiMacFamily;
674defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
675defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
676defaultChassis.chassisType = kSMBchassisAllInOne;
677break;
678
679case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
680case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
681defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
682defaultBIOSInfo.releaseDate= kDefaultMacProNehalemBIOSReleaseDate;
683defaultSystemInfo.productName= kDefaultMacProNehalem;
684defaultSystemInfo.family= kDefaultMacProFamily;
685defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
686defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
687defaultChassis.chassisType = kSMBchassisTower;
688break;
689
690case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
691case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
692case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
693defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
694defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
695defaultSystemInfo.productName= kDefaultMacProWestmere;
696defaultSystemInfo.family= kDefaultMacProFamily;
697defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
698defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
699defaultChassis.chassisType = kSMBchassisTower;
700break;
701
702default:
703defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
704defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
705defaultSystemInfo.productName= kDefaultMacPro;
706defaultSystemInfo.family= kDefaultMacProFamily;
707defaultBaseBoard.product = kDefaultMacProBoardProduct;
708defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
709defaultChassis.chassisType = kSMBchassisUnknown;
710break;
711}
712break;
713}
714default:
715defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
716defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
717defaultSystemInfo.productName= kDefaultMacPro;
718defaultSystemInfo.family= kDefaultMacProFamily;
719defaultBaseBoard.product = kDefaultMacProBoardProduct;
720defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
721defaultChassis.chassisType = kSMBchassisUnknown;
722break;
723}
724break;
725}
726}
727}
728}
729
730/* Used for SM*n smbios.plist keys */
731bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
732{
733static int idx = -1;
734static int current = -1;
735int len;
736char key[24];
737
738if (current != structHeader->handle) {
739idx++;
740current = structHeader->handle;
741}
742
743sprintf(key, "%s%d", keyString, idx);
744
745if (value) {
746if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
747return true;
748}
749} else {
750if (getValueForKey(key, string, &len, SMBPlist)) {
751return true;
752}
753}
754return false;
755}
756
757char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
758{
759uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
760
761if (!field) {
762return NULL;
763}
764
765for (field--; field != 0 && strlen((char *)stringPtr) > 0;
766field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
767
768return (char *)stringPtr;
769}
770
771void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
772{
773int strSize;
774
775if (!field) {
776return;
777}
778
779if (!string) {
780*field = 0;
781return;
782}
783
784strSize = strlen(string);
785
786// remove any spaces found at the end
787while ((strSize != 0) && (string[strSize - 1] == ' ')) {
788strSize--;
789}
790
791if (strSize == 0) {
792*field = 0;
793return;
794}
795
796memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
797*field = stringIndex;
798
799stringIndex++;
800stringsSize += strSize + 1;
801}
802
803bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
804{
805const char *string = 0;
806int len;
807bool parsed;
808int val;
809
810if (numOfSetters <= idx) {
811return false;
812}
813
814switch (SMBSetters[idx].valueType) {
815case kSMBString:
816{
817if (SMBSetters[idx].keyString)
818{
819if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
820{
821break;
822} else {
823if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
824{
825if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
826{
827break;
828}
829}
830}
831
832}
833if (SMBSetters[idx].getSMBValue) {
834if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
835break;
836}
837}
838// Bungo
839if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
840string = *(SMBSetters[idx].defaultValue);
841break;
842}
843string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
844break;
845}
846case kSMBByte:
847case kSMBWord:
848case kSMBDWord:
849//case kSMBQWord:
850if (SMBSetters[idx].keyString) {
851parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
852if (!parsed)
853{
854if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
855parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
856}
857}
858if (parsed) {
859switch (SMBSetters[idx].valueType) {
860case kSMBByte:
861value->byte = (uint8_t)val;
862break;
863case kSMBWord:
864value->word = (uint16_t)val;
865break;
866//case kSMBQWord:
867//value->qword = (uint64_t)val;
868//break;
869case kSMBDWord:
870default:
871value->dword = (uint32_t)val;
872break;
873}
874return true;
875}
876}
877
878if (SMBSetters[idx].getSMBValue) {
879if (SMBSetters[idx].getSMBValue(value)) {
880return true;
881}
882}
883// #if 0 Bungo: enables code below
884// Bungo
885if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
886// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
887switch (SMBSetters[idx].valueType) {
888case kSMBByte:
889value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
890break;
891case kSMBWord:
892value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
893break;
894//case kSMBQWord:
895//value->qword = *(uint32_t *)(SMBSetters[idx].defaultValue);
896//break;
897case kSMBDWord:
898default:
899value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
900break;
901}
902return true;
903}
904// #endif Bungo
905break;
906}
907
908// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
909if ((SMBSetters[idx].valueType == kSMBString) && string) {
910setSMBStringForField(structPtr->new, string, &value->byte);
911}
912return true;
913}
914
915//-------------------------------------------------------------------------------------------------------------------------
916// Apple Specific
917//-------------------------------------------------------------------------------------------------------------------------
918
919/* ===========================================
920 Firmware Volume (Apple Specific - Type 128)
921 ============================================= */
922void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
923{
924return;
925}
926
927/* ===========================================
928 Memory SPD Data (Apple Specific - Type 130)
929 ============================================= */
930void addSMBMemorySPD(SMBStructPtrs *structPtr)
931{
932/* SPD data from Platform.RAM.spd */
933return;
934}
935
936/* ============================================
937 OEM Processor Type (Apple Specific - Type 131)
938 ============================================== */
939void addSMBOemProcessorType(SMBStructPtrs *structPtr)
940{
941SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
942
943p->header.type= kSMBTypeOemProcessorType;
944p->header.length= sizeof(SMBOemProcessorType);
945p->header.handle= handle++;
946
947setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
948
949structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
950tableLength += sizeof(SMBOemProcessorType) + 2;
951structureCount++;
952}
953
954/* =================================================
955 OEM Processor Bus Speed (Apple Specific - Type 132)
956 =================================================== */
957void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
958{
959SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
960
961switch (Platform.CPU.Family)
962{
963case 0x06:
964{
965switch (Platform.CPU.Model)
966{
967case 0x19:// Intel Core i5 650 @3.20 Ghz
968case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
969case CPU_MODEL_DALES:
970case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
971case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
972case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
973case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
974case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
975case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
976case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
977case CPU_MODEL_IVYBRIDGE_XEON:
978case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
979case CPU_MODEL_HASWELL:
980case CPU_MODEL_HASWELL_SVR:
981case CPU_MODEL_HASWELL_ULT:
982case CPU_MODEL_CRYSTALWELL:
983
984break;
985
986default:
987return;
988}
989}
990}
991
992p->header.type= kSMBTypeOemProcessorBusSpeed;
993p->header.length= sizeof(SMBOemProcessorBusSpeed);
994p->header.handle= handle++;
995
996setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
997
998structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
999tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
1000structureCount++;
1001}
1002
1003/* ==============================================
1004 OEM Platform Feature (Apple Specific - Type 133)
1005 ================================================ */
1006 /*void addSMBOemPlatformFeature(SMBStructPtrs *structPtr) { }*/
1007
1008//-------------------------------------------------------------------------------------------------------------------------
1009// EndOfTable
1010//-------------------------------------------------------------------------------------------------------------------------
1011void addSMBEndOfTable(SMBStructPtrs *structPtr)
1012{
1013structPtr->new->type= kSMBTypeEndOfTable;
1014structPtr->new->length= sizeof(SMBStructHeader);
1015structPtr->new->handle= handle++;
1016
1017structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1018tableLength += sizeof(SMBStructHeader) + 2;
1019structureCount++;
1020}
1021
1022void setSMBStruct(SMBStructPtrs *structPtr)
1023{
1024bool setterFound = false;
1025
1026uint8_t *ptr;
1027SMBWord structSize;
1028int i;
1029
1030/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
1031bool forceFullMemInfo = false;
1032
1033if (structPtr->orig->type == kSMBTypeMemoryDevice) {
1034getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1035if (forceFullMemInfo) {
1036structPtr->orig->length = 27;
1037}
1038}
1039
1040stringIndex = 1;
1041stringsSize = 0;
1042
1043if (handle < structPtr->orig->handle) {
1044handle = structPtr->orig->handle;
1045}
1046// Bungo: fix unsuported tables lengths from original smbios: extend smaller or truncate bigger
1047switch (structPtr->orig->type) {
1048case kSMBTypeBIOSInformation:
1049structSize = sizeof(SMBBIOSInformation);
1050break;
1051case kSMBTypeSystemInformation:
1052structSize = sizeof(SMBSystemInformation);
1053break;
1054case kSMBTypeBaseBoard:
1055structSize = sizeof(SMBBaseBoard);
1056break;
1057case kSMBTypeSystemEnclosure:
1058structSize = sizeof(SMBSystemEnclosure);
1059break;
1060case kSMBTypeProcessorInformation:
1061structSize = sizeof(SMBProcessorInformation);
1062break;
1063case kSMBTypeMemoryDevice:
1064structSize = sizeof(SMBMemoryDevice);
1065break;
1066default:
1067structSize = structPtr->orig->length; // don't change if not to patch
1068break;
1069}
1070
1071// memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1072if (structPtr->orig->length <= structSize) {
1073memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1074} else {
1075memcpy((void *)structPtr->new, structPtr->orig, structSize);
1076}
1077
1078structPtr->new->length = structSize;
1079
1080for (i = 0; i < numOfSetters; i++) {
1081// Bungo:
1082if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structSize)) {
1083setterFound = true;
1084setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1085}
1086}
1087
1088if (setterFound) {
1089// Bungo:
1090ptr = (uint8_t *)structPtr->new + structPtr->new->length;
1091for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1092
1093if (((uint16_t *)ptr)[0] == 0) {
1094ptr += 2;
1095}
1096structSize = ptr - (uint8_t *)structPtr->new;
1097} else {
1098ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1099for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1100
1101if (((uint16_t *)ptr)[0] == 0) {
1102ptr += 2;
1103}
1104
1105structSize = ptr - (uint8_t *)structPtr->orig;
1106memcpy((void *)structPtr->new, structPtr->orig, structSize);
1107}
1108
1109structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1110
1111tableLength += structSize;
1112
1113if (structSize > maxStructSize) {
1114maxStructSize = structSize;
1115}
1116
1117structureCount++;
1118}
1119
1120void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1121{
1122uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1123structPtr->orig = (SMBStructHeader *)ptr;
1124
1125for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1126switch (structPtr->orig->type) {
1127/* Skip all Apple Specific Structures */
1128case kSMBTypeFirmwareVolume:
1129case kSMBTypeMemorySPD:
1130case kSMBTypeOemProcessorType:
1131case kSMBTypeOemProcessorBusSpeed:
1132/* And this one too, to be added at the end */
1133case kSMBTypeEndOfTable:
1134break;
1135
1136default:
1137{
1138/* Add */
1139setSMBStruct(structPtr);
1140break;
1141}
1142}
1143
1144ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1145for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1146
1147if (((uint16_t *)ptr)[0] == 0) {
1148ptr += 2;
1149}
1150
1151structPtr->orig = (SMBStructHeader *)ptr;
1152}
1153
1154addSMBFirmwareVolume(structPtr);
1155addSMBMemorySPD(structPtr);
1156addSMBOemProcessorType(structPtr);
1157addSMBOemProcessorBusSpeed(structPtr);
1158
1159addSMBEndOfTable(structPtr);
1160}
1161
1162// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only
1163uint8_t *FixSystemUUID()
1164{
1165uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1166SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1167int i, isZero, isOnes;
1168uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
1169const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
1170uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
1171
1172for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1173{
1174ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1175for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1176
1177if (((uint16_t *)ptr)[0] == 0) {
1178ptr += 2;
1179}
1180
1181structHeader = (SMBStructHeader *)ptr;
1182}
1183
1184ptr = ((SMBSystemInformation *)structHeader)->uuid;
1185
1186if (!sysId || !ret) { // no or bad custom UUID,...
1187sysId = 0;
1188ret = Platform.UUID; // ...try bios dmi system uuid extraction
1189}
1190
1191for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
1192{
1193if (ret[i] != 0x00) {
1194isZero = 0;
1195}
1196
1197if (ret[i] != 0xff) {
1198isOnes = 0;
1199}
1200}
1201
1202if (isZero || isOnes) { // if empty or setable...
1203verbose("No UUID present in SMBIOS System Information Table\n");
1204ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1205}
1206
1207memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1208return ptr;
1209} // Bungo: end fix
1210
1211void setupSMBIOSTable(void)
1212{
1213SMBStructPtrs *structPtr;
1214uint8_t *buffer;
1215// bool setSMB = true; Bungo
1216
1217if (!origeps) {
1218return;
1219}
1220
1221neweps = origeps;
1222
1223structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1224if (!structPtr) {
1225return;
1226}
1227
1228buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1229if (!buffer) {
1230free(structPtr);
1231return;
1232}
1233
1234bzero(buffer, SMB_ALLOC_SIZE);
1235structPtr->new = (SMBStructHeader *)buffer;
1236
1237// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1238getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1239// if (setSMB) Bungo
1240setDefaultSMBData();
1241
1242setupNewSMBIOSTable(origeps, structPtr);
1243
1244neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1245if (!neweps) {
1246free(buffer);
1247free(structPtr);
1248return;
1249}
1250bzero(neweps, sizeof(SMBEntryPoint));
1251
1252neweps->anchor[0]= '_';
1253neweps->anchor[1]= 'S';
1254neweps->anchor[2]= 'M';
1255neweps->anchor[3]= '_';
1256neweps->entryPointLength= sizeof(SMBEntryPoint);
1257neweps->majorVersion= 2; // Bungo:
1258neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1259neweps->maxStructureSize= maxStructSize;
1260neweps->entryPointRevision= 0;
1261
1262neweps->dmi.anchor[0]= '_';
1263neweps->dmi.anchor[1]= 'D';
1264neweps->dmi.anchor[2]= 'M';
1265neweps->dmi.anchor[3]= 'I';
1266neweps->dmi.anchor[4]= '_';
1267neweps->dmi.tableLength= tableLength;
1268neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1269neweps->dmi.structureCount= structureCount;
1270neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1271
1272if (!neweps->dmi.tableAddress) {
1273free(buffer);
1274free(structPtr);
1275return;
1276}
1277
1278memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1279
1280Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
1281
1282neweps->dmi.checksum= 0;
1283neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1284
1285neweps->checksum= 0;
1286neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1287
1288free(buffer);
1289free(structPtr);
1290
1291decodeSMBIOSTable(neweps);
1292
1293DBG("SMBIOS orig was = %x\n", origeps);
1294DBG("SMBIOS new is = %x\n", neweps);
1295}
1296
1297void *getSmbios(int which)
1298{
1299switch (which) {
1300case SMBIOS_ORIGINAL:
1301if (!origeps) {
1302origeps = getAddressOfSmbiosTable();
1303}
1304return origeps;
1305case SMBIOS_PATCHED:
1306return neweps;
1307}
1308
1309return 0;
1310}
1311
1312/* Collect any information needed later */
1313void readSMBIOSInfo(SMBEntryPoint *eps)
1314{
1315uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1316SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1317
1318int dimmnbr = 0;
1319Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1320Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1321Platform.DMI.MemoryModules= 0;
1322
1323for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1324{
1325switch (structHeader->type)
1326{
1327case kSMBTypeSystemInformation:
1328Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid
1329break;
1330
1331case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1332switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1333case kSMBchassisDesktop:
1334case kSMBchassisLPDesktop:
1335case kSMBchassisAllInOne:
1336case kSMBchassisLunchBox:
1337PlatformType = 1; // desktop (iMac, MacMini)
1338break;
1339case kSMBchassisPortable:
1340case kSMBchassisLaptop:
1341case kSMBchassisNotebook:
1342case kSMBchassisHandHeld:
1343case kSMBchassisSubNotebook:
1344PlatformType = 2; // notebook (Mac Books)
1345 break;
1346default:
1347PlatformType = 3; // workstation (Mac Pro, Xserve)
1348break;
1349}
1350break;
1351//
1352case kSMBTypePhysicalMemoryArray:
1353Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1354break;
1355
1356case kSMBTypeMemoryDevice:
1357Platform.DMI.CntMemorySlots++;
1358if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
1359Platform.DMI.MemoryModules++;
1360}
1361if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
1362Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1363}
1364dimmnbr++;
1365break;
1366default:
1367break;
1368}
1369
1370structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1371for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1372
1373if (((uint16_t *)structPtr)[0] == 0) {
1374structPtr += 2;
1375}
1376
1377structHeader = (SMBStructHeader *)structPtr;
1378}
1379}
1380

Archive Download this file

Revision: 2355