fast_pair_gatt_service_client.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_
  5. #define ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_
  6. #include "device/bluetooth/bluetooth_adapter.h"
  7. inline constexpr int kBlockByteSize = 16;
  8. namespace ash {
  9. namespace quick_pair {
  10. class FastPairDataEncryptor;
  11. // This class is responsible for connecting to the Fast Pair GATT service for a
  12. // device and invoking a callback when ready, or when an error is discovered
  13. // during initialization.
  14. class FastPairGattServiceClient : public device::BluetoothAdapter::Observer {
  15. public:
  16. ~FastPairGattServiceClient() override = default;
  17. virtual device::BluetoothRemoteGattService* gatt_service() = 0;
  18. // Constructs a data vector based on the message type, flags, provider
  19. // address, and seekers address. Writes data to the key based characteristic
  20. // and calls the callback with response data on success, or with a PairFailure
  21. // on failure.
  22. virtual void WriteRequestAsync(
  23. uint8_t message_type,
  24. uint8_t flags,
  25. const std::string& provider_address,
  26. const std::string& seekers_address,
  27. FastPairDataEncryptor* fast_pair_data_encryptor,
  28. base::OnceCallback<void(std::vector<uint8_t>,
  29. absl::optional<PairFailure>)>
  30. write_response_callback) = 0;
  31. // Constructs a data vector based on the message type and passkey. Writes
  32. // data to the passkey characteristic and calls the callback with response
  33. // data on success, or with a PairFailure on failure.
  34. virtual void WritePasskeyAsync(
  35. uint8_t message_type,
  36. uint32_t passkey,
  37. FastPairDataEncryptor* fast_pair_data_encryptor,
  38. base::OnceCallback<void(std::vector<uint8_t>,
  39. absl::optional<PairFailure>)>
  40. write_response_callback) = 0;
  41. // Writes the account key to the account key characteristic.
  42. virtual void WriteAccountKey(
  43. std::array<uint8_t, 16> account_key,
  44. FastPairDataEncryptor* fast_pair_data_encryptor,
  45. base::OnceCallback<
  46. void(absl::optional<device::BluetoothGattService::GattErrorCode>)>
  47. write_account_key_callback) = 0;
  48. // Returns whether or not this client has an active GATT connection.
  49. virtual bool IsConnected() = 0;
  50. };
  51. } // namespace quick_pair
  52. } // namespace ash
  53. #endif // ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_GATT_SERVICE_CLIENT_H_