| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/mac/bluetooth_utility.h" | 5 #include "chrome/browser/mac/bluetooth_utility.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <IOKit/IOKitLib.h> | 8 #include <IOKit/IOKitLib.h> |
| 9 | 9 |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 NSDictionary* objc_dict = base::mac::CFToNSCast(scoped_dict.get()); | 43 NSDictionary* objc_dict = base::mac::CFToNSCast(scoped_dict.get()); |
| 44 NSNumber* lmp_version = | 44 NSNumber* lmp_version = |
| 45 base::mac::ObjCCast<NSNumber>([objc_dict objectForKey:@"LMPVersion"]); | 45 base::mac::ObjCCast<NSNumber>([objc_dict objectForKey:@"LMPVersion"]); |
| 46 if (!lmp_version) | 46 if (!lmp_version) |
| 47 continue; | 47 continue; |
| 48 | 48 |
| 49 // The LMP version is too low to support Bluetooth LE. | 49 // The LMP version is too low to support Bluetooth LE. |
| 50 if ([lmp_version intValue] < 6) | 50 if ([lmp_version intValue] < 6) |
| 51 continue; | 51 continue; |
| 52 | 52 |
| 53 // Check the supported features registry entry for Bluetooth LE | |
| 54 // availability. The relevant bit has a different meaning on OSX 10.6, and | |
| 55 // could change again in the future. | |
| 56 if (base::mac::IsOSSnowLeopard()) | |
| 57 return BLUETOOTH_AVAILABLE_LE_UNKNOWN; | |
| 58 | |
| 59 NSData* data = base::mac::ObjCCast<NSData>( | 53 NSData* data = base::mac::ObjCCast<NSData>( |
| 60 [objc_dict objectForKey:@"HCISupportedFeatures"]); | 54 [objc_dict objectForKey:@"HCISupportedFeatures"]); |
| 61 | 55 |
| 62 NSUInteger supported_features_index = 4; | 56 NSUInteger supported_features_index = 4; |
| 63 NSUInteger length = [data length]; | 57 NSUInteger length = [data length]; |
| 64 if (length < supported_features_index + 1) | 58 if (length < supported_features_index + 1) |
| 65 continue; | 59 continue; |
| 66 | 60 |
| 67 // The bytes are indexed in reverse order. | 61 // The bytes are indexed in reverse order. |
| 68 NSUInteger index = length - supported_features_index - 1; | 62 NSUInteger index = length - supported_features_index - 1; |
| 69 | 63 |
| 70 const unsigned char* bytes = | 64 const unsigned char* bytes = |
| 71 static_cast<const unsigned char*>([data bytes]); | 65 static_cast<const unsigned char*>([data bytes]); |
| 72 const unsigned char byte = bytes[index]; | 66 const unsigned char byte = bytes[index]; |
| 73 bool le_supported = byte & kBluetoothFeatureLESupportedController; | 67 bool le_supported = byte & kBluetoothFeatureLESupportedController; |
| 74 if (le_supported) | 68 if (le_supported) |
| 75 return BLUETOOTH_AVAILABLE_WITH_LE; | 69 return BLUETOOTH_AVAILABLE_WITH_LE; |
| 76 } | 70 } |
| 77 | 71 |
| 78 return bluetooth_available ? BLUETOOTH_AVAILABLE_WITHOUT_LE | 72 return bluetooth_available ? BLUETOOTH_AVAILABLE_WITHOUT_LE |
| 79 : BLUETOOTH_AVAILABILITY_ERROR; | 73 : BLUETOOTH_AVAILABILITY_ERROR; |
| 80 } | 74 } |
| 81 | 75 |
| 82 } // namespace bluetooth_utility | 76 } // namespace bluetooth_utility |
| OLD | NEW |