Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
GattNumbers.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef GATT_NUMBERS_HPP_
27#define GATT_NUMBERS_HPP_
28
29#include <cstdint>
30
31#include <jau/basic_types.hpp>
32#include <jau/darray.hpp>
33#include <jau/octets.hpp>
34#include <jau/uuid.hpp>
35
36#include "BTTypes0.hpp"
38
39/**
40 * - - - - - - - - - - - - - - -
41 *
42 * GattNumbers.hpp Module for Higher level GATT value and service types like GattServiceType, GattCharacteristicType,
43 * GattCharacteristicProperty, GattRequirementSpec .. and finally GattServiceCharacteristic.
44 *
45 * - https://www.bluetooth.com/specifications/gatt/services/
46 *
47 * - https://www.bluetooth.com/specifications/gatt/ - See GATT Specification Supplement (GSS) Version 2
48 *
49 */
50namespace direct_bt {
51
52/** \addtogroup DBTUserAPI
53 *
54 * @{
55 */
56
57/**
58 * Following UUID16 GATT profile attribute types are listed under:
59 * BT Core Spec v5.2: Vol 3, Part G GATT: 3.4 Summary of GATT Profile Attribute Types
60 *
61 * See BTGattDesc::Type and GattCharacteristicType for further declarations.
62 */
63enum GattAttributeType : uint16_t {
64 /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.4.1 Discover All Primary Services, using AttPDUMsg::Opcode::READ_BY_GROUP_TYPE_REQ */
67
68 /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.5.1 Find Included Services, using AttPDUMsg::Opcode::READ_BY_TYPE_REQ */
70
71 /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.6.1 Discover All Characteristics of a Service, using , using AttPDUMsg::Opcode::READ_BY_TYPE_REQ */
72 CHARACTERISTIC = 0x2803
73};
74
75/**
76 * GATT Service Type, each encapsulating a set of Characteristics.
77 *
78 * <pre>
79 * https://www.bluetooth.com/specifications/gatt/services/
80 *
81 * https://www.bluetooth.com/specifications/gatt/ - See GATT Specification Supplement (GSS) Version 2
82 * </pre>
83 */
84enum GattServiceType : uint16_t {
85 /** This service contains generic information about the device. This is a mandatory service. */
87 /** The service allows receiving indications of changed services. This is a mandatory service. */
89 /** This service exposes a control point to change the peripheral alert behavior. */
91 /** The service defines behavior on the device when a link is lost between two devices. */
92 LINK_LOSS = 0x1803,
93 /** This service exposes temperature and other data from a thermometer intended for healthcare and fitness applications. */
95 /** This service exposes manufacturer and/or vendor information about a device. */
97 /** This service exposes the state of a battery within a device. */
99};
100std::string GattServiceTypeToString(const GattServiceType v) noexcept;
101
102/**
103 * GATT Assigned Characteristic Attribute Type for single logical value.
104 *
105 * https://www.bluetooth.com/specifications/gatt/characteristics/
106 *
107 * See GattAttributeType for further non BTGattChar related declarations.
108 */
109enum GattCharacteristicType : uint16_t {
110 //
111 // GENERIC_ACCESS
112 //
113 DEVICE_NAME = 0x2A00,
114 APPEARANCE = 0x2A01,
118
119 //
120 // GENERIC_ATTRIBUTE
121 //
123
124 /** Mandatory: sint16 10^-2: Celsius */
125 TEMPERATURE = 0x2A6E,
126
127 /** Mandatory: sint16 10^-1: Celsius */
130
131 //
132 // HEALTH_THERMOMETER
133 //
135 /** Mandatory: 8bit: 1 armpit, 2 body (general), 3(ear), 4 (finger), ... */
139
140 //
141 // DEVICE_INFORMATION
142 //
143 /** Mandatory: uint40 */
144 SYSTEM_ID = 0x2A23,
152 PNP_ID = 0x2A50,
153};
154std::string GattCharacteristicTypeToString(const GattCharacteristicType v) noexcept;
155
157 Broadcast = 0x01,
158 Read = 0x02,
161 Notify = 0x10,
162 Indicate = 0x20,
164 ExtProps = 0x80,
165 /** FIXME: extension? */
167 /** FIXME: extension? */
168 AuxWriteExt = 0x82
171
172enum GattRequirementSpec : uint8_t {
173 Excluded = 0x00,
174 Mandatory = 0x01,
175 Optional = 0x02,
179 C1 = 0x21,
180};
181std::string GattRequirementSpecToString(const GattRequirementSpec v) noexcept;
182
186
187 std::string toString() const noexcept;
188};
189
194
195 std::string toString() const noexcept;
196};
197
201
202 enum PropertySpecIdx : int {
203 ReadIdx = 0,
211 BroadcastIdx
212 };
213 /** Aggregated in PropertySpecIdx order */
215
217
218 std::string toString() const noexcept;
219};
220
224
225 std::string toString() const noexcept;
226};
227
228// #define DIRECTBT_BUILDIN_GATT_SERVICE_CHARACTERISTIC_SPEC 1
229#if defined(DIRECTBT_BUILDIN_GATT_SERVICE_CHARACTERISTIC_SPEC)
230/**
231 * Intentionally ease compile and linker burden by using 'extern' instead of 'inline',
232 * as the latter would require compile to crunch the structure
233 * and linker to chose where to place the actual artifact.
234 */
239
240/**
241 * Find the GattServiceCharacteristic entry by given uuid16,
242 * denominating either a GattServiceType or GattCharacteristicType.
243 */
244const GattServiceCharacteristic * findGattServiceChar(const uint16_t uuid16) noexcept;
245
246/**
247 * Find the GattCharacteristicSpec entry by given uuid16,
248 * denominating either a GattCharacteristicType.
249 */
250const GattCharacteristicSpec * findGattCharSpec(const uint16_t uuid16) noexcept;
251
252#endif /* DIRECTBT_BUILDIN_GATT_SERVICE_CHARACTERISTIC_SPEC */
253
254/********************************************************
255 *
256 * Known GATT Characteristic data value types.
257 *
258 ********************************************************/
259
260/**
261 * Converts a GATT Name (not null-terminated) UTF8 to a null-terminated C++ string
262 */
263std::string GattNameToString(const jau::TROOctets &v) noexcept;
264
265/**
266 * <i>Peripheral Preferred Connection Parameters</i> is a GATT Characteristic.
267 * <pre>
268 * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters.xml
269 * </pre>
270 */
272 /** mandatory [6..3200] x 1.25ms */
273 const uint16_t minConnectionInterval;
274 /** mandatory [6..3200] x 1.25ms and >= minConnectionInterval */
275 const uint16_t maxConnectionInterval;
276 /** mandatory [1..1000] */
277 const uint16_t slaveLatency;
278 /** mandatory [10..3200] */
280
281 static std::shared_ptr<GattPeriphalPreferredConnectionParameters> get(const jau::TROOctets &source) noexcept;
282
284
285 std::string toString() const noexcept;
286};
287
288/**
289 * <i>Generic Access Service</i> is a mandatory GATT service all peripherals are required to implement. (FIXME: Add reference)
290 * <pre>
291 * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.generic_access.xml
292 * </pre>
293 */
295 public:
296 /** Characteristic: Mandatory [Read: Mandatory; Write: Optional; ...]*/
297 const std::string deviceName;
298 /** Characteristic: Mandatory [Read: Mandatory; Write: Excluded; ...]*/
300 /** Characteristic: Optional [Read: Mandatory; Write: Conditional; ...]*/
301 const std::string peripheralPrivacyFlag; // FIXME: Value
302 /** Characteristic: Conditional [Read: Excluded; Write: Mandatory; ...]*/
303 const std::string reconnectionAdress; // FIXME: Value
304 /** Characteristic: Optional [Read: Mandatory; Write: Excluded; ...]*/
305 const std::shared_ptr<GattPeriphalPreferredConnectionParameters> prefConnParam;
306
307 GattGenericAccessSvc(std::string deviceName_, const AppearanceCat appearance_,
308 std::shared_ptr<GattPeriphalPreferredConnectionParameters> prefConnParam_) noexcept
309 : deviceName(std::move(deviceName_)), appearance(appearance_), prefConnParam(std::move(prefConnParam_)) {}
310
311 std::string toString() const noexcept;
312};
313
314/**
315 * <i>PnP ID</i> is a GATT Characteristic.
316 * <pre>
317 * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.pnp_id.xml
318 * </pre>
319 */
321 const uint8_t vendor_id_source;
322 const uint16_t vendor_id;
323 const uint16_t product_id;
324 const uint16_t product_version;
325
326 static std::shared_ptr<GattPnP_ID> get(const jau::TROOctets &source) noexcept;
327
328 GattPnP_ID() noexcept
329 : vendor_id_source(0), vendor_id(0), product_id(0), product_version(0) {}
330
331 GattPnP_ID(const jau::TROOctets &source) noexcept;
332
333 GattPnP_ID(const uint8_t vendor_id_source_, const uint16_t vendor_id_, const uint16_t product_id_, const uint16_t product_version_) noexcept
334 : vendor_id_source(vendor_id_source_), vendor_id(vendor_id_), product_id(product_id_), product_version(product_version_) {}
335
336 std::string toString() const noexcept;
337};
338
339/**
340 * <i>Device Information</i> is a GATT service.
341 * <pre>
342 * https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.device_information.xml
343 * </pre>
344 */
346 public:
347 /** Optional */
349 /** Optional */
350 const std::string modelNumber;
351 /** Optional */
352 const std::string serialNumber;
353 /** Optional */
354 const std::string firmwareRevision;
355 /** Optional */
356 const std::string hardwareRevision;
357 /** Optional */
358 const std::string softwareRevision;
359 /** Optional */
360 const std::string manufacturer;
361 /** Optional */
363 /** Optional */
364 const std::shared_ptr<GattPnP_ID> pnpID;
365
366 GattDeviceInformationSvc(jau::POctets systemID_, std::string modelNumber_, std::string serialNumber_,
367 std::string firmwareRevision_, std::string hardwareRevision_, std::string softwareRevision_,
368 std::string manufacturer_, jau::POctets regulatoryCertDataList_, std::shared_ptr<GattPnP_ID> pnpID_) noexcept
369 : systemID( std::move(systemID_) ), modelNumber( std::move(modelNumber_) ), serialNumber( std::move(serialNumber_) ),
370 firmwareRevision( std::move(firmwareRevision_) ), hardwareRevision( std::move(hardwareRevision_) ),
371 softwareRevision( std::move(softwareRevision_) ), manufacturer( std::move(manufacturer_) ),
372 regulatoryCertDataList( std::move(regulatoryCertDataList_) ), pnpID( std::move(pnpID_) ) {}
373
374 std::string toString() const noexcept;
375};
376
377/** https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org.bluetooth.service.battery_service.xml */
379 // TODO
380};
381
382/** https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.temperature_measurement.xml */
384 public:
385 enum Bits : uint8_t {
386 /** bit 0: If set, temperature is in Fahrenheit, otherwise Celsius. */
387 IS_TEMP_FAHRENHEIT = 1,
388 /** bit 1: If set, timestamp field present, otherwise not.. */
389 HAS_TIMESTAMP = 2,
390 /** bit 2: If set, temperature type field present, otherwise not.. */
391 HAS_TEMP_TYPE = 4
392 };
393 /** Bitfields of Bits. 1 byte. */
394 const uint8_t flags;
395
396 /** In Celsius if IS_TEMP_FAHRENHEIT is set, otherwise Fahrenheit. 4 bytes. */
397 const float temperatureValue;
398
399 /** Timestamp, if HAS_TIMESTAMP is set. 7 bytes(!?) here w/o fractions. */
401
402 /** Temperature Type, if HAS_TEMP_TYPE is set: Format ????. 1 byte (!?). */
403 const uint8_t temperature_type;
404
405 static std::shared_ptr<GattTemperatureMeasurement> get(const jau::TROOctets &source) noexcept;
406
407 static std::shared_ptr<GattTemperatureMeasurement> get(const jau::TOctetSlice &source) noexcept {
408 const jau::TROOctets o(source.get_ptr(0), source.size(), jau::lb_endian_t::little);
409 return get(o);
410 }
411
412 GattTemperatureMeasurement(const uint8_t flags_, const float temperatureValue_,
413 const ieee11073::AbsoluteTime &timestamp_, const uint8_t temperature_type_) noexcept
414 : flags(flags_), temperatureValue(temperatureValue_), timestamp(timestamp_), temperature_type(temperature_type_) {}
415
416 bool isFahrenheit() const noexcept { return 0 != ( flags & Bits::IS_TEMP_FAHRENHEIT ); }
417 bool hasTimestamp() const noexcept { return 0 != ( flags & Bits::HAS_TIMESTAMP ); }
418 bool hasTemperatureType() const noexcept { return 0 != ( flags & Bits::HAS_TEMP_TYPE ); }
419
420 std::string toString() const noexcept;
421};
422
423/**@}*/
424
425} // namespace direct_bt
426
427#endif /* GATT_IOCTL_HPP_ */
https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org....
Device Information is a GATT service.
GattDeviceInformationSvc(jau::POctets systemID_, std::string modelNumber_, std::string serialNumber_, std::string firmwareRevision_, std::string hardwareRevision_, std::string softwareRevision_, std::string manufacturer_, jau::POctets regulatoryCertDataList_, std::shared_ptr< GattPnP_ID > pnpID_) noexcept
const std::string serialNumber
Optional.
const std::string firmwareRevision
Optional.
const std::string softwareRevision
Optional.
const std::shared_ptr< GattPnP_ID > pnpID
Optional.
const jau::POctets regulatoryCertDataList
Optional.
const jau::POctets systemID
Optional.
const std::string modelNumber
Optional.
const std::string manufacturer
Optional.
const std::string hardwareRevision
Optional.
Generic Access Service is a mandatory GATT service all peripherals are required to implement.
const AppearanceCat appearance
Characteristic: Mandatory [Read: Mandatory; Write: Excluded; ...].
const std::string deviceName
Characteristic: Mandatory [Read: Mandatory; Write: Optional; ...].
const std::shared_ptr< GattPeriphalPreferredConnectionParameters > prefConnParam
Characteristic: Optional [Read: Mandatory; Write: Excluded; ...].
const std::string peripheralPrivacyFlag
Characteristic: Optional [Read: Mandatory; Write: Conditional; ...].
GattGenericAccessSvc(std::string deviceName_, const AppearanceCat appearance_, std::shared_ptr< GattPeriphalPreferredConnectionParameters > prefConnParam_) noexcept
const std::string reconnectionAdress
Characteristic: Conditional [Read: Excluded; Write: Mandatory; ...].
https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org....
static std::shared_ptr< GattTemperatureMeasurement > get(const jau::TOctetSlice &source) noexcept
const uint8_t flags
Bitfields of Bits.
const ieee11073::AbsoluteTime timestamp
Timestamp, if HAS_TIMESTAMP is set.
GattTemperatureMeasurement(const uint8_t flags_, const float temperatureValue_, const ieee11073::AbsoluteTime &timestamp_, const uint8_t temperature_type_) noexcept
const uint8_t temperature_type
Temperature Type, if HAS_TEMP_TYPE is set: Format ????.
bool hasTemperatureType() const noexcept
const float temperatureValue
In Celsius if IS_TEMP_FAHRENHEIT is set, otherwise Fahrenheit.
date / timestamp format
Definition: DataTypes.hpp:72
Persistent endian aware octet data, i.e.
Definition: octets.hpp:560
Transient endian aware octet data slice, i.e.
Definition: octets.hpp:495
Transient read only and endian aware octet data, i.e.
Definition: octets.hpp:67
@ little
Identifier for little endian, equivalent to endian::little.
std::string GattRequirementSpecToString(const GattRequirementSpec v) noexcept
std::string GattNameToString(const jau::TROOctets &v) noexcept
Converts a GATT Name (not null-terminated) UTF8 to a null-terminated C++ string.
GattAttributeType
Following UUID16 GATT profile attribute types are listed under: BT Core Spec v5.2: Vol 3,...
Definition: GattNumbers.hpp:63
GattCharacteristicProperty
Entry * get(const EUI48 &addr, const std::string &name, AddressNameEntryMatchFunc m) noexcept
Returns a matching BTSecurityRegistry::Entry with the given addr and/or name.
std::string GattCharacteristicTypeToString(const GattCharacteristicType v) noexcept
std::string GattCharacteristicPropertyToString(const GattCharacteristicProperty v) noexcept
std::string GattServiceTypeToString(const GattServiceType v) noexcept
GattServiceType
GATT Service Type, each encapsulating a set of Characteristics.
Definition: GattNumbers.hpp:84
GattCharacteristicType
GATT Assigned Characteristic Attribute Type for single logical value.
@ INCLUDE_DECLARATION
Definition: GattNumbers.hpp:69
@ SECONDARY_SERVICE
Definition: GattNumbers.hpp:66
@ AuxWriteExt
FIXME: extension?
@ ReliableWriteExt
FIXME: extension?
@ LINK_LOSS
The service defines behavior on the device when a link is lost between two devices.
Definition: GattNumbers.hpp:92
@ BATTERY_SERVICE
This service exposes the state of a battery within a device.
Definition: GattNumbers.hpp:98
@ HEALTH_THERMOMETER
This service exposes temperature and other data from a thermometer intended for healthcare and fitnes...
Definition: GattNumbers.hpp:94
@ DEVICE_INFORMATION
This service exposes manufacturer and/or vendor information about a device.
Definition: GattNumbers.hpp:96
@ GENERIC_ACCESS
This service contains generic information about the device.
Definition: GattNumbers.hpp:86
@ GENERIC_ATTRIBUTE
The service allows receiving indications of changed services.
Definition: GattNumbers.hpp:88
@ IMMEDIATE_ALERT
This service exposes a control point to change the peripheral alert behavior.
Definition: GattNumbers.hpp:90
@ if_characteristic_supported
@ if_notify_or_indicate_supported
@ MODEL_NUMBER_STRING
@ RECONNECTION_ADDRESS
@ TEMPERATURE_CELSIUS
Mandatory: sint16 10^-1: Celsius.
@ TEMPERATURE
Mandatory: sint16 10^-2: Celsius.
@ MEASUREMENT_INTERVAL
@ INTERMEDIATE_TEMPERATURE
@ TEMPERATURE_TYPE
Mandatory: 8bit: 1 armpit, 2 body (general), 3(ear), 4 (finger), ...
@ SYSTEM_ID
Mandatory: uint40.
@ PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS
@ MANUFACTURER_NAME_STRING
@ REGULATORY_CERT_DATA_LIST
@ TEMPERATURE_MEASUREMENT
@ SOFTWARE_REVISION_STRING
@ TEMPERATURE_FAHRENHEIT
@ SERIAL_NUMBER_STRING
@ PERIPHERAL_PRIVACY_FLAG
@ HARDWARE_REVISION_STRING
@ FIRMWARE_REVISION_STRING
GattCharacteristicProperty property
std::string toString() const noexcept
jau::darray< GattCharacteristicPropertySpec > propertySpec
Aggregated in PropertySpecIdx order.
GattClientCharacteristicConfigSpec clientConfig
GattCharacteristicType characteristic
GattCharacteristicPropertySpec writeWithAck
GattCharacteristicPropertySpec read
Peripheral Preferred Connection Parameters is a GATT Characteristic.
const uint16_t connectionSupervisionTimeoutMultiplier
mandatory [10..3200]
const uint16_t minConnectionInterval
mandatory [6..3200] x 1.25ms
const uint16_t maxConnectionInterval
mandatory [6..3200] x 1.25ms and >= minConnectionInterval
const uint16_t slaveLatency
mandatory [1..1000]
PnP ID is a GATT Characteristic.
const uint16_t product_version
const uint8_t vendor_id_source
const uint16_t vendor_id
const uint16_t product_id
GattPnP_ID(const uint8_t vendor_id_source_, const uint16_t vendor_id_, const uint16_t product_id_, const uint16_t product_version_) noexcept
jau::darray< GattCharacteristicSpec > characteristics
GattServiceType
const jau::darray< const GattServiceCharacteristic * > GATT_SERVICES
GattCharacteristicProperty
GattRequirementSpec
const GattServiceCharacteristic GATT_HEALTH_THERMOMETER_SRVC
https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Services/org....
const GattServiceCharacteristic GATT_DEVICE_INFORMATION_SRVC
const GattServiceCharacteristic GATT_GENERIC_ACCESS_SRVC
GattCharacteristicType