bluetooth_gatt_characteristic.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "base/callback_forward.h"
  10. #include "device/bluetooth/bluetooth_export.h"
  11. #include "device/bluetooth/bluetooth_gatt_service.h"
  12. #include "device/bluetooth/public/cpp/bluetooth_uuid.h"
  13. namespace device {
  14. // BluetoothGattCharacteristic represents a local or remote GATT characteristic.
  15. // A GATT characteristic is a basic data element used to construct a GATT
  16. // service. Hence, instances of a BluetoothGattCharacteristic are associated
  17. // with a BluetoothGattService.
  18. class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristic {
  19. public:
  20. // Values representing the possible properties of a characteristic, which
  21. // define how the characteristic can be used. Each of these properties serve
  22. // a role as defined in the Bluetooth Specification.
  23. // |PROPERTY_EXTENDED_PROPERTIES| is a special property that, if present,
  24. // indicates that there is a characteristic descriptor (namely the
  25. // "Characteristic Extended Properties Descriptor" with UUID 0x2900) that
  26. // contains additional properties pertaining to the characteristic.
  27. // The properties "ReliableWrite| and |WriteAuxiliaries| are retrieved from
  28. // that characteristic.
  29. enum Property {
  30. PROPERTY_NONE = 0,
  31. PROPERTY_BROADCAST = 1 << 0,
  32. PROPERTY_READ = 1 << 1,
  33. PROPERTY_WRITE_WITHOUT_RESPONSE = 1 << 2,
  34. PROPERTY_WRITE = 1 << 3,
  35. PROPERTY_NOTIFY = 1 << 4,
  36. PROPERTY_INDICATE = 1 << 5,
  37. PROPERTY_AUTHENTICATED_SIGNED_WRITES = 1 << 6,
  38. PROPERTY_EXTENDED_PROPERTIES = 1 << 7,
  39. PROPERTY_RELIABLE_WRITE = 1 << 8,
  40. PROPERTY_WRITABLE_AUXILIARIES = 1 << 9,
  41. PROPERTY_READ_ENCRYPTED = 1 << 10,
  42. PROPERTY_WRITE_ENCRYPTED = 1 << 11,
  43. PROPERTY_READ_ENCRYPTED_AUTHENTICATED = 1 << 12,
  44. PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED = 1 << 13,
  45. NUM_PROPERTY = 1 << 14,
  46. };
  47. typedef uint32_t Properties;
  48. // Values representing read, write, and encryption permissions for a
  49. // characteristic's value. While attribute permissions for all GATT
  50. // definitions have been set by the Bluetooth specification, characteristic
  51. // value permissions are left up to the higher-level profile.
  52. //
  53. // Attribute permissions are distinct from the characteristic properties. For
  54. // example, a characteristic may have the property |PROPERTY_READ| to make
  55. // clients know that it is possible to read the characteristic value and have
  56. // the permission |PERMISSION_READ_ENCRYPTED| to require a secure connection.
  57. // It is up to the application to properly specify the permissions and
  58. // properties for a local characteristic.
  59. // TODO(rkc): Currently BlueZ infers permissions for characteristics from
  60. // the properties. Once this is fixed, we will start sending the permissions
  61. // for characteristics to BlueZ. Till then permissions for characteristics
  62. // are unimplemented.
  63. enum Permission {
  64. PERMISSION_NONE = 0,
  65. PERMISSION_READ = 1 << 0,
  66. PERMISSION_WRITE = 1 << 1,
  67. PERMISSION_READ_ENCRYPTED = 1 << 2,
  68. PERMISSION_WRITE_ENCRYPTED = 1 << 3,
  69. PERMISSION_READ_ENCRYPTED_AUTHENTICATED = 1 << 4,
  70. PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED = 1 << 5,
  71. NUM_PERMISSION = 1 << 6,
  72. };
  73. typedef uint32_t Permissions;
  74. // Bluetooth Spec Vol 3, Part G, 3.3.3.3 Client Characteristic Configuration.
  75. enum class NotificationType { kNotification = 1, kIndication };
  76. // The ErrorCallback is used by methods to asynchronously report errors.
  77. using ErrorCallback =
  78. base::OnceCallback<void(BluetoothGattService::GattErrorCode)>;
  79. BluetoothGattCharacteristic(const BluetoothGattCharacteristic&) = delete;
  80. BluetoothGattCharacteristic& operator=(const BluetoothGattCharacteristic&) =
  81. delete;
  82. // Identifier used to uniquely identify a GATT characteristic object. This is
  83. // different from the characteristic UUID: while multiple characteristics with
  84. // the same UUID can exist on a Bluetooth device, the identifier returned from
  85. // this method is unique among all characteristics on the adapter. The
  86. // contents of the identifier are platform specific.
  87. virtual std::string GetIdentifier() const = 0;
  88. // The Bluetooth-specific UUID of the characteristic.
  89. virtual BluetoothUUID GetUUID() const = 0;
  90. // Returns the bitmask of characteristic properties.
  91. virtual Properties GetProperties() const = 0;
  92. // Returns the bitmask of characteristic attribute permissions.
  93. virtual Permissions GetPermissions() const = 0;
  94. protected:
  95. BluetoothGattCharacteristic();
  96. virtual ~BluetoothGattCharacteristic();
  97. };
  98. } // namespace device
  99. #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_