1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <CoreFoundation/CoreFoundation.h>
21 #include <IOKit/IOKitLib.h>
25 dmi_get(const char *classname
, CFStringRef property
)
28 CFMutableDictionaryRef matching
= NULL
;
29 CFTypeRef cfres
= NULL
;
30 io_service_t service
= 0;
31 matching
= IOServiceMatching(classname
);
33 log_debug("localchassis", "cannot get %s class from registry",
37 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, matching
);
39 log_warnx("localchassis", "cannot get matching %s class from registry",
43 cfres
= IORegistryEntryCreateCFProperty(service
, property
, kCFAllocatorDefault
,
46 log_debug("localchassis",
47 "cannot find property %s in class %s in registry",
48 CFStringGetCStringPtr(property
, kCFStringEncodingMacRoman
),
53 if (CFGetTypeID(cfres
) == CFStringGetTypeID())
54 result
= strdup(CFStringGetCStringPtr((CFStringRef
)cfres
,
55 kCFStringEncodingMacRoman
));
56 else if (CFGetTypeID(cfres
) == CFDataGetTypeID()) {
57 /* OK, we know this is a string. */
58 result
= calloc(1, CFDataGetLength((CFDataRef
)cfres
) + 1);
59 if (!result
) goto end
;
60 memcpy(result
, CFDataGetBytePtr((CFDataRef
)cfres
),
61 CFDataGetLength((CFDataRef
)cfres
));
63 log_debug("localchassis", "unknown type for property %s in class %s",
64 CFStringGetCStringPtr(property
, kCFStringEncodingMacRoman
),
68 if (cfres
) CFRelease(cfres
);
69 if (service
) IOObjectRelease(service
);
76 return dmi_get("IOPlatformExpertDevice", CFSTR("version"));
82 /* Dunno where it is. Maybe in SMC? */
89 return dmi_get("IOPlatformExpertDevice", CFSTR("IOPlatformSerialNumber"));
95 return dmi_get("IOPlatformExpertDevice", CFSTR("manufacturer"));
101 return dmi_get("IOPlatformExpertDevice", CFSTR("model"));
107 return dmi_get("IOPlatformExpertDevice", CFSTR("board-id"));