ble_srv_common.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /**
  2. * Copyright (c) 2012 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /** @file
  41. *
  42. * @defgroup ble_sdk_srv_common Common service definitions
  43. * @{
  44. * @ingroup ble_sdk_srv
  45. * @brief Constants, type definitions, and functions that are common to all services.
  46. */
  47. #ifndef BLE_SRV_COMMON_H__
  48. #define BLE_SRV_COMMON_H__
  49. #include <stdint.h>
  50. #include <stdbool.h>
  51. #include "ble_types.h"
  52. #include "app_util.h"
  53. #include "ble.h"
  54. #include "ble_gap.h"
  55. #include "ble_gatt.h"
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. /** @defgroup UUID_SERVICES Service UUID definitions
  60. * @{ */
  61. #define BLE_UUID_ALERT_NOTIFICATION_SERVICE 0x1811 /**< Alert Notification service UUID. */
  62. #define BLE_UUID_BATTERY_SERVICE 0x180F /**< Battery service UUID. */
  63. #define BLE_UUID_BLOOD_PRESSURE_SERVICE 0x1810 /**< Blood Pressure service UUID. */
  64. #define BLE_UUID_CURRENT_TIME_SERVICE 0x1805 /**< Current Time service UUID. */
  65. #define BLE_UUID_CYCLING_SPEED_AND_CADENCE 0x1816 /**< Cycling Speed and Cadence service UUID. */
  66. #define BLE_UUID_LOCATION_AND_NAVIGATION_SERVICE 0x1819 /**< Location and Navigation service UUID. */
  67. #define BLE_UUID_DEVICE_INFORMATION_SERVICE 0x180A /**< Device Information service UUID. */
  68. #define BLE_UUID_GLUCOSE_SERVICE 0x1808 /**< Glucose service UUID. */
  69. #define BLE_UUID_HEALTH_THERMOMETER_SERVICE 0x1809 /**< Health Thermometer service UUID. */
  70. #define BLE_UUID_HEART_RATE_SERVICE 0x180D /**< Heart Rate service UUID. */
  71. #define BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE 0x1812 /**< Human Interface Device service UUID. */
  72. #define BLE_UUID_IMMEDIATE_ALERT_SERVICE 0x1802 /**< Immediate Alert service UUID. */
  73. #define BLE_UUID_LINK_LOSS_SERVICE 0x1803 /**< Link Loss service UUID. */
  74. #define BLE_UUID_NEXT_DST_CHANGE_SERVICE 0x1807 /**< Next Dst Change service UUID. */
  75. #define BLE_UUID_PHONE_ALERT_STATUS_SERVICE 0x180E /**< Phone Alert Status service UUID. */
  76. #define BLE_UUID_REFERENCE_TIME_UPDATE_SERVICE 0x1806 /**< Reference Time Update service UUID. */
  77. #define BLE_UUID_RUNNING_SPEED_AND_CADENCE 0x1814 /**< Running Speed and Cadence service UUID. */
  78. #define BLE_UUID_SCAN_PARAMETERS_SERVICE 0x1813 /**< Scan Parameters service UUID. */
  79. #define BLE_UUID_TX_POWER_SERVICE 0x1804 /**< TX Power service UUID. */
  80. #define BLE_UUID_IPSP_SERVICE 0x1820 /**< Internet Protocol Support service UUID. */
  81. #define BLE_UUID_BMS_SERVICE 0x181E /**< BOND MANAGEMENT service UUID*/
  82. #define BLE_UUID_CGM_SERVICE 0x181F /**< Continuous Glucose Monitoring service UUID*/
  83. #define BLE_UUID_PLX_SERVICE 0x1822 /**< Pulse Oximeter Service UUID*/
  84. #define BLE_UUID_OTS_SERVICE 0x1825 /**< Object Transfer Service UUID*/
  85. /** @} */
  86. /** @defgroup UUID_CHARACTERISTICS Characteristic UUID definitions
  87. * @{ */
  88. #define BLE_UUID_REMOVABLE_CHAR 0x2A3A /**< Removable characteristic UUID. */
  89. #define BLE_UUID_SERVICE_REQUIRED_CHAR 0x2A3B /**< Service Required characteristic UUID. */
  90. #define BLE_UUID_ALERT_CATEGORY_ID_CHAR 0x2A43 /**< Alert Category Id characteristic UUID. */
  91. #define BLE_UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR 0x2A42 /**< Alert Category Id Bit Mask characteristic UUID. */
  92. #define BLE_UUID_ALERT_LEVEL_CHAR 0x2A06 /**< Alert Level characteristic UUID. */
  93. #define BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR 0x2A44 /**< Alert Notification Control Point characteristic UUID. */
  94. #define BLE_UUID_ALERT_STATUS_CHAR 0x2A3F /**< Alert Status characteristic UUID. */
  95. #define BLE_UUID_BATTERY_LEVEL_CHAR 0x2A19 /**< Battery Level characteristic UUID. */
  96. #define BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR 0x2A49 /**< Blood Pressure Feature characteristic UUID. */
  97. #define BLE_UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR 0x2A35 /**< Blood Pressure Measurement characteristic UUID. */
  98. #define BLE_UUID_BODY_SENSOR_LOCATION_CHAR 0x2A38 /**< Body Sensor Location characteristic UUID. */
  99. #define BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR 0x2A22 /**< Boot Keyboard Input Report characteristic UUID. */
  100. #define BLE_UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR 0x2A32 /**< Boot Keyboard Output Report characteristic UUID. */
  101. #define BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR 0x2A33 /**< Boot Mouse Input Report characteristic UUID. */
  102. #define BLE_UUID_CURRENT_TIME_CHAR 0x2A2B /**< Current Time characteristic UUID. */
  103. #define BLE_UUID_DATE_TIME_CHAR 0x2A08 /**< Date Time characteristic UUID. */
  104. #define BLE_UUID_DAY_DATE_TIME_CHAR 0x2A0A /**< Day Date Time characteristic UUID. */
  105. #define BLE_UUID_DAY_OF_WEEK_CHAR 0x2A09 /**< Day Of Week characteristic UUID. */
  106. #define BLE_UUID_DST_OFFSET_CHAR 0x2A0D /**< Dst Offset characteristic UUID. */
  107. #define BLE_UUID_EXACT_TIME_256_CHAR 0x2A0C /**< Exact Time 256 characteristic UUID. */
  108. #define BLE_UUID_FIRMWARE_REVISION_STRING_CHAR 0x2A26 /**< Firmware Revision String characteristic UUID. */
  109. #define BLE_UUID_GLUCOSE_FEATURE_CHAR 0x2A51 /**< Glucose Feature characteristic UUID. */
  110. #define BLE_UUID_GLUCOSE_MEASUREMENT_CHAR 0x2A18 /**< Glucose Measurement characteristic UUID. */
  111. #define BLE_UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR 0x2A34 /**< Glucose Measurement Context characteristic UUID. */
  112. #define BLE_UUID_HARDWARE_REVISION_STRING_CHAR 0x2A27 /**< Hardware Revision String characteristic UUID. */
  113. #define BLE_UUID_HEART_RATE_CONTROL_POINT_CHAR 0x2A39 /**< Heart Rate Control Point characteristic UUID. */
  114. #define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR 0x2A37 /**< Heart Rate Measurement characteristic UUID. */
  115. #define BLE_UUID_HID_CONTROL_POINT_CHAR 0x2A4C /**< Hid Control Point characteristic UUID. */
  116. #define BLE_UUID_HID_INFORMATION_CHAR 0x2A4A /**< Hid Information characteristic UUID. */
  117. #define BLE_UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR 0x2A2A /**< IEEE Regulatory Certification Data List characteristic UUID. */
  118. #define BLE_UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR 0x2A36 /**< Intermediate Cuff Pressure characteristic UUID. */
  119. #define BLE_UUID_INTERMEDIATE_TEMPERATURE_CHAR 0x2A1E /**< Intermediate Temperature characteristic UUID. */
  120. #define BLE_UUID_LOCAL_TIME_INFORMATION_CHAR 0x2A0F /**< Local Time Information characteristic UUID. */
  121. #define BLE_UUID_MANUFACTURER_NAME_STRING_CHAR 0x2A29 /**< Manufacturer Name String characteristic UUID. */
  122. #define BLE_UUID_MEASUREMENT_INTERVAL_CHAR 0x2A21 /**< Measurement Interval characteristic UUID. */
  123. #define BLE_UUID_MODEL_NUMBER_STRING_CHAR 0x2A24 /**< Model Number String characteristic UUID. */
  124. #define BLE_UUID_UNREAD_ALERT_CHAR 0x2A45 /**< Unread Alert characteristic UUID. */
  125. #define BLE_UUID_NEW_ALERT_CHAR 0x2A46 /**< New Alert characteristic UUID. */
  126. #define BLE_UUID_PNP_ID_CHAR 0x2A50 /**< PNP Id characteristic UUID. */
  127. #define BLE_UUID_PROTOCOL_MODE_CHAR 0x2A4E /**< Protocol Mode characteristic UUID. */
  128. #define BLE_UUID_RECORD_ACCESS_CONTROL_POINT_CHAR 0x2A52 /**< Record Access Control Point characteristic UUID. */
  129. #define BLE_UUID_REFERENCE_TIME_INFORMATION_CHAR 0x2A14 /**< Reference Time Information characteristic UUID. */
  130. #define BLE_UUID_REPORT_CHAR 0x2A4D /**< Report characteristic UUID. */
  131. #define BLE_UUID_REPORT_MAP_CHAR 0x2A4B /**< Report Map characteristic UUID. */
  132. #define BLE_UUID_RINGER_CONTROL_POINT_CHAR 0x2A40 /**< Ringer Control Point characteristic UUID. */
  133. #define BLE_UUID_RINGER_SETTING_CHAR 0x2A41 /**< Ringer Setting characteristic UUID. */
  134. #define BLE_UUID_SCAN_INTERVAL_WINDOW_CHAR 0x2A4F /**< Scan Interval Window characteristic UUID. */
  135. #define BLE_UUID_SCAN_REFRESH_CHAR 0x2A31 /**< Scan Refresh characteristic UUID. */
  136. #define BLE_UUID_SERIAL_NUMBER_STRING_CHAR 0x2A25 /**< Serial Number String characteristic UUID. */
  137. #define BLE_UUID_SOFTWARE_REVISION_STRING_CHAR 0x2A28 /**< Software Revision String characteristic UUID. */
  138. #define BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR 0x2A47 /**< Supported New Alert Category characteristic UUID. */
  139. #define BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR 0x2A48 /**< Supported Unread Alert Category characteristic UUID. */
  140. #define BLE_UUID_SYSTEM_ID_CHAR 0x2A23 /**< System Id characteristic UUID. */
  141. #define BLE_UUID_TEMPERATURE_MEASUREMENT_CHAR 0x2A1C /**< Temperature Measurement characteristic UUID. */
  142. #define BLE_UUID_TEMPERATURE_TYPE_CHAR 0x2A1D /**< Temperature Type characteristic UUID. */
  143. #define BLE_UUID_TIME_ACCURACY_CHAR 0x2A12 /**< Time Accuracy characteristic UUID. */
  144. #define BLE_UUID_TIME_SOURCE_CHAR 0x2A13 /**< Time Source characteristic UUID. */
  145. #define BLE_UUID_TIME_UPDATE_CONTROL_POINT_CHAR 0x2A16 /**< Time Update Control Point characteristic UUID. */
  146. #define BLE_UUID_TIME_UPDATE_STATE_CHAR 0x2A17 /**< Time Update State characteristic UUID. */
  147. #define BLE_UUID_TIME_WITH_DST_CHAR 0x2A11 /**< Time With Dst characteristic UUID. */
  148. #define BLE_UUID_TIME_ZONE_CHAR 0x2A0E /**< Time Zone characteristic UUID. */
  149. #define BLE_UUID_TX_POWER_LEVEL_CHAR 0x2A07 /**< TX Power Level characteristic UUID. */
  150. #define BLE_UUID_CSC_FEATURE_CHAR 0x2A5C /**< Cycling Speed and Cadence Feature characteristic UUID. */
  151. #define BLE_UUID_CSC_MEASUREMENT_CHAR 0x2A5B /**< Cycling Speed and Cadence Measurement characteristic UUID. */
  152. #define BLE_UUID_RSC_FEATURE_CHAR 0x2A54 /**< Running Speed and Cadence Feature characteristic UUID. */
  153. #define BLE_UUID_SC_CTRLPT_CHAR 0x2A55 /**< Speed and Cadence Control Point UUID. */
  154. #define BLE_UUID_RSC_MEASUREMENT_CHAR 0x2A53 /**< Running Speed and Cadence Measurement characteristic UUID. */
  155. #define BLE_UUID_SENSOR_LOCATION_CHAR 0x2A5D /**< Sensor Location characteristic UUID. */
  156. #define BLE_UUID_EXTERNAL_REPORT_REF_DESCR 0x2907 /**< External Report Reference descriptor UUID. */
  157. #define BLE_UUID_REPORT_REF_DESCR 0x2908 /**< Report Reference descriptor UUID. */
  158. #define BLE_UUID_LN_FEATURE_CHAR 0x2A6A /**< Location Navigation Service, Feature characteristic UUID. */
  159. #define BLE_UUID_LN_POSITION_QUALITY_CHAR 0x2A69 /**< Location Navigation Service, Position quality UUID. */
  160. #define BLE_UUID_LN_LOCATION_AND_SPEED_CHAR 0x2A67 /**< Location Navigation Service, Location and Speed characteristic UUID. */
  161. #define BLE_UUID_LN_NAVIGATION_CHAR 0x2A68 /**< Location Navigation Service, Navigation characteristic UUID. */
  162. #define BLE_UUID_LN_CONTROL_POINT_CHAR 0x2A6B /**< Location Navigation Service, Control point characteristic UUID. */
  163. #define BLE_UUID_BMS_CTRLPT 0x2AA4 /**< BMS Control Point characteristic UUID. */
  164. #define BLE_UUID_BMS_FEATURE 0x2AA5 /**< BMS Feature characteristic UUID. */
  165. #define BLE_UUID_CGM_MEASUREMENT 0x2AA7 /**< CGM Service, Measurement characteristic UUID*/
  166. #define BLE_UUID_CGM_FEATURE 0x2AA8 /**< CGM Service, Feature characteristic UUID*/
  167. #define BLE_UUID_CGM_STATUS 0x2AA9 /**< CGM Service, Status characteristic UUID*/
  168. #define BLE_UUID_CGM_SESSION_START_TIME 0x2AAA /**< CGM Service, session start time characteristic UUID*/
  169. #define BLE_UUID_CGM_SESSION_RUN_TIME 0x2AAB /**< CGM Service, session run time characteristic UUID*/
  170. #define BLE_UUID_CGM_SPECIFIC_OPS_CTRLPT 0x2AAC /**< CGM Service, specific ops ctrlpt characteristic UUID*/
  171. #define BLE_UUID_PLX_SPOT_CHECK_MEAS 0x2A5E /**< PLX Service, spot check measurement characteristic UUID*/
  172. #define BLE_UUID_PLX_CONTINUOUS_MEAS 0x2A5F /**< PLX Service, continuous measurement characteristic UUID*/
  173. #define BLE_UUID_PLX_FEATURES 0x2A60 /**< PLX Service, feature characteristic UUID*/
  174. #define BLE_UUID_OTS_FEATURES 0x2ABD /**< OTS Service, feature characteristic UUID*/
  175. #define BLE_UUID_OTS_OBJECT_NAME 0x2ABE /**< OTS Service, Object Name characteristic UUID*/
  176. #define BLE_UUID_OTS_OBJECT_TYPE 0x2ABF /**< OTS Service, Object Type characteristic UUID*/
  177. #define BLE_UUID_OTS_OBJECT_SIZE 0x2AC0 /**< OTS Service, Object Size characteristic UUID*/
  178. #define BLE_UUID_OTS_OBJECT_FIRST_CREATED 0x2AC1 /**< OTS Service, Object First Created characteristic UUID*/
  179. #define BLE_UUID_OTS_OBJECT_LAST_MODIFIED 0x2AC2 /**< OTS Service, Object Last Modified characteristic UUID*/
  180. #define BLE_UUID_OTS_OBJECT_ID 0x2AC3 /**< OTS Service, Object ID characteristic UUID*/
  181. #define BLE_UUID_OTS_OBJECT_PROPERTIES 0x2AC4 /**< OTS Service, Object Properties characteristic UUID*/
  182. #define BLE_UUID_OTS_OACP 0x2AC5 /**< OTS Service, Object Action Control Point characteristic UUID*/
  183. #define BLE_UUID_OTS_OLCP 0x2AC6 /**< OTS Service, Object List Control Point characteristic UUID*/
  184. #define BLE_UUID_OTS_LF 0x2AC7 /**< OTS Service, Object List Filter characteristic UUID*/
  185. #define BLE_UUID_OTS_OBJECT_CHANGED 0x2AC8 /**< OTS Service, Object Changed characteristic UUID*/
  186. /** @} */
  187. /** @defgroup ALERT_LEVEL_VALUES Definitions for the Alert Level characteristic values
  188. * @{ */
  189. #define BLE_CHAR_ALERT_LEVEL_NO_ALERT 0x00 /**< No Alert. */
  190. #define BLE_CHAR_ALERT_LEVEL_MILD_ALERT 0x01 /**< Mild Alert. */
  191. #define BLE_CHAR_ALERT_LEVEL_HIGH_ALERT 0x02 /**< High Alert. */
  192. /** @} */
  193. #define BLE_SRV_ENCODED_REPORT_REF_LEN 2 /**< The length of an encoded Report Reference Descriptor. */
  194. #define BLE_CCCD_VALUE_LEN 2 /**< The length of a CCCD value. */
  195. /**@brief Type definition for error handler function that will be called in case of an error in
  196. * a service or a service library module. */
  197. typedef void (*ble_srv_error_handler_t) (uint32_t nrf_error);
  198. /**@brief Value of a Report Reference descriptor.
  199. *
  200. * @details This is mapping information that maps the parent characteristic to the Report ID(s) and
  201. * Report Type(s) defined within a Report Map characteristic.
  202. */
  203. typedef struct
  204. {
  205. uint8_t report_id; /**< Non-zero value if there is more than one instance of the same Report Type */
  206. uint8_t report_type; /**< Type of Report characteristic (see @ref BLE_HIDS_REPORT_TYPE) */
  207. } ble_srv_report_ref_t;
  208. /**@brief UTF-8 string data type.
  209. *
  210. * @note The type can only hold a pointer to the string data (i.e. not the actual data).
  211. */
  212. typedef struct
  213. {
  214. uint16_t length; /**< String length. */
  215. uint8_t * p_str; /**< String data. */
  216. } ble_srv_utf8_str_t;
  217. /**@brief Security settings structure.
  218. * @details This structure contains the security options needed during initialization of the
  219. * service.
  220. */
  221. typedef struct
  222. {
  223. ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
  224. ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
  225. } ble_srv_security_mode_t;
  226. /**@brief Security settings structure.
  227. * @details This structure contains the security options needed during initialization of the
  228. * service. It can be used when the characteristics contains a CCCD.
  229. */
  230. typedef struct
  231. {
  232. ble_gap_conn_sec_mode_t cccd_write_perm; /**< Write permissions for Client Characteristic Configuration Descriptor. */
  233. ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
  234. ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
  235. } ble_srv_cccd_security_mode_t;
  236. /**@brief Function for decoding a CCCD value, and then testing if notification is
  237. * enabled.
  238. *
  239. * @param[in] p_encoded_data Buffer where the encoded CCCD is stored.
  240. *
  241. * @retval TRUE If notification is enabled.
  242. * @retval FALSE Otherwise.
  243. */
  244. bool ble_srv_is_notification_enabled(uint8_t const * p_encoded_data);
  245. /**@brief Function for decoding a CCCD value, and then testing if indication is
  246. * enabled.
  247. *
  248. * @param[in] p_encoded_data Buffer where the encoded CCCD is stored.
  249. *
  250. * @retval TRUE If indication is enabled.
  251. * @retval FALSE Otherwise.
  252. */
  253. bool ble_srv_is_indication_enabled(uint8_t const * p_encoded_data);
  254. /**@brief Function for encoding a Report Reference Descriptor.
  255. *
  256. * @param[in] p_encoded_buffer The buffer of the encoded data.
  257. * @param[in] p_report_ref Report Reference value to be encoded.
  258. *
  259. * @return Length of the encoded data.
  260. */
  261. uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer,
  262. const ble_srv_report_ref_t * p_report_ref);
  263. /**@brief Function for making a UTF-8 structure refer to an ASCII string.
  264. *
  265. * @param[out] p_utf8 UTF-8 structure to be set.
  266. * @param[in] p_ascii ASCII string to be referred to.
  267. */
  268. void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii);
  269. /**@brief Security Access enumeration.
  270. * @details This enumeration gives the possible requirements for accessing a characteristic value.
  271. */
  272. typedef enum
  273. {
  274. SEC_NO_ACCESS = 0, /**< Not possible to access. */
  275. SEC_OPEN = 1, /**< Access open. */
  276. SEC_JUST_WORKS = 2, /**< Access possible with 'Just Works' security at least. */
  277. SEC_MITM = 3, /**< Access possible with 'MITM' security at least. */
  278. SEC_SIGNED = 4, /**< Access possible with 'signed' security at least. */
  279. SEC_SIGNED_MITM = 5 /**< Access possible with 'signed and MITM' security at least. */
  280. }security_req_t;
  281. /**@brief Characteristic User Descriptor parameters.
  282. * @details This structure contains the parameters for User Descriptor.
  283. */
  284. typedef struct
  285. {
  286. uint16_t max_size; /**< Maximum size of the user descriptor*/
  287. uint16_t size; /**< Size of the user descriptor*/
  288. uint8_t *p_char_user_desc; /**< User descriptor content, pointer to a UTF-8 encoded string (non-NULL terminated)*/
  289. bool is_var_len; /**< Indicates if the user descriptor has variable length.*/
  290. ble_gatt_char_props_t char_props; /**< user descriptor properties.*/
  291. bool is_defered_read; /**< Indicate if deferred read operations are supported.*/
  292. bool is_defered_write; /**< Indicate if deferred write operations are supported.*/
  293. security_req_t read_access; /**< Security requirement for reading the user descriptor.*/
  294. security_req_t write_access; /**< Security requirement for writing the user descriptor.*/
  295. bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/
  296. }ble_add_char_user_desc_t;
  297. /**@brief Add characteristic parameters structure.
  298. * @details This structure contains the parameters needed to use the @ref characteristic_add function.
  299. */
  300. typedef struct
  301. {
  302. uint16_t uuid; /**< Characteristic UUID (16 bits UUIDs).*/
  303. uint8_t uuid_type; /**< Base UUID. If 0, the Bluetooth SIG UUID will be used. Otherwise, this should be a value returned by @ref sd_ble_uuid_vs_add when adding the base UUID.*/
  304. uint16_t max_len; /**< Maximum length of the characteristic value.*/
  305. uint16_t init_len; /**< Initial length of the characteristic value.*/
  306. uint8_t * p_init_value; /**< Initial encoded value of the characteristic.*/
  307. bool is_var_len; /**< Indicates if the characteristic value has variable length.*/
  308. ble_gatt_char_props_t char_props; /**< Characteristic properties.*/
  309. ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic extended properties.*/
  310. bool is_defered_read; /**< Indicate if deferred read operations are supported.*/
  311. bool is_defered_write; /**< Indicate if deferred write operations are supported.*/
  312. security_req_t read_access; /**< Security requirement for reading the characteristic value.*/
  313. security_req_t write_access; /**< Security requirement for writing the characteristic value.*/
  314. security_req_t cccd_write_access; /**< Security requirement for writing the characteristic's CCCD.*/
  315. bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/
  316. ble_add_char_user_desc_t *p_user_descr; /**< Pointer to user descriptor if needed*/
  317. ble_gatts_char_pf_t *p_presentation_format; /**< Pointer to characteristic format if needed*/
  318. } ble_add_char_params_t;
  319. /**@brief Add descriptor parameters structure.
  320. * @details This structure contains the parameters needed to use the @ref descriptor_add function.
  321. */
  322. typedef struct
  323. {
  324. uint16_t uuid; /**< descriptor UUID (16 bits UUIDs).*/
  325. uint8_t uuid_type; /**< Base UUID. If 0, the Bluetooth SIG UUID will be used. Otherwise, this should be a value returned by @ref sd_ble_uuid_vs_add when adding the base UUID.*/
  326. bool is_defered_read; /**< Indicate if deferred read operations are supported.*/
  327. bool is_defered_write; /**< Indicate if deferred write operations are supported.*/
  328. bool is_var_len; /**< Indicates if the descriptor value has variable length.*/
  329. security_req_t read_access; /**< Security requirement for reading the descriptor value.*/
  330. security_req_t write_access; /**< Security requirement for writing the descriptor value.*/
  331. bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/
  332. uint16_t init_len; /**< Initial descriptor value length in bytes. */
  333. uint16_t init_offs; /**< Initial descriptor value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */
  334. uint16_t max_len; /**< Maximum descriptor value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
  335. uint8_t* p_value; /**< Pointer to the value of the descriptor*/
  336. } ble_add_descr_params_t;
  337. /**@brief Function for adding a characteristic to a given service.
  338. *
  339. * If no pointer is given for the initial value,
  340. * the initial length parameter will be ignored and the initial length will be 0.
  341. *
  342. * @param[in] service_handle Handle of the service to which the characteristic is to be added.
  343. * @param[in] p_char_props Information needed to add the characteristic.
  344. * @param[out] p_char_handle Handle of the added characteristic.
  345. *
  346. * @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned.
  347. */
  348. uint32_t characteristic_add(uint16_t service_handle,
  349. ble_add_char_params_t * p_char_props,
  350. ble_gatts_char_handles_t * p_char_handle);
  351. /**@brief Function for adding a characteristic's descriptor to a given characteristic.
  352. *
  353. * @param[in] char_handle Handle of the characteristic to which the descriptor is to be added, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  354. * @param[in] p_descr_props Information needed to add the descriptor.
  355. * @param[out] p_descr_handle Handle of the added descriptor.
  356. *
  357. * @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned.
  358. */
  359. uint32_t descriptor_add(uint16_t char_handle,
  360. ble_add_descr_params_t * p_descr_props,
  361. uint16_t * p_descr_handle);
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365. #endif // BLE_SRV_COMMON_H__
  366. /** @} */