Blame doc/gatt-api.txt

Packit 34410b
BlueZ D-Bus GATT API description
Packit 34410b
********************************
Packit 34410b
Packit 34410b
GATT local and remote services share the same high-level D-Bus API. Local
Packit 34410b
refers to GATT based service exported by a BlueZ plugin or an external
Packit 34410b
application. Remote refers to GATT services exported by the peer.
Packit 34410b
Packit 34410b
BlueZ acts as a proxy, translating ATT operations to D-Bus method calls and
Packit 34410b
Properties (or the opposite). Support for D-Bus Object Manager is mandatory for
Packit 34410b
external services to allow seamless GATT declarations (Service, Characteristic
Packit 34410b
and Descriptors) discovery. Each GATT service tree is required to export a D-Bus
Packit 34410b
Object Manager at its root that is solely responsible for the objects that
Packit 34410b
belong to that service.
Packit 34410b
Packit 34410b
Releasing a registered GATT service is not defined yet. Any API extension
Packit 34410b
should avoid breaking the defined API, and if possible keep an unified GATT
Packit 34410b
remote and local services representation.
Packit 34410b
Packit 34410b
Service hierarchy
Packit 34410b
=================
Packit 34410b
Packit 34410b
GATT remote and local service representation. Object path for local services
Packit 34410b
is freely definable.
Packit 34410b
Packit 34410b
External applications implementing local services must register the services
Packit 34410b
using GattManager1 registration method and must implement the methods and
Packit 34410b
properties defined in GattService1 interface.
Packit 34410b
Packit 34410b
Service		org.bluez
Packit 34410b
Interface	org.bluez.GattService1
Packit 34410b
Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX
Packit 34410b
Packit 34410b
Properties	string UUID [read-only]
Packit 34410b
Packit 34410b
			128-bit service UUID.
Packit 34410b
Packit 34410b
		boolean Primary [read-only]
Packit 34410b
Packit 34410b
			Indicates whether or not this GATT service is a
Packit 34410b
			primary service. If false, the service is secondary.
Packit 34410b
Packit 34410b
		object Device [read-only, optional]
Packit 34410b
Packit 34410b
			Object path of the Bluetooth device the service
Packit 34410b
			belongs to. Only present on services from remote
Packit 34410b
			devices.
Packit 34410b
Packit 34410b
		array{object} Includes [read-only, optional]
Packit 34410b
Packit 34410b
			Array of object paths representing the included
Packit 34410b
			services of this service.
Packit 34410b
Packit 34410b
		uint16 Handle [read-write, optional] (Server Only)
Packit 34410b
Packit 34410b
			Service handle. When available in the server it
Packit 34410b
			would attempt to use to allocate into the database
Packit 34410b
			which may fail, to auto allocate the value 0x0000
Packit 34410b
			shall be used which will cause the allocated handle to
Packit 34410b
			be set once registered.
Packit 34410b
Packit 34410b
Packit 34410b
Characteristic hierarchy
Packit 34410b
========================
Packit 34410b
Packit 34410b
For local GATT defined services, the object paths need to follow the service
Packit 34410b
path hierarchy and are freely definable.
Packit 34410b
Packit 34410b
Service		org.bluez
Packit 34410b
Interface	org.bluez.GattCharacteristic1
Packit 34410b
Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY
Packit 34410b
Packit 34410b
Methods		array{byte} ReadValue(dict options)
Packit 34410b
Packit 34410b
			Issues a request to read the value of the
Packit 34410b
			characteristic and returns the value if the
Packit 34410b
			operation was successful.
Packit 34410b
Packit 34410b
			Possible options: "offset": uint16 offset
Packit 34410b
					  "mtu": Exchanged MTU (Server only)
Packit 34410b
					  "device": Object Device (Server only)
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.InProgress
Packit 34410b
					 org.bluez.Error.NotPermitted
Packit 34410b
					 org.bluez.Error.NotAuthorized
Packit 34410b
					 org.bluez.Error.InvalidOffset
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		void WriteValue(array{byte} value, dict options)
Packit 34410b
Packit 34410b
			Issues a request to write the value of the
Packit 34410b
			characteristic.
Packit 34410b
Packit 34410b
			Possible options: "offset": Start offset
Packit 34410b
					  "type": string
Packit 34410b
						Possible values:
Packit 34410b
						"command": Write without
Packit 34410b
						response
Packit 34410b
						"request": Write with response
Packit 34410b
						"reliable": Reliable Write
Packit 34410b
					  "mtu": Exchanged MTU (Server only)
Packit 34410b
					  "device": Device path (Server only)
Packit 34410b
					  "link": Link type (Server only)
Packit 34410b
					  "prepare-authorize": True if prepare
Packit 34410b
							       authorization
Packit 34410b
							       request
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.InProgress
Packit 34410b
					 org.bluez.Error.NotPermitted
Packit 34410b
					 org.bluez.Error.InvalidValueLength
Packit 34410b
					 org.bluez.Error.NotAuthorized
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		fd, uint16 AcquireWrite(dict options) [optional]
Packit 34410b
Packit 34410b
			Acquire file descriptor and MTU for writing. Only
Packit 34410b
			sockets are supported. Usage of WriteValue will be
Packit 34410b
			locked causing it to return NotPermitted error.
Packit 34410b
Packit 34410b
			For server the MTU returned shall be equal or smaller
Packit 34410b
			than the negotiated MTU.
Packit 34410b
Packit 34410b
			For client it only works with characteristic that has
Packit 34410b
			WriteAcquired property which relies on
Packit 34410b
			write-without-response Flag.
Packit 34410b
Packit 34410b
			To release the lock the client shall close the file
Packit 34410b
			descriptor, a HUP is generated in case the device
Packit 34410b
			is disconnected.
Packit 34410b
Packit 34410b
			Note: the MTU can only be negotiated once and is
Packit 34410b
			symmetric therefore this method may be delayed in
Packit 34410b
			order to have the exchange MTU completed, because of
Packit 34410b
			that the file descriptor is closed during
Packit 34410b
			reconnections as the MTU has to be renegotiated.
Packit 34410b
Packit 34410b
			Possible options: "device": Object Device (Server only)
Packit 34410b
					  "mtu": Exchanged MTU (Server only)
Packit 34410b
					  "link": Link type (Server only)
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		fd, uint16 AcquireNotify(dict options) [optional]
Packit 34410b
Packit 34410b
			Acquire file descriptor and MTU for notify. Only
Packit 34410b
			sockets are support. Usage of StartNotify will be locked
Packit 34410b
			causing it to return NotPermitted error.
Packit 34410b
Packit 34410b
			For server the MTU returned shall be equal or smaller
Packit 34410b
			than the negotiated MTU.
Packit 34410b
Packit 34410b
			Only works with characteristic that has NotifyAcquired
Packit 34410b
			which relies on notify Flag and no other client have
Packit 34410b
			called StartNotify.
Packit 34410b
Packit 34410b
			Notification are enabled during this procedure so
Packit 34410b
			StartNotify shall not be called, any notification
Packit 34410b
			will be dispatched via file descriptor therefore the
Packit 34410b
			Value property is not affected during the time where
Packit 34410b
			notify has been acquired.
Packit 34410b
Packit 34410b
			To release the lock the client shall close the file
Packit 34410b
			descriptor, a HUP is generated in case the device
Packit 34410b
			is disconnected.
Packit 34410b
Packit 34410b
			Note: the MTU can only be negotiated once and is
Packit 34410b
			symmetric therefore this method may be delayed in
Packit 34410b
			order to have the exchange MTU completed, because of
Packit 34410b
			that the file descriptor is closed during
Packit 34410b
			reconnections as the MTU has to be renegotiated.
Packit 34410b
Packit 34410b
			Possible options: "device": Object Device (Server only)
Packit 34410b
					  "mtu": Exchanged MTU (Server only)
Packit 34410b
					  "link": Link type (Server only)
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		void StartNotify()
Packit 34410b
Packit 34410b
			Starts a notification session from this characteristic
Packit 34410b
			if it supports value notifications or indications.
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.NotPermitted
Packit 34410b
					 org.bluez.Error.InProgress
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		void StopNotify()
Packit 34410b
Packit 34410b
			This method will cancel any previous StartNotify
Packit 34410b
			transaction. Note that notifications from a
Packit 34410b
			characteristic are shared between sessions thus
Packit 34410b
			calling StopNotify will release a single session.
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
Packit 34410b
		void Confirm() [optional] (Server only)
Packit 34410b
Packit 34410b
			This method doesn't expect a reply so it is just a
Packit 34410b
			confirmation that value was received.
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
Packit 34410b
Properties	string UUID [read-only]
Packit 34410b
Packit 34410b
			128-bit characteristic UUID.
Packit 34410b
Packit 34410b
		object Service [read-only]
Packit 34410b
Packit 34410b
			Object path of the GATT service the characteristic
Packit 34410b
			belongs to.
Packit 34410b
Packit 34410b
		array{byte} Value [read-only, optional]
Packit 34410b
Packit 34410b
			The cached value of the characteristic. This property
Packit 34410b
			gets updated only after a successful read request and
Packit 34410b
			when a notification or indication is received, upon
Packit 34410b
			which a PropertiesChanged signal will be emitted.
Packit 34410b
Packit 34410b
		boolean WriteAcquired [read-only, optional]
Packit 34410b
Packit 34410b
			True, if this characteristic has been acquired by any
Packit 34410b
			client using AcquireWrite.
Packit 34410b
Packit 34410b
			For client properties is ommited in case
Packit 34410b
			'write-without-response' flag is not set.
Packit 34410b
Packit 34410b
			For server the presence of this property indicates
Packit 34410b
			that AcquireWrite is supported.
Packit 34410b
Packit 34410b
		boolean NotifyAcquired [read-only, optional]
Packit 34410b
Packit 34410b
			True, if this characteristic has been acquired by any
Packit 34410b
			client using AcquireNotify.
Packit 34410b
Packit 34410b
			For client this properties is ommited in case 'notify'
Packit 34410b
			flag is not set.
Packit 34410b
Packit 34410b
			For server the presence of this property indicates
Packit 34410b
			that AcquireNotify is supported.
Packit 34410b
Packit 34410b
		boolean Notifying [read-only, optional]
Packit 34410b
Packit 34410b
			True, if notifications or indications on this
Packit 34410b
			characteristic are currently enabled.
Packit 34410b
Packit 34410b
		array{string} Flags [read-only]
Packit 34410b
Packit 34410b
			Defines how the characteristic value can be used. See
Packit 34410b
			Core spec "Table 3.5: Characteristic Properties bit
Packit 34410b
			field", and "Table 3.8: Characteristic Extended
Packit 34410b
			Properties bit field". Allowed values:
Packit 34410b
Packit 34410b
				"broadcast"
Packit 34410b
				"read"
Packit 34410b
				"write-without-response"
Packit 34410b
				"write"
Packit 34410b
				"notify"
Packit 34410b
				"indicate"
Packit 34410b
				"authenticated-signed-writes"
Packit 34410b
				"extended-properties"
Packit 34410b
				"reliable-write"
Packit 34410b
				"writable-auxiliaries"
Packit 34410b
				"encrypt-read"
Packit 34410b
				"encrypt-write"
Packit 34410b
				"encrypt-authenticated-read"
Packit 34410b
				"encrypt-authenticated-write"
Packit 34410b
				"secure-read" (Server only)
Packit 34410b
				"secure-write" (Server only)
Packit 34410b
				"authorize"
Packit 34410b
Packit 34410b
		uint16 Handle [read-write, optional] (Server Only)
Packit 34410b
Packit 34410b
			Characteristic handle. When available in the server it
Packit 34410b
			would attempt to use to allocate into the database
Packit 34410b
			which may fail, to auto allocate the value 0x0000
Packit 34410b
			shall be used which will cause the allocated handle to
Packit 34410b
			be set once registered.
Packit 34410b
Packit 34410b
Characteristic Descriptors hierarchy
Packit 34410b
====================================
Packit 34410b
Packit 34410b
Local or remote GATT characteristic descriptors hierarchy.
Packit 34410b
Packit 34410b
Service		org.bluez
Packit 34410b
Interface	org.bluez.GattDescriptor1
Packit 34410b
Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ
Packit 34410b
Packit 34410b
Methods		array{byte} ReadValue(dict flags)
Packit 34410b
Packit 34410b
			Issues a request to read the value of the
Packit 34410b
			characteristic and returns the value if the
Packit 34410b
			operation was successful.
Packit 34410b
Packit 34410b
			Possible options: "offset": Start offset
Packit 34410b
					  "device": Device path (Server only)
Packit 34410b
					  "link": Link type (Server only)
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.InProgress
Packit 34410b
					 org.bluez.Error.NotPermitted
Packit 34410b
					 org.bluez.Error.NotAuthorized
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
		void WriteValue(array{byte} value, dict flags)
Packit 34410b
Packit 34410b
			Issues a request to write the value of the
Packit 34410b
			characteristic.
Packit 34410b
Packit 34410b
			Possible options: "offset": Start offset
Packit 34410b
					  "device": Device path (Server only)
Packit 34410b
					  "link": Link type (Server only)
Packit 34410b
					  "prepare-authorize": boolean Is prepare
Packit 34410b
							       authorization
Packit 34410b
							       request
Packit 34410b
Packit 34410b
			Possible Errors: org.bluez.Error.Failed
Packit 34410b
					 org.bluez.Error.InProgress
Packit 34410b
					 org.bluez.Error.NotPermitted
Packit 34410b
					 org.bluez.Error.InvalidValueLength
Packit 34410b
					 org.bluez.Error.NotAuthorized
Packit 34410b
					 org.bluez.Error.NotSupported
Packit 34410b
Packit 34410b
Properties	string UUID [read-only]
Packit 34410b
Packit 34410b
			128-bit descriptor UUID.
Packit 34410b
Packit 34410b
		object Characteristic [read-only]
Packit 34410b
Packit 34410b
			Object path of the GATT characteristic the descriptor
Packit 34410b
			belongs to.
Packit 34410b
Packit 34410b
		array{byte} Value [read-only, optional]
Packit 34410b
Packit 34410b
			The cached value of the descriptor. This property
Packit 34410b
			gets updated only after a successful read request, upon
Packit 34410b
			which a PropertiesChanged signal will be emitted.
Packit 34410b
Packit 34410b
		array{string} Flags [read-only]
Packit 34410b
Packit 34410b
			Defines how the descriptor value can be used.
Packit 34410b
Packit 34410b
			Possible values:
Packit 34410b
Packit 34410b
				"read"
Packit 34410b
				"write"
Packit 34410b
				"encrypt-read"
Packit 34410b
				"encrypt-write"
Packit 34410b
				"encrypt-authenticated-read"
Packit 34410b
				"encrypt-authenticated-write"
Packit 34410b
				"secure-read" (Server Only)
Packit 34410b
				"secure-write" (Server Only)
Packit 34410b
				"authorize"
Packit 34410b
Packit 34410b
		uint16 Handle [read-write, optional] (Server Only)
Packit 34410b
Packit 34410b
			Characteristic handle. When available in the server it
Packit 34410b
			would attempt to use to allocate into the database
Packit 34410b
			which may fail, to auto allocate the value 0x0000
Packit 34410b
			shall be used which will cause the allocated handle to
Packit 34410b
			be set once registered.
Packit 34410b
Packit 34410b
GATT Profile hierarchy
Packit 34410b
=====================
Packit 34410b
Packit 34410b
Local profile (GATT client) instance. By registering this type of object
Packit 34410b
an application effectively indicates support for a specific GATT profile
Packit 34410b
and requests automatic connections to be established to devices
Packit 34410b
supporting it.
Packit 34410b
Packit 34410b
Service		<application dependent>
Packit 34410b
Interface	org.bluez.GattProfile1
Packit 34410b
Object path	<application dependent>
Packit 34410b
Packit 34410b
Methods		void Release()
Packit 34410b
Packit 34410b
			This method gets called when the service daemon
Packit 34410b
			unregisters the profile. The profile can use it to
Packit 34410b
			do cleanup tasks. There is no need to unregister the
Packit 34410b
			profile, because when this method gets called it has
Packit 34410b
			already been unregistered.
Packit 34410b
Packit 34410b
Properties	array{string} UUIDs [read-only]
Packit 34410b
Packit 34410b
			128-bit GATT service UUIDs to auto connect.
Packit 34410b
Packit 34410b
Packit 34410b
GATT Manager hierarchy
Packit 34410b
======================
Packit 34410b
Packit 34410b
GATT Manager allows external applications to register GATT services and
Packit 34410b
profiles.
Packit 34410b
Packit 34410b
Registering a profile allows applications to subscribe to *remote* services.
Packit 34410b
These must implement the GattProfile1 interface defined above.
Packit 34410b
Packit 34410b
Registering a service allows applications to publish a *local* GATT service,
Packit 34410b
which then becomes available to remote devices. A GATT service is represented by
Packit 34410b
a D-Bus object hierarchy where the root node corresponds to a service and the
Packit 34410b
child nodes represent characteristics and descriptors that belong to that
Packit 34410b
service. Each node must implement one of GattService1, GattCharacteristic1,
Packit 34410b
or GattDescriptor1 interfaces described above, based on the attribute it
Packit 34410b
represents. Each node must also implement the standard D-Bus Properties
Packit 34410b
interface to expose their properties. These objects collectively represent a
Packit 34410b
GATT service definition.
Packit 34410b
Packit 34410b
To make service registration simple, BlueZ requires that all objects that belong
Packit 34410b
to a GATT service be grouped under a D-Bus Object Manager that solely manages
Packit 34410b
the objects of that service. Hence, the standard DBus.ObjectManager interface
Packit 34410b
must be available on the root service path. An example application hierarchy
Packit 34410b
containing two separate GATT services may look like this:
Packit 34410b
Packit 34410b
-> /com/example
Packit 34410b
  |   - org.freedesktop.DBus.ObjectManager
Packit 34410b
  |
Packit 34410b
  -> /com/example/service0
Packit 34410b
  | |   - org.freedesktop.DBus.Properties
Packit 34410b
  | |   - org.bluez.GattService1
Packit 34410b
  | |
Packit 34410b
  | -> /com/example/service0/char0
Packit 34410b
  | |     - org.freedesktop.DBus.Properties
Packit 34410b
  | |     - org.bluez.GattCharacteristic1
Packit 34410b
  | |
Packit 34410b
  | -> /com/example/service0/char1
Packit 34410b
  |   |   - org.freedesktop.DBus.Properties
Packit 34410b
  |   |   - org.bluez.GattCharacteristic1
Packit 34410b
  |   |
Packit 34410b
  |   -> /com/example/service0/char1/desc0
Packit 34410b
  |       - org.freedesktop.DBus.Properties
Packit 34410b
  |       - org.bluez.GattDescriptor1
Packit 34410b
  |
Packit 34410b
  -> /com/example/service1
Packit 34410b
    |   - org.freedesktop.DBus.Properties
Packit 34410b
    |   - org.bluez.GattService1
Packit 34410b
    |
Packit 34410b
    -> /com/example/service1/char0
Packit 34410b
        - org.freedesktop.DBus.Properties
Packit 34410b
        - org.bluez.GattCharacteristic1
Packit 34410b
Packit 34410b
When a service is registered, BlueZ will automatically obtain information about
Packit 34410b
all objects using the service's Object Manager. Once a service has been
Packit 34410b
registered, the objects of a service should not be removed. If BlueZ receives an
Packit 34410b
InterfacesRemoved signal from a service's Object Manager, it will immediately
Packit 34410b
unregister the service. Similarly, if the application disconnects from the bus,
Packit 34410b
all of its registered services will be automatically unregistered.
Packit 34410b
InterfacesAdded signals will be ignored.
Packit 34410b
Packit 34410b
Examples:
Packit 34410b
	- Client
Packit 34410b
		test/example-gatt-client
Packit 34410b
		client/bluetoothctl
Packit 34410b
	- Server
Packit 34410b
		test/example-gatt-server
Packit 34410b
		tools/gatt-service
Packit 34410b
Packit 34410b
Packit 34410b
Service		org.bluez
Packit 34410b
Interface	org.bluez.GattManager1
Packit 34410b
Object path	[variable prefix]/{hci0,hci1,...}
Packit 34410b
Packit 34410b
Methods		void RegisterApplication(object application, dict options)
Packit 34410b
Packit 34410b
			Registers a local GATT services hierarchy as described
Packit 34410b
			above (GATT Server) and/or GATT profiles (GATT Client).
Packit 34410b
Packit 34410b
			The application object path together with the D-Bus
Packit 34410b
			system bus connection ID define the identification of
Packit 34410b
			the application registering a GATT based
Packit 34410b
			service or profile.
Packit 34410b
Packit 34410b
			Possible errors: org.bluez.Error.InvalidArguments
Packit 34410b
					 org.bluez.Error.AlreadyExists
Packit 34410b
Packit 34410b
		void UnregisterApplication(object application)
Packit 34410b
Packit 34410b
			This unregisters the services that has been
Packit 34410b
			previously registered. The object path parameter
Packit 34410b
			must match the same value that has been used
Packit 34410b
			on registration.
Packit 34410b
Packit 34410b
			Possible errors: org.bluez.Error.InvalidArguments
Packit 34410b
					 org.bluez.Error.DoesNotExist