1/*
2 * Copyright (c) 2002 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include "ioregpath.h"
25#include <IOKit/IOKitLib.h>
26
27CFDictionaryRef
28myIORegistryEntryCopyValue(const char * path)
29{
30    io_registry_entry_t 	service;
31    kern_return_t       	status;
32    CFMutableDictionaryRef	properties = NULL;
33
34    service = IORegistryEntryFromPath(kIOMasterPortDefault, path);
35    if (service == MACH_PORT_NULL) {
36	return (NULL);
37    }
38    status = IORegistryEntryCreateCFProperties(service,
39					       &properties,
40					       kCFAllocatorDefault,
41					       kNilOptions);
42    if (status != KERN_SUCCESS) {
43	properties = NULL;
44    }
45    IOObjectRelease(service);
46    return (properties);
47}
48
49CFTypeRef
50myIORegistryEntryCopyProperty(const char * path, CFStringRef prop)
51{
52    io_registry_entry_t 	service;
53    CFTypeRef			val;
54
55    service = IORegistryEntryFromPath(kIOMasterPortDefault, path);
56    if (service == MACH_PORT_NULL) {
57	return (NULL);
58    }
59    val = IORegistryEntryCreateCFProperty(service, prop,
60					  kCFAllocatorDefault,
61					  kNilOptions);
62    IOObjectRelease(service);
63    return (val);
64}
65
66CFDictionaryRef
67myIORegistryEntryBSDNameMatchingCopyValue(const char * devname, Boolean parent)
68{
69    kern_return_t       	status;
70    CFMutableDictionaryRef	properties = NULL;
71    io_registry_entry_t 	service;
72
73    service
74	= IOServiceGetMatchingService(kIOMasterPortDefault,
75				      IOBSDNameMatching(kIOMasterPortDefault, 0, devname));
76    if (service == MACH_PORT_NULL) {
77	return (NULL);
78    }
79    if (parent) {
80	io_registry_entry_t	parent_service;
81
82	status = IORegistryEntryGetParentEntry(service, kIOServicePlane,
83					       &parent_service);
84	if (status == KERN_SUCCESS) {
85	    status = IORegistryEntryCreateCFProperties(parent_service,
86						       &properties,
87						       kCFAllocatorDefault,
88						       kNilOptions);
89	    IOObjectRelease(parent_service);
90	}
91    }
92    else {
93	status = IORegistryEntryCreateCFProperties(service,
94						   &properties,
95						   kCFAllocatorDefault,
96						   kNilOptions);
97    }
98    if (status != KERN_SUCCESS) {
99	properties = NULL;
100    }
101    IOObjectRelease(service);
102    return (properties);
103}
104
105