Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 1216583003: Adding Hashed Address to BluetoothLowEnergyDeviceMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeinfo
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/bluetooth_low_energy_device_mac.h" 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
6 6
7 #import <CoreFoundation/CoreFoundation.h> 7 #import <CoreFoundation/CoreFoundation.h>
8 8
9 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "device/bluetooth/bluetooth_device.h"
12 14
13 using device::BluetoothDevice; 15 using device::BluetoothDevice;
14 using device::BluetoothLowEnergyDeviceMac; 16 using device::BluetoothLowEnergyDeviceMac;
15 17
16 namespace { 18 namespace {
17 19
18 // Converts a CBUUID to a Cocoa string. 20 // Converts a CBUUID to a Cocoa string.
19 // 21 //
20 // The string representation can have the following formats: 22 // The string representation can have the following formats:
21 // - 16 bit: xxxx 23 // - 16 bit: xxxx
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 std::string uuid_c_string = base::SysNSStringToUTF8(uuidString); 61 std::string uuid_c_string = base::SysNSStringToUTF8(uuidString);
60 return device::BluetoothUUID(uuid_c_string); 62 return device::BluetoothUUID(uuid_c_string);
61 } 63 }
62 64
63 } // namespace 65 } // namespace
64 66
65 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( 67 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
66 CBPeripheral* peripheral, 68 CBPeripheral* peripheral,
67 NSDictionary* advertisementData, 69 NSDictionary* advertisementData,
68 int rssi) { 70 int rssi) {
71 identifier_ = GetPeripheralIdentifier(peripheral);
72 hash_address_ = GetPeripheralHashAddress(peripheral);
69 Update(peripheral, advertisementData, rssi); 73 Update(peripheral, advertisementData, rssi);
70 } 74 }
71 75
72 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { 76 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
73 } 77 }
74 78
75 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, 79 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
76 NSDictionary* advertisementData, 80 NSDictionary* advertisementData,
77 int rssi) { 81 int rssi) {
78 last_update_time = [NSDate date]; 82 last_update_time = [NSDate date];
79 peripheral_.reset([peripheral retain]); 83 peripheral_.reset([peripheral retain]);
80 rssi_ = rssi; 84 rssi_ = rssi;
81 ClearServiceData(); 85 ClearServiceData();
82 NSNumber* nbConnectable = 86 NSNumber* nbConnectable =
83 [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; 87 [advertisementData objectForKey:CBAdvertisementDataIsConnectable];
84 connectable_ = [nbConnectable boolValue]; 88 connectable_ = [nbConnectable boolValue];
85 NSDictionary* serviceData = 89 NSDictionary* serviceData =
86 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; 90 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey];
87 for (CBUUID* uuid in serviceData) { 91 for (CBUUID* uuid in serviceData) {
88 NSData* data = [serviceData objectForKey:uuid]; 92 NSData* data = [serviceData objectForKey:uuid];
89 BluetoothUUID serviceUUID = BluetoothUUIDWithCBUUID(uuid); 93 BluetoothUUID serviceUUID = BluetoothUUIDWithCBUUID(uuid);
90 SetServiceData(serviceUUID, (const char*)[data bytes], [data length]); 94 SetServiceData(serviceUUID, (const char*)[data bytes], [data length]);
91 } 95 }
92 } 96 }
93 97
94 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { 98 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
95 return GetPeripheralIdentifier(peripheral_); 99 return identifier_;
96 } 100 }
97 101
98 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { 102 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
99 return 0; 103 return 0;
100 } 104 }
101 105
102 std::string BluetoothLowEnergyDeviceMac::GetAddress() const { 106 std::string BluetoothLowEnergyDeviceMac::GetAddress() const {
103 return std::string(); 107 return hash_address_;
104 } 108 }
105 109
106 BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource() 110 BluetoothDevice::VendorIDSource BluetoothLowEnergyDeviceMac::GetVendorIDSource()
107 const { 111 const {
108 return VENDOR_ID_UNKNOWN; 112 return VENDOR_ID_UNKNOWN;
109 } 113 }
110 114
111 uint16 BluetoothLowEnergyDeviceMac::GetVendorID() const { 115 uint16 BluetoothLowEnergyDeviceMac::GetVendorID() const {
112 return 0; 116 return 0;
113 } 117 }
114 118
115 uint16 BluetoothLowEnergyDeviceMac::GetProductID() const { 119 uint16 BluetoothLowEnergyDeviceMac::GetProductID() const {
116 return 0; 120 return 0;
117 } 121 }
118 122
119 uint16 BluetoothLowEnergyDeviceMac::GetDeviceID() const { 123 uint16 BluetoothLowEnergyDeviceMac::GetDeviceID() const {
120 return 0; 124 return 0;
121 } 125 }
122 126
123 int BluetoothLowEnergyDeviceMac::GetRSSI() const { 127 int BluetoothLowEnergyDeviceMac::GetRSSI() const {
124 return rssi_; 128 return rssi_;
125 } 129 }
126 130
127 bool BluetoothLowEnergyDeviceMac::IsPaired() const { 131 bool BluetoothLowEnergyDeviceMac::IsPaired() const {
128 return false; 132 return false;
129 } 133 }
130 134
131 bool BluetoothLowEnergyDeviceMac::IsConnected() const { 135 bool BluetoothLowEnergyDeviceMac::IsConnected() const {
136 // TODO(krstnmnlsn): Remove check once we move to OSX SDK >= 10.9.
scheib 2015/07/01 17:29:44 Rephrase as explaining that isConnected was deprec
krstnmnlsn 2015/07/02 00:25:30 Done.
137 if ([peripheral_ respondsToSelector:@selector(state)]) {
138 return ([peripheral_ state] == CBPeripheralStateConnected);
139 }
132 return [peripheral_ isConnected]; 140 return [peripheral_ isConnected];
133 } 141 }
134 142
135 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { 143 bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
136 return connectable_; 144 return connectable_;
137 } 145 }
138 146
139 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { 147 bool BluetoothLowEnergyDeviceMac::IsConnecting() const {
140 return false; 148 return false;
141 } 149 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // When -[CBPeripheral identifier] is available. 250 // When -[CBPeripheral identifier] is available.
243 NSUUID* uuid = [peripheral identifier]; 251 NSUUID* uuid = [peripheral identifier];
244 NSString* uuidString = [uuid UUIDString]; 252 NSString* uuidString = [uuid UUIDString];
245 return base::SysNSStringToUTF8(uuidString); 253 return base::SysNSStringToUTF8(uuidString);
246 } 254 }
247 255
248 base::ScopedCFTypeRef<CFStringRef> str( 256 base::ScopedCFTypeRef<CFStringRef> str(
249 CFUUIDCreateString(NULL, [peripheral UUID])); 257 CFUUIDCreateString(NULL, [peripheral UUID]));
250 return SysCFStringRefToUTF8(str); 258 return SysCFStringRefToUTF8(str);
251 } 259 }
260
261 std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
262 CBPeripheral* peripheral) {
263 const size_t kCanonicalAddressNumberOfBytes = 6;
264 char raw[kCanonicalAddressNumberOfBytes] = {0};
265 crypto::SHA256HashString(GetPeripheralIdentifier(peripheral), raw,
266 sizeof(raw));
267 std::string hash = base::HexEncode(raw, sizeof(raw));
268 return BluetoothDevice::CanonicalizeAddress(hash);
269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698