Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.
Embed:
(wiki syntax)
Show/hide line numbers
ble_srv_common.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 /** @file 00034 * 00035 * @defgroup ble_sdk_srv_common Common service definitions 00036 * @{ 00037 * @ingroup ble_sdk_srv 00038 * @brief Constants, type definitions, and functions that are common to all services. 00039 */ 00040 00041 #ifndef BLE_SRV_COMMON_H__ 00042 #define BLE_SRV_COMMON_H__ 00043 00044 #include <stdint.h> 00045 #include <stdbool.h> 00046 #include "ble_types.h" 00047 #include "app_util.h " 00048 #include "nrf_ble.h" 00049 #include "ble_gap.h" 00050 #include "ble_gatt.h" 00051 00052 /** @defgroup UUID_SERVICES Service UUID definitions 00053 * @{ */ 00054 #define BLE_UUID_ALERT_NOTIFICATION_SERVICE 0x1811 /**< Alert Notification service UUID. */ 00055 #define BLE_UUID_BATTERY_SERVICE 0x180F /**< Battery service UUID. */ 00056 #define BLE_UUID_BLOOD_PRESSURE_SERVICE 0x1810 /**< Blood Pressure service UUID. */ 00057 #define BLE_UUID_CURRENT_TIME_SERVICE 0x1805 /**< Current Time service UUID. */ 00058 #define BLE_UUID_CYCLING_SPEED_AND_CADENCE 0x1816 /**< Cycling Speed and Cadence service UUID. */ 00059 #define BLE_UUID_LOCATION_AND_NAVIGATION_SERVICE 0x1819 /**< Location and Navigation service UUID. */ 00060 #define BLE_UUID_DEVICE_INFORMATION_SERVICE 0x180A /**< Device Information service UUID. */ 00061 #define BLE_UUID_GLUCOSE_SERVICE 0x1808 /**< Glucose service UUID. */ 00062 #define BLE_UUID_HEALTH_THERMOMETER_SERVICE 0x1809 /**< Health Thermometer service UUID. */ 00063 #define BLE_UUID_HEART_RATE_SERVICE 0x180D /**< Heart Rate service UUID. */ 00064 #define BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE 0x1812 /**< Human Interface Device service UUID. */ 00065 #define BLE_UUID_IMMEDIATE_ALERT_SERVICE 0x1802 /**< Immediate Alert service UUID. */ 00066 #define BLE_UUID_LINK_LOSS_SERVICE 0x1803 /**< Link Loss service UUID. */ 00067 #define BLE_UUID_NEXT_DST_CHANGE_SERVICE 0x1807 /**< Next Dst Change service UUID. */ 00068 #define BLE_UUID_PHONE_ALERT_STATUS_SERVICE 0x180E /**< Phone Alert Status service UUID. */ 00069 #define BLE_UUID_REFERENCE_TIME_UPDATE_SERVICE 0x1806 /**< Reference Time Update service UUID. */ 00070 #define BLE_UUID_RUNNING_SPEED_AND_CADENCE 0x1814 /**< Running Speed and Cadence service UUID. */ 00071 #define BLE_UUID_SCAN_PARAMETERS_SERVICE 0x1813 /**< Scan Parameters service UUID. */ 00072 #define BLE_UUID_TX_POWER_SERVICE 0x1804 /**< TX Power service UUID. */ 00073 #define BLE_UUID_IPSP_SERVICE 0x1820 /**< Internet Protocol Support service UUID. */ 00074 /** @} */ 00075 00076 /** @defgroup UUID_CHARACTERISTICS Characteristic UUID definitions 00077 * @{ */ 00078 #define BLE_UUID_BATTERY_LEVEL_STATE_CHAR 0x2A1B /**< Battery Level State characteristic UUID. */ 00079 #define BLE_UUID_BATTERY_POWER_STATE_CHAR 0x2A1A /**< Battery Power State characteristic UUID. */ 00080 #define BLE_UUID_REMOVABLE_CHAR 0x2A3A /**< Removable characteristic UUID. */ 00081 #define BLE_UUID_SERVICE_REQUIRED_CHAR 0x2A3B /**< Service Required characteristic UUID. */ 00082 #define BLE_UUID_ALERT_CATEGORY_ID_CHAR 0x2A43 /**< Alert Category Id characteristic UUID. */ 00083 #define BLE_UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR 0x2A42 /**< Alert Category Id Bit Mask characteristic UUID. */ 00084 #define BLE_UUID_ALERT_LEVEL_CHAR 0x2A06 /**< Alert Level characteristic UUID. */ 00085 #define BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR 0x2A44 /**< Alert Notification Control Point characteristic UUID. */ 00086 #define BLE_UUID_ALERT_STATUS_CHAR 0x2A3F /**< Alert Status characteristic UUID. */ 00087 #define BLE_UUID_BATTERY_LEVEL_CHAR 0x2A19 /**< Battery Level characteristic UUID. */ 00088 #define BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR 0x2A49 /**< Blood Pressure Feature characteristic UUID. */ 00089 #define BLE_UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR 0x2A35 /**< Blood Pressure Measurement characteristic UUID. */ 00090 #define BLE_UUID_BODY_SENSOR_LOCATION_CHAR 0x2A38 /**< Body Sensor Location characteristic UUID. */ 00091 #define BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR 0x2A22 /**< Boot Keyboard Input Report characteristic UUID. */ 00092 #define BLE_UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR 0x2A32 /**< Boot Keyboard Output Report characteristic UUID. */ 00093 #define BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR 0x2A33 /**< Boot Mouse Input Report characteristic UUID. */ 00094 #define BLE_UUID_CURRENT_TIME_CHAR 0x2A2B /**< Current Time characteristic UUID. */ 00095 #define BLE_UUID_DATE_TIME_CHAR 0x2A08 /**< Date Time characteristic UUID. */ 00096 #define BLE_UUID_DAY_DATE_TIME_CHAR 0x2A0A /**< Day Date Time characteristic UUID. */ 00097 #define BLE_UUID_DAY_OF_WEEK_CHAR 0x2A09 /**< Day Of Week characteristic UUID. */ 00098 #define BLE_UUID_DST_OFFSET_CHAR 0x2A0D /**< Dst Offset characteristic UUID. */ 00099 #define BLE_UUID_EXACT_TIME_256_CHAR 0x2A0C /**< Exact Time 256 characteristic UUID. */ 00100 #define BLE_UUID_FIRMWARE_REVISION_STRING_CHAR 0x2A26 /**< Firmware Revision String characteristic UUID. */ 00101 #define BLE_UUID_GLUCOSE_FEATURE_CHAR 0x2A51 /**< Glucose Feature characteristic UUID. */ 00102 #define BLE_UUID_GLUCOSE_MEASUREMENT_CHAR 0x2A18 /**< Glucose Measurement characteristic UUID. */ 00103 #define BLE_UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR 0x2A34 /**< Glucose Measurement Context characteristic UUID. */ 00104 #define BLE_UUID_HARDWARE_REVISION_STRING_CHAR 0x2A27 /**< Hardware Revision String characteristic UUID. */ 00105 #define BLE_UUID_HEART_RATE_CONTROL_POINT_CHAR 0x2A39 /**< Heart Rate Control Point characteristic UUID. */ 00106 #define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR 0x2A37 /**< Heart Rate Measurement characteristic UUID. */ 00107 #define BLE_UUID_HID_CONTROL_POINT_CHAR 0x2A4C /**< Hid Control Point characteristic UUID. */ 00108 #define BLE_UUID_HID_INFORMATION_CHAR 0x2A4A /**< Hid Information characteristic UUID. */ 00109 #define BLE_UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR 0x2A2A /**< IEEE Regulatory Certification Data List characteristic UUID. */ 00110 #define BLE_UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR 0x2A36 /**< Intermediate Cuff Pressure characteristic UUID. */ 00111 #define BLE_UUID_INTERMEDIATE_TEMPERATURE_CHAR 0x2A1E /**< Intermediate Temperature characteristic UUID. */ 00112 #define BLE_UUID_LOCAL_TIME_INFORMATION_CHAR 0x2A0F /**< Local Time Information characteristic UUID. */ 00113 #define BLE_UUID_MANUFACTURER_NAME_STRING_CHAR 0x2A29 /**< Manufacturer Name String characteristic UUID. */ 00114 #define BLE_UUID_MEASUREMENT_INTERVAL_CHAR 0x2A21 /**< Measurement Interval characteristic UUID. */ 00115 #define BLE_UUID_MODEL_NUMBER_STRING_CHAR 0x2A24 /**< Model Number String characteristic UUID. */ 00116 #define BLE_UUID_UNREAD_ALERT_CHAR 0x2A45 /**< Unread Alert characteristic UUID. */ 00117 #define BLE_UUID_NEW_ALERT_CHAR 0x2A46 /**< New Alert characteristic UUID. */ 00118 #define BLE_UUID_PNP_ID_CHAR 0x2A50 /**< PNP Id characteristic UUID. */ 00119 #define BLE_UUID_PROTOCOL_MODE_CHAR 0x2A4E /**< Protocol Mode characteristic UUID. */ 00120 #define BLE_UUID_RECORD_ACCESS_CONTROL_POINT_CHAR 0x2A52 /**< Record Access Control Point characteristic UUID. */ 00121 #define BLE_UUID_REFERENCE_TIME_INFORMATION_CHAR 0x2A14 /**< Reference Time Information characteristic UUID. */ 00122 #define BLE_UUID_REPORT_CHAR 0x2A4D /**< Report characteristic UUID. */ 00123 #define BLE_UUID_REPORT_MAP_CHAR 0x2A4B /**< Report Map characteristic UUID. */ 00124 #define BLE_UUID_RINGER_CONTROL_POINT_CHAR 0x2A40 /**< Ringer Control Point characteristic UUID. */ 00125 #define BLE_UUID_RINGER_SETTING_CHAR 0x2A41 /**< Ringer Setting characteristic UUID. */ 00126 #define BLE_UUID_SCAN_INTERVAL_WINDOW_CHAR 0x2A4F /**< Scan Interval Window characteristic UUID. */ 00127 #define BLE_UUID_SCAN_REFRESH_CHAR 0x2A31 /**< Scan Refresh characteristic UUID. */ 00128 #define BLE_UUID_SERIAL_NUMBER_STRING_CHAR 0x2A25 /**< Serial Number String characteristic UUID. */ 00129 #define BLE_UUID_SOFTWARE_REVISION_STRING_CHAR 0x2A28 /**< Software Revision String characteristic UUID. */ 00130 #define BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR 0x2A47 /**< Supported New Alert Category characteristic UUID. */ 00131 #define BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR 0x2A48 /**< Supported Unread Alert Category characteristic UUID. */ 00132 #define BLE_UUID_SYSTEM_ID_CHAR 0x2A23 /**< System Id characteristic UUID. */ 00133 #define BLE_UUID_TEMPERATURE_MEASUREMENT_CHAR 0x2A1C /**< Temperature Measurement characteristic UUID. */ 00134 #define BLE_UUID_TEMPERATURE_TYPE_CHAR 0x2A1D /**< Temperature Type characteristic UUID. */ 00135 #define BLE_UUID_TIME_ACCURACY_CHAR 0x2A12 /**< Time Accuracy characteristic UUID. */ 00136 #define BLE_UUID_TIME_SOURCE_CHAR 0x2A13 /**< Time Source characteristic UUID. */ 00137 #define BLE_UUID_TIME_UPDATE_CONTROL_POINT_CHAR 0x2A16 /**< Time Update Control Point characteristic UUID. */ 00138 #define BLE_UUID_TIME_UPDATE_STATE_CHAR 0x2A17 /**< Time Update State characteristic UUID. */ 00139 #define BLE_UUID_TIME_WITH_DST_CHAR 0x2A11 /**< Time With Dst characteristic UUID. */ 00140 #define BLE_UUID_TIME_ZONE_CHAR 0x2A0E /**< Time Zone characteristic UUID. */ 00141 #define BLE_UUID_TX_POWER_LEVEL_CHAR 0x2A07 /**< TX Power Level characteristic UUID. */ 00142 #define BLE_UUID_CSC_FEATURE_CHAR 0x2A5C /**< Cycling Speed and Cadence Feature characteristic UUID. */ 00143 #define BLE_UUID_CSC_MEASUREMENT_CHAR 0x2A5B /**< Cycling Speed and Cadence Measurement characteristic UUID. */ 00144 #define BLE_UUID_RSC_FEATURE_CHAR 0x2A54 /**< Running Speed and Cadence Feature characteristic UUID. */ 00145 #define BLE_UUID_SC_CTRLPT_CHAR 0x2A55 /**< Speed and Cadence Control Point UUID. */ 00146 #define BLE_UUID_RSC_MEASUREMENT_CHAR 0x2A53 /**< Running Speed and Cadence Measurement characteristic UUID. */ 00147 #define BLE_UUID_SENSOR_LOCATION_CHAR 0x2A5D /**< Sensor Location characteristic UUID. */ 00148 #define BLE_UUID_EXTERNAL_REPORT_REF_DESCR 0x2907 /**< External Report Reference descriptor UUID. */ 00149 #define BLE_UUID_REPORT_REF_DESCR 0x2908 /**< Report Reference descriptor UUID. */ 00150 #define BLE_UUID_LN_FEATURE_CHAR 0x2A6A /**< Location Navigation Service, Feature characteristic UUID. */ 00151 #define BLE_UUID_LN_POSITION_QUALITY_CHAR 0x2A69 /**< Location Navigation Service, Position quality UUID. */ 00152 #define BLE_UUID_LN_LOCATION_AND_SPEED_CHAR 0x2A67 /**< Location Navigation Service, Location and Speed characteristic UUID. */ 00153 #define BLE_UUID_LN_NAVIGATION_CHAR 0x2A68 /**< Location Navigation Service, Navigation characteristic UUID. */ 00154 #define BLE_UUID_LN_CONTROL_POINT_CHAR 0x2A6B /**< Location Navigation Service, Control point characteristic UUID. */ 00155 /** @} */ 00156 00157 /** @defgroup ALERT_LEVEL_VALUES Definitions for the Alert Level characteristic values 00158 * @{ */ 00159 #define BLE_CHAR_ALERT_LEVEL_NO_ALERT 0x00 /**< No Alert. */ 00160 #define BLE_CHAR_ALERT_LEVEL_MILD_ALERT 0x01 /**< Mild Alert. */ 00161 #define BLE_CHAR_ALERT_LEVEL_HIGH_ALERT 0x02 /**< High Alert. */ 00162 /** @} */ 00163 00164 #define BLE_SRV_ENCODED_REPORT_REF_LEN 2 /**< The length of an encoded Report Reference Descriptor. */ 00165 #define BLE_CCCD_VALUE_LEN 2 /**< The length of a CCCD value. */ 00166 00167 /**@brief Type definition for error handler function that will be called in case of an error in 00168 * a service or a service library module. */ 00169 typedef void (*ble_srv_error_handler_t) (uint32_t nrf_error); 00170 00171 00172 00173 /**@brief Value of a Report Reference descriptor. 00174 * 00175 * @details This is mapping information that maps the parent characteristic to the Report ID(s) and 00176 * Report Type(s) defined within a Report Map characteristic. 00177 */ 00178 typedef struct 00179 { 00180 uint8_t report_id; /**< Non-zero value if there is more than one instance of the same Report Type */ 00181 uint8_t report_type; /**< Type of Report characteristic (see @ref BLE_HIDS_REPORT_TYPE) */ 00182 } ble_srv_report_ref_t; 00183 00184 /**@brief UTF-8 string data type. 00185 * 00186 * @note The type can only hold a pointer to the string data (i.e. not the actual data). 00187 */ 00188 typedef struct 00189 { 00190 uint16_t length; /**< String length. */ 00191 uint8_t * p_str; /**< String data. */ 00192 } ble_srv_utf8_str_t; 00193 00194 00195 /**@brief Security settings structure. 00196 * @details This structure contains the security options needed during initialization of the 00197 * service. 00198 */ 00199 typedef struct 00200 { 00201 ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ 00202 ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ 00203 } ble_srv_security_mode_t; 00204 00205 /**@brief Security settings structure. 00206 * @details This structure contains the security options needed during initialization of the 00207 * service. It can be used when the characteristics contains a CCCD. 00208 */ 00209 typedef struct 00210 { 00211 ble_gap_conn_sec_mode_t cccd_write_perm; /**< Write permissions for Client Characteristic Configuration Descriptor. */ 00212 ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ 00213 ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ 00214 } ble_srv_cccd_security_mode_t; 00215 00216 /**@brief Function for decoding a CCCD value, and then testing if notification is 00217 * enabled. 00218 * 00219 * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. 00220 * 00221 * @retval TRUE If notification is enabled. 00222 * @retval FALSE Otherwise. 00223 */ 00224 static __INLINE bool ble_srv_is_notification_enabled(uint8_t * p_encoded_data) 00225 { 00226 uint16_t cccd_value = uint16_decode(p_encoded_data); 00227 return ((cccd_value & BLE_GATT_HVX_NOTIFICATION) != 0); 00228 } 00229 00230 /**@brief Function for decoding a CCCD value, and then testing if indication is 00231 * enabled. 00232 * 00233 * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. 00234 * 00235 * @retval TRUE If indication is enabled. 00236 * @retval FALSE Otherwise. 00237 */ 00238 static __INLINE bool ble_srv_is_indication_enabled(uint8_t * p_encoded_data) 00239 { 00240 uint16_t cccd_value = uint16_decode(p_encoded_data); 00241 return ((cccd_value & BLE_GATT_HVX_INDICATION) != 0); 00242 } 00243 00244 /**@brief Function for encoding a Report Reference Descriptor. 00245 * 00246 * @param[in] p_encoded_buffer The buffer of the encoded data. 00247 * @param[in] p_report_ref Report Reference value to be encoded. 00248 * 00249 * @return Length of the encoded data. 00250 */ 00251 uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, 00252 const ble_srv_report_ref_t * p_report_ref); 00253 00254 /**@brief Function for making a UTF-8 structure refer to an ASCII string. 00255 * 00256 * @param[out] p_utf8 UTF-8 structure to be set. 00257 * @param[in] p_ascii ASCII string to be referred to. 00258 */ 00259 void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii); 00260 00261 00262 /**@brief Security Access enumeration. 00263 * @details This enumeration gives the possible requirements for accessing a characteristic value. 00264 */ 00265 typedef enum 00266 { 00267 SEC_NO_ACCESS = 0, /**< Not possible to access. */ 00268 SEC_OPEN = 1, /**< Access open. */ 00269 SEC_JUST_WORKS = 2, /**< Access possible with 'Just Works' security at least. */ 00270 SEC_MITM = 3, /**< Access possible with 'MITM' security at least. */ 00271 SEC_SIGNED = 4, /**< Access possible with 'signed' security at least. */ 00272 SEC_SIGNED_MITM = 5 /**< Access possible with 'signed and MITM' security at least. */ 00273 }security_req_t; 00274 00275 00276 /**@brief Characteristic User Descriptor parameters. 00277 * @details This structure contains the parameters for User Descriptor. 00278 */ 00279 typedef struct 00280 { 00281 uint16_t max_size; /**< Maximum size of the user descriptor*/ 00282 uint16_t size; /**< Size of the user descriptor*/ 00283 uint8_t *p_char_user_desc; /**< User descriptor content, pointer to a UTF-8 encoded string (non-NULL terminated)*/ 00284 bool is_var_len; /**< Indicates if the user descriptor has variable length.*/ 00285 ble_gatt_char_props_t char_props; /**< user descriptor properties.*/ 00286 bool is_defered_read; /**< Indicate if deferred read operations are supported.*/ 00287 bool is_defered_write; /**< Indicate if deferred write operations are supported.*/ 00288 security_req_t read_access; /**< Security requirement for reading the user descriptor.*/ 00289 security_req_t write_access; /**< Security requirement for writing the user descriptor.*/ 00290 bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/ 00291 }ble_add_char_user_desc_t; 00292 00293 00294 /**@brief Add characteristic parameters structure. 00295 * @details This structure contains the parameters needed to use the @ref characteristic_add function. 00296 */ 00297 typedef struct 00298 { 00299 uint16_t uuid; /**< Characteristic UUID (16 bits UUIDs).*/ 00300 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.*/ 00301 uint16_t max_len; /**< Maximum length of the characteristic value.*/ 00302 uint16_t init_len; /**< Initial length of the characteristic value.*/ 00303 uint8_t * p_init_value; /**< Initial encoded value of the characteristic.*/ 00304 bool is_var_len; /**< Indicates if the characteristic value has variable length.*/ 00305 ble_gatt_char_props_t char_props; /**< Characteristic properties.*/ 00306 bool is_defered_read; /**< Indicate if deferred read operations are supported.*/ 00307 bool is_defered_write; /**< Indicate if deferred write operations are supported.*/ 00308 security_req_t read_access; /**< Security requirement for reading the characteristic value.*/ 00309 security_req_t write_access; /**< Security requirement for writing the characteristic value.*/ 00310 security_req_t cccd_write_access; /**< Security requirement for writing the characteristic's CCCD.*/ 00311 bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/ 00312 ble_add_char_user_desc_t *p_user_descr; /**< Pointer to user descriptor if needed*/ 00313 ble_gatts_char_pf_t *p_presentation_format; /**< Pointer to characteristic format if needed*/ 00314 } ble_add_char_params_t; 00315 00316 00317 /**@brief Add descriptor parameters structure. 00318 * @details This structure contains the parameters needed to use the @ref descriptor_add function. 00319 */ 00320 typedef struct 00321 { 00322 uint16_t uuid; /**< descriptor UUID (16 bits UUIDs).*/ 00323 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.*/ 00324 bool is_defered_read; /**< Indicate if deferred read operations are supported.*/ 00325 bool is_defered_write; /**< Indicate if deferred write operations are supported.*/ 00326 bool is_var_len; /**< Indicates if the descriptor value has variable length.*/ 00327 security_req_t read_access; /**< Security requirement for reading the descriptor value.*/ 00328 security_req_t write_access; /**< Security requirement for writing the descriptor value.*/ 00329 bool is_value_user; /**< Indicate if the content of the characteristic is to be stored in the application (user) or in the stack.*/ 00330 uint16_t init_len; /**< Initial descriptor value length in bytes. */ 00331 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. */ 00332 uint16_t max_len; /**< Maximum descriptor value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */ 00333 uint8_t* p_value; /**< Pointer to the value of the descriptor*/ 00334 } ble_add_descr_params_t; 00335 00336 00337 /**@brief Function for adding a characteristic to a given service. 00338 * 00339 * If no pointer is given for the initial value, 00340 * the initial length parameter will be ignored and the initial length will be 0. 00341 * 00342 * @param[in] service_handle Handle of the service to which the characteristic is to be added. 00343 * @param[in] p_char_props Information needed to add the characteristic. 00344 * @param[out] p_char_handle Handle of the added characteristic. 00345 * 00346 * @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned. 00347 */ 00348 uint32_t characteristic_add(uint16_t service_handle, 00349 ble_add_char_params_t * p_char_props, 00350 ble_gatts_char_handles_t * p_char_handle); 00351 00352 00353 /**@brief Function for adding a characteristic's descriptor to a given characteristic. 00354 * 00355 * @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. 00356 * @param[in] p_descr_props Information needed to add the descriptor. 00357 * @param[out] p_descr_handle Handle of the added descriptor. 00358 * 00359 * @retval NRF_SUCCESS If the characteristic was added successfully. Otherwise, an error code is returned. 00360 */ 00361 uint32_t descriptor_add(uint16_t char_handle, 00362 ble_add_descr_params_t * p_descr_props, 00363 uint16_t * p_descr_handle); 00364 00365 00366 #endif // BLE_SRV_COMMON_H__ 00367 00368 /** @} */
Generated on Tue Jul 12 2022 15:05:58 by 1.7.2