cvb

Fork of nrf51-sdk by Lancaster University

Committer:
tb942
Date:
Tue Aug 14 18:27:20 2018 +0000
Revision:
9:d3dd910b0f4b
Parent:
0:bc2961fa1ef0

        

Who changed what in which revision?

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