| OLD | NEW |
| 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 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <queue> | 11 #include <queue> |
| 9 #include <string> | 12 #include <string> |
| 10 | 13 |
| 11 #include "base/macros.h" | 14 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 16 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" | 19 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" |
| 17 #include "components/proximity_auth/ble/fake_wire_message.h" | 20 #include "components/proximity_auth/ble/fake_wire_message.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // | | 55 // | |
| 53 // Read kInvitationResponseSignal from Reader Characteristic | 56 // Read kInvitationResponseSignal from Reader Characteristic |
| 54 // | | 57 // | |
| 55 // | | 58 // | |
| 56 // | | 59 // | |
| 57 // Proximity Auth Connection Established | 60 // Proximity Auth Connection Established |
| 58 class BluetoothLowEnergyConnection : public Connection, | 61 class BluetoothLowEnergyConnection : public Connection, |
| 59 public device::BluetoothAdapter::Observer { | 62 public device::BluetoothAdapter::Observer { |
| 60 public: | 63 public: |
| 61 // Signals sent to the remote device to indicate connection related events. | 64 // Signals sent to the remote device to indicate connection related events. |
| 62 enum class ControlSignal : uint32 { | 65 enum class ControlSignal : uint32_t { |
| 63 kInviteToConnectSignal = 0, | 66 kInviteToConnectSignal = 0, |
| 64 kInvitationResponseSignal = 1, | 67 kInvitationResponseSignal = 1, |
| 65 kSendSignal = 2, | 68 kSendSignal = 2, |
| 66 kDisconnectSignal = 3, | 69 kDisconnectSignal = 3, |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class | 72 // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class |
| 70 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. | 73 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. |
| 71 enum class SubStatus { | 74 enum class SubStatus { |
| 72 DISCONNECTED, | 75 DISCONNECTED, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void SendMessageImpl(scoped_ptr<WireMessage> message) override; | 120 void SendMessageImpl(scoped_ptr<WireMessage> message) override; |
| 118 | 121 |
| 119 // device::BluetoothAdapter::Observer: | 122 // device::BluetoothAdapter::Observer: |
| 120 void DeviceChanged(device::BluetoothAdapter* adapter, | 123 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 121 device::BluetoothDevice* device) override; | 124 device::BluetoothDevice* device) override; |
| 122 void DeviceRemoved(device::BluetoothAdapter* adapter, | 125 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 123 device::BluetoothDevice* device) override; | 126 device::BluetoothDevice* device) override; |
| 124 void GattCharacteristicValueChanged( | 127 void GattCharacteristicValueChanged( |
| 125 device::BluetoothAdapter* adapter, | 128 device::BluetoothAdapter* adapter, |
| 126 device::BluetoothGattCharacteristic* characteristic, | 129 device::BluetoothGattCharacteristic* characteristic, |
| 127 const std::vector<uint8>& value) override; | 130 const std::vector<uint8_t>& value) override; |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 // Represents a request to write |value| to a some characteristic. | 133 // Represents a request to write |value| to a some characteristic. |
| 131 // |is_last_write_for_wire_messsage| indicates whether this request | 134 // |is_last_write_for_wire_messsage| indicates whether this request |
| 132 // corresponds to the last write request for some wire message. | 135 // corresponds to the last write request for some wire message. |
| 133 // A WireMessage corresponds to exactly two WriteRequest: the first containing | 136 // A WireMessage corresponds to exactly two WriteRequest: the first containing |
| 134 // a kSendSignal + the size of the WireMessage, and the second containing a | 137 // a kSendSignal + the size of the WireMessage, and the second containing a |
| 135 // SendStatusSignal + the serialized WireMessage. | 138 // SendStatusSignal + the serialized WireMessage. |
| 136 struct WriteRequest { | 139 struct WriteRequest { |
| 137 WriteRequest(const std::vector<uint8>& val, bool flag); | 140 WriteRequest(const std::vector<uint8_t>& val, bool flag); |
| 138 ~WriteRequest(); | 141 ~WriteRequest(); |
| 139 | 142 |
| 140 std::vector<uint8> value; | 143 std::vector<uint8_t> value; |
| 141 bool is_last_write_for_wire_message; | 144 bool is_last_write_for_wire_message; |
| 142 int number_of_failed_attempts; | 145 int number_of_failed_attempts; |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 // Creates the GATT connection with |remote_device|. | 148 // Creates the GATT connection with |remote_device|. |
| 146 void CreateGattConnection(); | 149 void CreateGattConnection(); |
| 147 | 150 |
| 148 // Called when a GATT connection is created. | 151 // Called when a GATT connection is created. |
| 149 void OnGattConnectionCreated( | 152 void OnGattConnectionCreated( |
| 150 scoped_ptr<device::BluetoothGattConnection> gatt_connection); | 153 scoped_ptr<device::BluetoothGattConnection> gatt_connection); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 void OnRemoteCharacteristicWritten(bool run_did_send_message_callback); | 211 void OnRemoteCharacteristicWritten(bool run_did_send_message_callback); |
| 209 | 212 |
| 210 // Called when there is an error writing to the remote characteristic | 213 // Called when there is an error writing to the remote characteristic |
| 211 // |to_peripheral_char_|. | 214 // |to_peripheral_char_|. |
| 212 void OnWriteRemoteCharacteristicError( | 215 void OnWriteRemoteCharacteristicError( |
| 213 bool run_did_send_message_callback, | 216 bool run_did_send_message_callback, |
| 214 device::BluetoothGattService::GattErrorCode error); | 217 device::BluetoothGattService::GattErrorCode error); |
| 215 | 218 |
| 216 // Builds the value to be written on |to_peripheral_char_|. The value | 219 // Builds the value to be written on |to_peripheral_char_|. The value |
| 217 // corresponds to |signal| concatenated with |payload|. | 220 // corresponds to |signal| concatenated with |payload|. |
| 218 WriteRequest BuildWriteRequest(const std::vector<uint8>& signal, | 221 WriteRequest BuildWriteRequest(const std::vector<uint8_t>& signal, |
| 219 const std::vector<uint8>& bytes, | 222 const std::vector<uint8_t>& bytes, |
| 220 bool is_last_message_for_wire_message); | 223 bool is_last_message_for_wire_message); |
| 221 | 224 |
| 222 // Prints the time elapsed since |Connect()| was called. | 225 // Prints the time elapsed since |Connect()| was called. |
| 223 void PrintTimeElapsed(); | 226 void PrintTimeElapsed(); |
| 224 | 227 |
| 225 // Returns the device corresponding to |remote_device_address_|. | 228 // Returns the device corresponding to |remote_device_address_|. |
| 226 device::BluetoothDevice* GetRemoteDevice(); | 229 device::BluetoothDevice* GetRemoteDevice(); |
| 227 | 230 |
| 228 // Returns the service corresponding to |remote_service_| in the current | 231 // Returns the service corresponding to |remote_service_| in the current |
| 229 // device. | 232 // device. |
| 230 device::BluetoothGattService* GetRemoteService(); | 233 device::BluetoothGattService* GetRemoteService(); |
| 231 | 234 |
| 232 // Returns the characteristic corresponding to |identifier| in the current | 235 // Returns the characteristic corresponding to |identifier| in the current |
| 233 // service. | 236 // service. |
| 234 device::BluetoothGattCharacteristic* GetGattCharacteristic( | 237 device::BluetoothGattCharacteristic* GetGattCharacteristic( |
| 235 const std::string& identifier); | 238 const std::string& identifier); |
| 236 | 239 |
| 237 // Convert the first 4 bytes from a byte vector to a uint32. | 240 // Convert the first 4 bytes from a byte vector to a uint32_t. |
| 238 uint32 ToUint32(const std::vector<uint8>& bytes); | 241 uint32_t ToUint32(const std::vector<uint8_t>& bytes); |
| 239 | 242 |
| 240 // Convert an uint32 to a byte vector. | 243 // Convert an uint32_t to a byte vector. |
| 241 const std::vector<uint8> ToByteVector(uint32 value); | 244 const std::vector<uint8_t> ToByteVector(uint32_t value); |
| 242 | 245 |
| 243 // The Bluetooth adapter over which the Bluetooth connection will be made. | 246 // The Bluetooth adapter over which the Bluetooth connection will be made. |
| 244 scoped_refptr<device::BluetoothAdapter> adapter_; | 247 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 245 | 248 |
| 246 // Remote service the |gatt_connection_| was established with. | 249 // Remote service the |gatt_connection_| was established with. |
| 247 RemoteAttribute remote_service_; | 250 RemoteAttribute remote_service_; |
| 248 | 251 |
| 249 // Characteristic used to send data to the remote device. | 252 // Characteristic used to send data to the remote device. |
| 250 RemoteAttribute to_peripheral_char_; | 253 RemoteAttribute to_peripheral_char_; |
| 251 | 254 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 base::TimeTicks start_time_; | 303 base::TimeTicks start_time_; |
| 301 | 304 |
| 302 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; | 305 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; |
| 303 | 306 |
| 304 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); | 307 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); |
| 305 }; | 308 }; |
| 306 | 309 |
| 307 } // namespace proximity_auth | 310 } // namespace proximity_auth |
| 308 | 311 |
| 309 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 312 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| OLD | NEW |