OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <CoreFoundation/CoreFoundation.h> | 5 #include <CoreFoundation/CoreFoundation.h> |
6 #include <IOKit/IOKitLib.h> | 6 #include <IOKit/IOKitLib.h> |
7 #include <IOKit/network/IOEthernetController.h> | 7 #include <IOKit/network/IOEthernetController.h> |
8 #include <IOKit/network/IOEthernetInterface.h> | 8 #include <IOKit/network/IOEthernetInterface.h> |
9 #include <IOKit/network/IONetworkInterface.h> | 9 #include <IOKit/network/IONetworkInterface.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/mac/scoped_ioobject.h" | 14 #include "base/mac/scoped_ioobject.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 | 19 |
20 namespace rlz_lib { | 20 namespace rlz_lib { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // See http://developer.apple.com/library/mac/#technotes/tn1103/_index.html | 24 // See http://developer.apple.com/library/mac/#technotes/tn1103/_index.html |
25 | 25 |
26 // The caller is responsible for freeing |matching_services|. | 26 // The caller is responsible for freeing |matching_services|. |
27 bool FindEthernetInterfaces(io_iterator_t* matching_services) { | 27 bool FindEthernetInterfaces(io_iterator_t* matching_services) { |
28 base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict( | 28 base::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict( |
29 IOServiceMatching(kIOEthernetInterfaceClass)); | 29 IOServiceMatching(kIOEthernetInterfaceClass)); |
30 if (!matching_dict) | 30 if (!matching_dict) |
31 return false; | 31 return false; |
32 | 32 |
33 base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> primary_interface( | 33 base::ScopedCFTypeRef<CFMutableDictionaryRef> primary_interface( |
34 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | 34 CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 35 0, |
35 &kCFTypeDictionaryKeyCallBacks, | 36 &kCFTypeDictionaryKeyCallBacks, |
36 &kCFTypeDictionaryValueCallBacks)); | 37 &kCFTypeDictionaryValueCallBacks)); |
37 if (!primary_interface) | 38 if (!primary_interface) |
38 return false; | 39 return false; |
39 | 40 |
40 CFDictionarySetValue( | 41 CFDictionarySetValue( |
41 primary_interface, CFSTR(kIOPrimaryInterface), kCFBooleanTrue); | 42 primary_interface, CFSTR(kIOPrimaryInterface), kCFBooleanTrue); |
42 CFDictionarySetValue( | 43 CFDictionarySetValue( |
43 matching_dict, CFSTR(kIOPropertyMatchKey), primary_interface); | 44 matching_dict, CFSTR(kIOPropertyMatchKey), primary_interface); |
44 | 45 |
(...skipping 17 matching lines...) Expand all Loading... |
62 io_object_t primary_interface_parent; | 63 io_object_t primary_interface_parent; |
63 kern_return_t kern_result = IORegistryEntryGetParentEntry( | 64 kern_return_t kern_result = IORegistryEntryGetParentEntry( |
64 primary_interface, kIOServicePlane, &primary_interface_parent); | 65 primary_interface, kIOServicePlane, &primary_interface_parent); |
65 base::mac::ScopedIOObject<io_object_t> primary_interface_parent_deleter( | 66 base::mac::ScopedIOObject<io_object_t> primary_interface_parent_deleter( |
66 primary_interface_parent); | 67 primary_interface_parent); |
67 success = kern_result == KERN_SUCCESS; | 68 success = kern_result == KERN_SUCCESS; |
68 | 69 |
69 if (!success) | 70 if (!success) |
70 continue; | 71 continue; |
71 | 72 |
72 base::mac::ScopedCFTypeRef<CFTypeRef> mac_data( | 73 base::ScopedCFTypeRef<CFTypeRef> mac_data( |
73 IORegistryEntryCreateCFProperty(primary_interface_parent, | 74 IORegistryEntryCreateCFProperty(primary_interface_parent, |
74 CFSTR(kIOMACAddress), | 75 CFSTR(kIOMACAddress), |
75 kCFAllocatorDefault, | 76 kCFAllocatorDefault, |
76 0)); | 77 0)); |
77 CFDataRef mac_data_data = base::mac::CFCast<CFDataRef>(mac_data); | 78 CFDataRef mac_data_data = base::mac::CFCast<CFDataRef>(mac_data); |
78 if (mac_data_data) { | 79 if (mac_data_data) { |
79 CFDataGetBytes( | 80 CFDataGetBytes( |
80 mac_data_data, CFRangeMake(0, kIOEthernetAddressSize), buffer); | 81 mac_data_data, CFRangeMake(0, kIOEthernetAddressSize), buffer); |
81 } | 82 } |
82 } | 83 } |
(...skipping 11 matching lines...) Expand all Loading... |
94 return result; | 95 return result; |
95 } | 96 } |
96 | 97 |
97 CFStringRef CopySerialNumber() { | 98 CFStringRef CopySerialNumber() { |
98 base::mac::ScopedIOObject<io_service_t> expert_device( | 99 base::mac::ScopedIOObject<io_service_t> expert_device( |
99 IOServiceGetMatchingService(kIOMasterPortDefault, | 100 IOServiceGetMatchingService(kIOMasterPortDefault, |
100 IOServiceMatching("IOPlatformExpertDevice"))); | 101 IOServiceMatching("IOPlatformExpertDevice"))); |
101 if (!expert_device) | 102 if (!expert_device) |
102 return NULL; | 103 return NULL; |
103 | 104 |
104 base::mac::ScopedCFTypeRef<CFTypeRef> serial_number( | 105 base::ScopedCFTypeRef<CFTypeRef> serial_number( |
105 IORegistryEntryCreateCFProperty(expert_device, | 106 IORegistryEntryCreateCFProperty(expert_device, |
106 CFSTR(kIOPlatformSerialNumberKey), | 107 CFSTR(kIOPlatformSerialNumberKey), |
107 kCFAllocatorDefault, | 108 kCFAllocatorDefault, |
108 0)); | 109 0)); |
109 CFStringRef serial_number_cfstring = | 110 CFStringRef serial_number_cfstring = |
110 base::mac::CFCast<CFStringRef>(serial_number); | 111 base::mac::CFCast<CFStringRef>(serial_number); |
111 if (!serial_number_cfstring) | 112 if (!serial_number_cfstring) |
112 return NULL; | 113 return NULL; |
113 | 114 |
114 ignore_result(serial_number.release()); | 115 ignore_result(serial_number.release()); |
(...skipping 23 matching lines...) Expand all Loading... |
138 CFRelease(serial); | 139 CFRelease(serial); |
139 } | 140 } |
140 | 141 |
141 // On windows, this is set to the volume id. Since it's not scrambled before | 142 // On windows, this is set to the volume id. Since it's not scrambled before |
142 // being sent, just set it to 1. | 143 // being sent, just set it to 1. |
143 *more_data = 1; | 144 *more_data = 1; |
144 return true; | 145 return true; |
145 } | 146 } |
146 | 147 |
147 } // namespace rlz_lib | 148 } // namespace rlz_lib |
OLD | NEW |