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