ble_gatt.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
  16. * contributors to this software may be used to endorse or promote products
  17. * derived from this software without specific prior written permission.
  18. *
  19. * 4. This software must only be used in a processor manufactured by Nordic
  20. * Semiconductor ASA, or in a processor manufactured by a third party that
  21. * is used in combination with a processor manufactured by Nordic Semiconductor.
  22. *
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. /**
  37. @addtogroup BLE_GATT Generic Attribute Profile (GATT) Common
  38. @{
  39. @brief Common definitions and prototypes for the GATT interfaces.
  40. */
  41. #ifndef BLE_GATT_H__
  42. #define BLE_GATT_H__
  43. #include "ble_types.h"
  44. #include "ble_ranges.h"
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /** @addtogroup BLE_GATT_DEFINES Defines
  49. * @{ */
  50. /** @brief Default MTU size. */
  51. #define GATT_MTU_SIZE_DEFAULT 23
  52. /** @brief Only the default MTU size of 23 is currently supported. */
  53. #define GATT_RX_MTU 23
  54. /**@brief Invalid Attribute Handle. */
  55. #define BLE_GATT_HANDLE_INVALID 0x0000
  56. /**@brief First Attribute Handle. */
  57. #define BLE_GATT_HANDLE_START 0x0001
  58. /**@brief Last Attribute Handle. */
  59. #define BLE_GATT_HANDLE_END 0xFFFF
  60. /** @defgroup BLE_GATT_TIMEOUT_SOURCES GATT Timeout sources
  61. * @{ */
  62. #define BLE_GATT_TIMEOUT_SRC_PROTOCOL 0x00 /**< ATT Protocol timeout. */
  63. /** @} */
  64. /** @defgroup BLE_GATT_WRITE_OPS GATT Write operations
  65. * @{ */
  66. #define BLE_GATT_OP_INVALID 0x00 /**< Invalid Operation. */
  67. #define BLE_GATT_OP_WRITE_REQ 0x01 /**< Write Request. */
  68. #define BLE_GATT_OP_WRITE_CMD 0x02 /**< Write Command. */
  69. #define BLE_GATT_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
  70. #define BLE_GATT_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
  71. #define BLE_GATT_OP_EXEC_WRITE_REQ 0x05 /**< Execute Write Request. */
  72. /** @} */
  73. /** @defgroup BLE_GATT_EXEC_WRITE_FLAGS GATT Execute Write flags
  74. * @{ */
  75. #define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL 0x00
  76. #define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE 0x01
  77. /** @} */
  78. /** @defgroup BLE_GATT_HVX_TYPES GATT Handle Value operations
  79. * @{ */
  80. #define BLE_GATT_HVX_INVALID 0x00 /**< Invalid Operation. */
  81. #define BLE_GATT_HVX_NOTIFICATION 0x01 /**< Handle Value Notification. */
  82. #define BLE_GATT_HVX_INDICATION 0x02 /**< Handle Value Indication. */
  83. /** @} */
  84. /** @defgroup BLE_GATT_STATUS_CODES GATT Status Codes
  85. * @{ */
  86. #define BLE_GATT_STATUS_SUCCESS 0x0000 /**< Success. */
  87. #define BLE_GATT_STATUS_UNKNOWN 0x0001 /**< Unknown or not applicable status. */
  88. #define BLE_GATT_STATUS_ATTERR_INVALID 0x0100 /**< ATT Error: Invalid Error Code. */
  89. #define BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101 /**< ATT Error: Invalid Attribute Handle. */
  90. #define BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED 0x0102 /**< ATT Error: Read not permitted. */
  91. #define BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED 0x0103 /**< ATT Error: Write not permitted. */
  92. #define BLE_GATT_STATUS_ATTERR_INVALID_PDU 0x0104 /**< ATT Error: Used in ATT as Invalid PDU. */
  93. #define BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION 0x0105 /**< ATT Error: Authenticated link required. */
  94. #define BLE_GATT_STATUS_ATTERR_REQUEST_NOT_SUPPORTED 0x0106 /**< ATT Error: Used in ATT as Request Not Supported. */
  95. #define BLE_GATT_STATUS_ATTERR_INVALID_OFFSET 0x0107 /**< ATT Error: Offset specified was past the end of the attribute. */
  96. #define BLE_GATT_STATUS_ATTERR_INSUF_AUTHORIZATION 0x0108 /**< ATT Error: Used in ATT as Insufficient Authorisation. */
  97. #define BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL 0x0109 /**< ATT Error: Used in ATT as Prepare Queue Full. */
  98. #define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND 0x010A /**< ATT Error: Used in ATT as Attribute not found. */
  99. #define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_LONG 0x010B /**< ATT Error: Attribute cannot be read or written using read/write blob requests. */
  100. #define BLE_GATT_STATUS_ATTERR_INSUF_ENC_KEY_SIZE 0x010C /**< ATT Error: Encryption key size used is insufficient. */
  101. #define BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH 0x010D /**< ATT Error: Invalid value size. */
  102. #define BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR 0x010E /**< ATT Error: Very unlikely error. */
  103. #define BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION 0x010F /**< ATT Error: Encrypted link required. */
  104. #define BLE_GATT_STATUS_ATTERR_UNSUPPORTED_GROUP_TYPE 0x0110 /**< ATT Error: Attribute type is not a supported grouping attribute. */
  105. #define BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES 0x0111 /**< ATT Error: Encrypted link required. */
  106. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_BEGIN 0x0112 /**< ATT Error: Reserved for Future Use range #1 begin. */
  107. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_END 0x017F /**< ATT Error: Reserved for Future Use range #1 end. */
  108. #define BLE_GATT_STATUS_ATTERR_APP_BEGIN 0x0180 /**< ATT Error: Application range begin. */
  109. #define BLE_GATT_STATUS_ATTERR_APP_END 0x019F /**< ATT Error: Application range end. */
  110. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_BEGIN 0x01A0 /**< ATT Error: Reserved for Future Use range #2 begin. */
  111. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_END 0x01DF /**< ATT Error: Reserved for Future Use range #2 end. */
  112. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_BEGIN 0x01E0 /**< ATT Error: Reserved for Future Use range #3 begin. */
  113. #define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_END 0x01FC /**< ATT Error: Reserved for Future Use range #3 end. */
  114. #define BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR 0x01FD /**< ATT Common Profile and Service Error: Client Characteristic Configuration Descriptor improperly configured. */
  115. #define BLE_GATT_STATUS_ATTERR_CPS_PROC_ALR_IN_PROG 0x01FE /**< ATT Common Profile and Service Error: Procedure Already in Progress. */
  116. #define BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE 0x01FF /**< ATT Common Profile and Service Error: Out Of Range. */
  117. /** @} */
  118. /** @defgroup BLE_GATT_CPF_FORMATS Characteristic Presentation Formats
  119. * @note Found at http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
  120. * @{ */
  121. #define BLE_GATT_CPF_FORMAT_RFU 0x00 /**< Reserved For Future Use. */
  122. #define BLE_GATT_CPF_FORMAT_BOOLEAN 0x01 /**< Boolean. */
  123. #define BLE_GATT_CPF_FORMAT_2BIT 0x02 /**< Unsigned 2-bit integer. */
  124. #define BLE_GATT_CPF_FORMAT_NIBBLE 0x03 /**< Unsigned 4-bit integer. */
  125. #define BLE_GATT_CPF_FORMAT_UINT8 0x04 /**< Unsigned 8-bit integer. */
  126. #define BLE_GATT_CPF_FORMAT_UINT12 0x05 /**< Unsigned 12-bit integer. */
  127. #define BLE_GATT_CPF_FORMAT_UINT16 0x06 /**< Unsigned 16-bit integer. */
  128. #define BLE_GATT_CPF_FORMAT_UINT24 0x07 /**< Unsigned 24-bit integer. */
  129. #define BLE_GATT_CPF_FORMAT_UINT32 0x08 /**< Unsigned 32-bit integer. */
  130. #define BLE_GATT_CPF_FORMAT_UINT48 0x09 /**< Unsigned 48-bit integer. */
  131. #define BLE_GATT_CPF_FORMAT_UINT64 0x0A /**< Unsigned 64-bit integer. */
  132. #define BLE_GATT_CPF_FORMAT_UINT128 0x0B /**< Unsigned 128-bit integer. */
  133. #define BLE_GATT_CPF_FORMAT_SINT8 0x0C /**< Signed 2-bit integer. */
  134. #define BLE_GATT_CPF_FORMAT_SINT12 0x0D /**< Signed 12-bit integer. */
  135. #define BLE_GATT_CPF_FORMAT_SINT16 0x0E /**< Signed 16-bit integer. */
  136. #define BLE_GATT_CPF_FORMAT_SINT24 0x0F /**< Signed 24-bit integer. */
  137. #define BLE_GATT_CPF_FORMAT_SINT32 0x10 /**< Signed 32-bit integer. */
  138. #define BLE_GATT_CPF_FORMAT_SINT48 0x11 /**< Signed 48-bit integer. */
  139. #define BLE_GATT_CPF_FORMAT_SINT64 0x12 /**< Signed 64-bit integer. */
  140. #define BLE_GATT_CPF_FORMAT_SINT128 0x13 /**< Signed 128-bit integer. */
  141. #define BLE_GATT_CPF_FORMAT_FLOAT32 0x14 /**< IEEE-754 32-bit floating point. */
  142. #define BLE_GATT_CPF_FORMAT_FLOAT64 0x15 /**< IEEE-754 64-bit floating point. */
  143. #define BLE_GATT_CPF_FORMAT_SFLOAT 0x16 /**< IEEE-11073 16-bit SFLOAT. */
  144. #define BLE_GATT_CPF_FORMAT_FLOAT 0x17 /**< IEEE-11073 32-bit FLOAT. */
  145. #define BLE_GATT_CPF_FORMAT_DUINT16 0x18 /**< IEEE-20601 format. */
  146. #define BLE_GATT_CPF_FORMAT_UTF8S 0x19 /**< UTF-8 string. */
  147. #define BLE_GATT_CPF_FORMAT_UTF16S 0x1A /**< UTF-16 string. */
  148. #define BLE_GATT_CPF_FORMAT_STRUCT 0x1B /**< Opaque Structure. */
  149. /** @} */
  150. /** @defgroup BLE_GATT_CPF_NAMESPACES GATT Bluetooth Namespaces
  151. * @{
  152. */
  153. #define BLE_GATT_CPF_NAMESPACE_BTSIG 0x01 /**< Bluetooth SIG defined Namespace. */
  154. #define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000 /**< Namespace Description Unknown. */
  155. /** @} */
  156. /** @} */
  157. /** @addtogroup BLE_GATT_STRUCTURES Structures
  158. * @{ */
  159. /**@brief GATT Characteristic Properties. */
  160. typedef struct
  161. {
  162. /* Standard properties */
  163. uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
  164. uint8_t read :1; /**< Reading the value permitted. */
  165. uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
  166. uint8_t write :1; /**< Writing the value with Write Request permitted. */
  167. uint8_t notify :1; /**< Notications of the value permitted. */
  168. uint8_t indicate :1; /**< Indications of the value permitted. */
  169. uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
  170. } ble_gatt_char_props_t;
  171. /**@brief GATT Characteristic Extended Properties. */
  172. typedef struct
  173. {
  174. /* Extended properties */
  175. uint8_t reliable_wr :1; /**< Writing the value with Queued Write operations permitted. */
  176. uint8_t wr_aux :1; /**< Writing the Characteristic User Description descriptor permitted. */
  177. } ble_gatt_char_ext_props_t;
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif // BLE_GATT_H__
  182. /** @} */
  183. /**
  184. @}
  185. @}
  186. */