gatt-api.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. BlueZ D-Bus GATT API description
  2. ********************************
  3. GATT local and remote services share the same high-level D-Bus API. Local
  4. refers to GATT based service exported by a BlueZ plugin or an external
  5. application. Remote refers to GATT services exported by the peer.
  6. BlueZ acts as a proxy, translating ATT operations to D-Bus method calls and
  7. Properties (or the opposite). Support for D-Bus Object Manager is mandatory for
  8. external services to allow seamless GATT declarations (Service, Characteristic
  9. and Descriptors) discovery. Each GATT service tree is required to export a D-Bus
  10. Object Manager at its root that is solely responsible for the objects that
  11. belong to that service.
  12. Releasing a registered GATT service is not defined yet. Any API extension
  13. should avoid breaking the defined API, and if possible keep an unified GATT
  14. remote and local services representation.
  15. Service hierarchy
  16. =================
  17. GATT remote and local service representation. Object path for local services
  18. is freely definable.
  19. External applications implementing local services must register the services
  20. using GattManager1 registration method and must implement the methods and
  21. properties defined in GattService1 interface.
  22. Service org.bluez
  23. Interface org.bluez.GattService1
  24. Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX
  25. Properties string UUID [read-only]
  26. 128-bit service UUID.
  27. boolean Primary [read-only]
  28. Indicates whether or not this GATT service is a
  29. primary service. If false, the service is secondary.
  30. object Device [read-only, optional]
  31. Object path of the Bluetooth device the service
  32. belongs to. Only present on services from remote
  33. devices.
  34. array{object} Includes [read-only, optional]
  35. Array of object paths representing the included
  36. services of this service.
  37. uint16 Handle [read-write, optional] (Server Only)
  38. Service handle. When available in the server it
  39. would attempt to use to allocate into the database
  40. which may fail, to auto allocate the value 0x0000
  41. shall be used which will cause the allocated handle to
  42. be set once registered.
  43. Characteristic hierarchy
  44. ========================
  45. For local GATT defined services, the object paths need to follow the service
  46. path hierarchy and are freely definable.
  47. Service org.bluez
  48. Interface org.bluez.GattCharacteristic1
  49. Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY
  50. Methods array{byte} ReadValue(dict options)
  51. Issues a request to read the value of the
  52. characteristic and returns the value if the
  53. operation was successful.
  54. Possible options: "offset": uint16 offset
  55. "mtu": Exchanged MTU (Server only)
  56. "device": Object Device (Server only)
  57. Possible Errors: org.bluez.Error.Failed
  58. org.bluez.Error.InProgress
  59. org.bluez.Error.NotPermitted
  60. org.bluez.Error.NotAuthorized
  61. org.bluez.Error.InvalidOffset
  62. org.bluez.Error.NotSupported
  63. void WriteValue(array{byte} value, dict options)
  64. Issues a request to write the value of the
  65. characteristic.
  66. Possible options: "offset": Start offset
  67. "type": string
  68. Possible values:
  69. "command": Write without
  70. response
  71. "request": Write with response
  72. "reliable": Reliable Write
  73. "mtu": Exchanged MTU (Server only)
  74. "device": Device path (Server only)
  75. "link": Link type (Server only)
  76. "prepare-authorize": True if prepare
  77. authorization
  78. request
  79. Possible Errors: org.bluez.Error.Failed
  80. org.bluez.Error.InProgress
  81. org.bluez.Error.NotPermitted
  82. org.bluez.Error.InvalidValueLength
  83. org.bluez.Error.NotAuthorized
  84. org.bluez.Error.NotSupported
  85. fd, uint16 AcquireWrite(dict options) [optional]
  86. Acquire file descriptor and MTU for writing. Only
  87. sockets are supported. Usage of WriteValue will be
  88. locked causing it to return NotPermitted error.
  89. For server the MTU returned shall be equal or smaller
  90. than the negotiated MTU.
  91. For client it only works with characteristic that has
  92. WriteAcquired property which relies on
  93. write-without-response Flag.
  94. To release the lock the client shall close the file
  95. descriptor, a HUP is generated in case the device
  96. is disconnected.
  97. Note: the MTU can only be negotiated once and is
  98. symmetric therefore this method may be delayed in
  99. order to have the exchange MTU completed, because of
  100. that the file descriptor is closed during
  101. reconnections as the MTU has to be renegotiated.
  102. Possible options: "device": Object Device (Server only)
  103. "mtu": Exchanged MTU (Server only)
  104. "link": Link type (Server only)
  105. Possible Errors: org.bluez.Error.Failed
  106. org.bluez.Error.NotSupported
  107. fd, uint16 AcquireNotify(dict options) [optional]
  108. Acquire file descriptor and MTU for notify. Only
  109. sockets are support. Usage of StartNotify will be locked
  110. causing it to return NotPermitted error.
  111. For server the MTU returned shall be equal or smaller
  112. than the negotiated MTU.
  113. Only works with characteristic that has NotifyAcquired
  114. which relies on notify Flag and no other client have
  115. called StartNotify.
  116. Notification are enabled during this procedure so
  117. StartNotify shall not be called, any notification
  118. will be dispatched via file descriptor therefore the
  119. Value property is not affected during the time where
  120. notify has been acquired.
  121. To release the lock the client shall close the file
  122. descriptor, a HUP is generated in case the device
  123. is disconnected.
  124. Note: the MTU can only be negotiated once and is
  125. symmetric therefore this method may be delayed in
  126. order to have the exchange MTU completed, because of
  127. that the file descriptor is closed during
  128. reconnections as the MTU has to be renegotiated.
  129. Possible options: "device": Object Device (Server only)
  130. "mtu": Exchanged MTU (Server only)
  131. "link": Link type (Server only)
  132. Possible Errors: org.bluez.Error.Failed
  133. org.bluez.Error.NotSupported
  134. void StartNotify()
  135. Starts a notification session from this characteristic
  136. if it supports value notifications or indications.
  137. Possible Errors: org.bluez.Error.Failed
  138. org.bluez.Error.NotPermitted
  139. org.bluez.Error.InProgress
  140. org.bluez.Error.NotConnected
  141. org.bluez.Error.NotSupported
  142. void StopNotify()
  143. This method will cancel any previous StartNotify
  144. transaction. Note that notifications from a
  145. characteristic are shared between sessions thus
  146. calling StopNotify will release a single session.
  147. Possible Errors: org.bluez.Error.Failed
  148. void Confirm() [optional] (Server only)
  149. This method doesn't expect a reply so it is just a
  150. confirmation that value was received.
  151. Possible Errors: org.bluez.Error.Failed
  152. Properties string UUID [read-only]
  153. 128-bit characteristic UUID.
  154. object Service [read-only]
  155. Object path of the GATT service the characteristic
  156. belongs to.
  157. array{byte} Value [read-only, optional]
  158. The cached value of the characteristic. This property
  159. gets updated only after a successful read request and
  160. when a notification or indication is received, upon
  161. which a PropertiesChanged signal will be emitted.
  162. boolean WriteAcquired [read-only, optional]
  163. True, if this characteristic has been acquired by any
  164. client using AcquireWrite.
  165. For client properties is ommited in case
  166. 'write-without-response' flag is not set.
  167. For server the presence of this property indicates
  168. that AcquireWrite is supported.
  169. boolean NotifyAcquired [read-only, optional]
  170. True, if this characteristic has been acquired by any
  171. client using AcquireNotify.
  172. For client this properties is ommited in case 'notify'
  173. flag is not set.
  174. For server the presence of this property indicates
  175. that AcquireNotify is supported.
  176. boolean Notifying [read-only, optional]
  177. True, if notifications or indications on this
  178. characteristic are currently enabled.
  179. array{string} Flags [read-only]
  180. Defines how the characteristic value can be used. See
  181. Core spec "Table 3.5: Characteristic Properties bit
  182. field", and "Table 3.8: Characteristic Extended
  183. Properties bit field".
  184. The "x-notify" and "x-indicate" flags restrict access
  185. to notifications and indications by imposing write
  186. restrictions on a characteristic's client
  187. characteristic configuration descriptor.
  188. Allowed values:
  189. "broadcast"
  190. "read"
  191. "write-without-response"
  192. "write"
  193. "notify"
  194. "indicate"
  195. "authenticated-signed-writes"
  196. "extended-properties"
  197. "reliable-write"
  198. "writable-auxiliaries"
  199. "encrypt-read"
  200. "encrypt-write"
  201. "encrypt-notify" (Server only)
  202. "encrypt-indicate" (Server only)
  203. "encrypt-authenticated-read"
  204. "encrypt-authenticated-write"
  205. "encrypt-authenticated-notify" (Server only)
  206. "encrypt-authenticated-indicate" (Server only)
  207. "secure-read" (Server only)
  208. "secure-write" (Server only)
  209. "secure-notify" (Server only)
  210. "secure-indicate" (Server only)
  211. "authorize"
  212. uint16 Handle [read-write, optional] (Server Only)
  213. Characteristic handle. When available in the server it
  214. would attempt to use to allocate into the database
  215. which may fail, to auto allocate the value 0x0000
  216. shall be used which will cause the allocated handle to
  217. be set once registered.
  218. uint16 MTU [read-only]
  219. Characteristic MTU, this is valid both for ReadValue
  220. and WriteValue but either method can use long
  221. procedures when supported.
  222. Characteristic Descriptors hierarchy
  223. ====================================
  224. Local or remote GATT characteristic descriptors hierarchy.
  225. Service org.bluez
  226. Interface org.bluez.GattDescriptor1
  227. Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ
  228. Methods array{byte} ReadValue(dict flags)
  229. Issues a request to read the value of the
  230. characteristic and returns the value if the
  231. operation was successful.
  232. Possible options: "offset": Start offset
  233. "device": Device path (Server only)
  234. "link": Link type (Server only)
  235. Possible Errors: org.bluez.Error.Failed
  236. org.bluez.Error.InProgress
  237. org.bluez.Error.NotPermitted
  238. org.bluez.Error.NotAuthorized
  239. org.bluez.Error.NotSupported
  240. void WriteValue(array{byte} value, dict flags)
  241. Issues a request to write the value of the
  242. characteristic.
  243. Possible options: "offset": Start offset
  244. "device": Device path (Server only)
  245. "link": Link type (Server only)
  246. "prepare-authorize": boolean Is prepare
  247. authorization
  248. request
  249. Possible Errors: org.bluez.Error.Failed
  250. org.bluez.Error.InProgress
  251. org.bluez.Error.NotPermitted
  252. org.bluez.Error.InvalidValueLength
  253. org.bluez.Error.NotAuthorized
  254. org.bluez.Error.NotSupported
  255. Properties string UUID [read-only]
  256. 128-bit descriptor UUID.
  257. object Characteristic [read-only]
  258. Object path of the GATT characteristic the descriptor
  259. belongs to.
  260. array{byte} Value [read-only, optional]
  261. The cached value of the descriptor. This property
  262. gets updated only after a successful read request, upon
  263. which a PropertiesChanged signal will be emitted.
  264. array{string} Flags [read-only]
  265. Defines how the descriptor value can be used.
  266. Possible values:
  267. "read"
  268. "write"
  269. "encrypt-read"
  270. "encrypt-write"
  271. "encrypt-authenticated-read"
  272. "encrypt-authenticated-write"
  273. "secure-read" (Server Only)
  274. "secure-write" (Server Only)
  275. "authorize"
  276. uint16 Handle [read-write, optional] (Server Only)
  277. Characteristic handle. When available in the server it
  278. would attempt to use to allocate into the database
  279. which may fail, to auto allocate the value 0x0000
  280. shall be used which will cause the allocated handle to
  281. be set once registered.
  282. GATT Profile hierarchy
  283. =====================
  284. Local profile (GATT client) instance. By registering this type of object
  285. an application effectively indicates support for a specific GATT profile
  286. and requests automatic connections to be established to devices
  287. supporting it.
  288. Service <application dependent>
  289. Interface org.bluez.GattProfile1
  290. Object path <application dependent>
  291. Methods void Release()
  292. This method gets called when the service daemon
  293. unregisters the profile. The profile can use it to
  294. do cleanup tasks. There is no need to unregister the
  295. profile, because when this method gets called it has
  296. already been unregistered.
  297. Properties array{string} UUIDs [read-only]
  298. 128-bit GATT service UUIDs to auto connect.
  299. GATT Manager hierarchy
  300. ======================
  301. GATT Manager allows external applications to register GATT services and
  302. profiles.
  303. Registering a profile allows applications to subscribe to *remote* services.
  304. These must implement the GattProfile1 interface defined above.
  305. Registering a service allows applications to publish a *local* GATT service,
  306. which then becomes available to remote devices. A GATT service is represented by
  307. a D-Bus object hierarchy where the root node corresponds to a service and the
  308. child nodes represent characteristics and descriptors that belong to that
  309. service. Each node must implement one of GattService1, GattCharacteristic1,
  310. or GattDescriptor1 interfaces described above, based on the attribute it
  311. represents. Each node must also implement the standard D-Bus Properties
  312. interface to expose their properties. These objects collectively represent a
  313. GATT service definition.
  314. To make service registration simple, BlueZ requires that all objects that belong
  315. to a GATT service be grouped under a D-Bus Object Manager that solely manages
  316. the objects of that service. Hence, the standard DBus.ObjectManager interface
  317. must be available on the root service path. An example application hierarchy
  318. containing two separate GATT services may look like this:
  319. -> /com/example
  320. | - org.freedesktop.DBus.ObjectManager
  321. |
  322. -> /com/example/service0
  323. | | - org.freedesktop.DBus.Properties
  324. | | - org.bluez.GattService1
  325. | |
  326. | -> /com/example/service0/char0
  327. | | - org.freedesktop.DBus.Properties
  328. | | - org.bluez.GattCharacteristic1
  329. | |
  330. | -> /com/example/service0/char1
  331. | | - org.freedesktop.DBus.Properties
  332. | | - org.bluez.GattCharacteristic1
  333. | |
  334. | -> /com/example/service0/char1/desc0
  335. | - org.freedesktop.DBus.Properties
  336. | - org.bluez.GattDescriptor1
  337. |
  338. -> /com/example/service1
  339. | - org.freedesktop.DBus.Properties
  340. | - org.bluez.GattService1
  341. |
  342. -> /com/example/service1/char0
  343. - org.freedesktop.DBus.Properties
  344. - org.bluez.GattCharacteristic1
  345. When a service is registered, BlueZ will automatically obtain information about
  346. all objects using the service's Object Manager. Once a service has been
  347. registered, the objects of a service should not be removed. If BlueZ receives an
  348. InterfacesRemoved signal from a service's Object Manager, it will immediately
  349. unregister the service. Similarly, if the application disconnects from the bus,
  350. all of its registered services will be automatically unregistered.
  351. InterfacesAdded signals will be ignored.
  352. Examples:
  353. - Client
  354. test/example-gatt-client
  355. client/bluetoothctl
  356. - Server
  357. test/example-gatt-server
  358. tools/gatt-service
  359. Service org.bluez
  360. Interface org.bluez.GattManager1
  361. Object path [variable prefix]/{hci0,hci1,...}
  362. Methods void RegisterApplication(object application, dict options)
  363. Registers a local GATT services hierarchy as described
  364. above (GATT Server) and/or GATT profiles (GATT Client).
  365. The application object path together with the D-Bus
  366. system bus connection ID define the identification of
  367. the application registering a GATT based
  368. service or profile.
  369. Possible errors: org.bluez.Error.InvalidArguments
  370. org.bluez.Error.AlreadyExists
  371. void UnregisterApplication(object application)
  372. This unregisters the services that has been
  373. previously registered. The object path parameter
  374. must match the same value that has been used
  375. on registration.
  376. Possible errors: org.bluez.Error.InvalidArguments
  377. org.bluez.Error.DoesNotExist