project for nrf51822 qfab
Dependencies: eddystone_URL mbed
Fork of eddystone_URL by
nRF51822/nordic/nrf-sdk/s110/ble_gatts.h@0:76dfa9657d9d, 2014-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Wed Nov 12 02:40:34 2014 +0000
- Revision:
- 0:76dfa9657d9d
????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:76dfa9657d9d | 2 | * |
jksoft | 0:76dfa9657d9d | 3 | * The information contained herein is confidential property of Nordic Semiconductor. The use, |
jksoft | 0:76dfa9657d9d | 4 | * copying, transfer or disclosure of such information is prohibited except by express written |
jksoft | 0:76dfa9657d9d | 5 | * agreement with Nordic Semiconductor. |
jksoft | 0:76dfa9657d9d | 6 | * |
jksoft | 0:76dfa9657d9d | 7 | */ |
jksoft | 0:76dfa9657d9d | 8 | /** |
jksoft | 0:76dfa9657d9d | 9 | @addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server |
jksoft | 0:76dfa9657d9d | 10 | @{ |
jksoft | 0:76dfa9657d9d | 11 | @brief Definitions and prototypes for the GATTS interface. |
jksoft | 0:76dfa9657d9d | 12 | */ |
jksoft | 0:76dfa9657d9d | 13 | |
jksoft | 0:76dfa9657d9d | 14 | #ifndef BLE_GATTS_H__ |
jksoft | 0:76dfa9657d9d | 15 | #define BLE_GATTS_H__ |
jksoft | 0:76dfa9657d9d | 16 | |
jksoft | 0:76dfa9657d9d | 17 | #include "ble_types.h" |
jksoft | 0:76dfa9657d9d | 18 | #include "ble_ranges.h" |
jksoft | 0:76dfa9657d9d | 19 | #include "ble_l2cap.h" |
jksoft | 0:76dfa9657d9d | 20 | #include "ble_gap.h" |
jksoft | 0:76dfa9657d9d | 21 | #include "ble_gatt.h" |
jksoft | 0:76dfa9657d9d | 22 | #include "nrf_svc.h" |
jksoft | 0:76dfa9657d9d | 23 | |
jksoft | 0:76dfa9657d9d | 24 | /** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations |
jksoft | 0:76dfa9657d9d | 25 | * @{ */ |
jksoft | 0:76dfa9657d9d | 26 | |
jksoft | 0:76dfa9657d9d | 27 | /** |
jksoft | 0:76dfa9657d9d | 28 | * @brief GATTS API SVC numbers. |
jksoft | 0:76dfa9657d9d | 29 | */ |
jksoft | 0:76dfa9657d9d | 30 | enum BLE_GATTS_SVCS |
jksoft | 0:76dfa9657d9d | 31 | { |
jksoft | 0:76dfa9657d9d | 32 | SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */ |
jksoft | 0:76dfa9657d9d | 33 | SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */ |
jksoft | 0:76dfa9657d9d | 34 | SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */ |
jksoft | 0:76dfa9657d9d | 35 | SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */ |
jksoft | 0:76dfa9657d9d | 36 | SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */ |
jksoft | 0:76dfa9657d9d | 37 | SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */ |
jksoft | 0:76dfa9657d9d | 38 | SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */ |
jksoft | 0:76dfa9657d9d | 39 | SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */ |
jksoft | 0:76dfa9657d9d | 40 | SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */ |
jksoft | 0:76dfa9657d9d | 41 | SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */ |
jksoft | 0:76dfa9657d9d | 42 | SD_BLE_GATTS_SYS_ATTR_GET, /**< Get updated persistent system attributes after terminating a connection. */ |
jksoft | 0:76dfa9657d9d | 43 | }; |
jksoft | 0:76dfa9657d9d | 44 | |
jksoft | 0:76dfa9657d9d | 45 | /** @} */ |
jksoft | 0:76dfa9657d9d | 46 | |
jksoft | 0:76dfa9657d9d | 47 | /** @addtogroup BLE_GATTS_DEFINES Defines |
jksoft | 0:76dfa9657d9d | 48 | * @{ */ |
jksoft | 0:76dfa9657d9d | 49 | |
jksoft | 0:76dfa9657d9d | 50 | /** @brief Only the default MTU size of 23 is currently supported. */ |
jksoft | 0:76dfa9657d9d | 51 | #define GATT_RX_MTU 23 |
jksoft | 0:76dfa9657d9d | 52 | |
jksoft | 0:76dfa9657d9d | 53 | /** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS |
jksoft | 0:76dfa9657d9d | 54 | * @{ */ |
jksoft | 0:76dfa9657d9d | 55 | #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */ |
jksoft | 0:76dfa9657d9d | 56 | #define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */ |
jksoft | 0:76dfa9657d9d | 57 | /** @} */ |
jksoft | 0:76dfa9657d9d | 58 | |
jksoft | 0:76dfa9657d9d | 59 | /** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths |
jksoft | 0:76dfa9657d9d | 60 | * @{ */ |
jksoft | 0:76dfa9657d9d | 61 | #define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */ |
jksoft | 0:76dfa9657d9d | 62 | #define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */ |
jksoft | 0:76dfa9657d9d | 63 | /** @} */ |
jksoft | 0:76dfa9657d9d | 64 | |
jksoft | 0:76dfa9657d9d | 65 | /** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types |
jksoft | 0:76dfa9657d9d | 66 | * @{ */ |
jksoft | 0:76dfa9657d9d | 67 | #define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */ |
jksoft | 0:76dfa9657d9d | 68 | #define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */ |
jksoft | 0:76dfa9657d9d | 69 | #define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */ |
jksoft | 0:76dfa9657d9d | 70 | /** @} */ |
jksoft | 0:76dfa9657d9d | 71 | |
jksoft | 0:76dfa9657d9d | 72 | |
jksoft | 0:76dfa9657d9d | 73 | /** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types |
jksoft | 0:76dfa9657d9d | 74 | * @{ */ |
jksoft | 0:76dfa9657d9d | 75 | #define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */ |
jksoft | 0:76dfa9657d9d | 76 | #define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */ |
jksoft | 0:76dfa9657d9d | 77 | #define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */ |
jksoft | 0:76dfa9657d9d | 78 | #define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */ |
jksoft | 0:76dfa9657d9d | 79 | #define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */ |
jksoft | 0:76dfa9657d9d | 80 | #define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */ |
jksoft | 0:76dfa9657d9d | 81 | #define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */ |
jksoft | 0:76dfa9657d9d | 82 | #define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */ |
jksoft | 0:76dfa9657d9d | 83 | /** @} */ |
jksoft | 0:76dfa9657d9d | 84 | |
jksoft | 0:76dfa9657d9d | 85 | |
jksoft | 0:76dfa9657d9d | 86 | /** @defgroup BLE_GATTS_OPS GATT Server Operations |
jksoft | 0:76dfa9657d9d | 87 | * @{ */ |
jksoft | 0:76dfa9657d9d | 88 | #define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */ |
jksoft | 0:76dfa9657d9d | 89 | #define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */ |
jksoft | 0:76dfa9657d9d | 90 | #define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */ |
jksoft | 0:76dfa9657d9d | 91 | #define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */ |
jksoft | 0:76dfa9657d9d | 92 | #define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */ |
jksoft | 0:76dfa9657d9d | 93 | #define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */ |
jksoft | 0:76dfa9657d9d | 94 | #define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */ |
jksoft | 0:76dfa9657d9d | 95 | /** @} */ |
jksoft | 0:76dfa9657d9d | 96 | |
jksoft | 0:76dfa9657d9d | 97 | /** @defgroup BLE_GATTS_VLOCS GATT Value Locations |
jksoft | 0:76dfa9657d9d | 98 | * @{ */ |
jksoft | 0:76dfa9657d9d | 99 | #define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */ |
jksoft | 0:76dfa9657d9d | 100 | #define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */ |
jksoft | 0:76dfa9657d9d | 101 | #define BLE_GATTS_VLOC_USER 0x02 /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack |
jksoft | 0:76dfa9657d9d | 102 | will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */ |
jksoft | 0:76dfa9657d9d | 103 | /** @} */ |
jksoft | 0:76dfa9657d9d | 104 | |
jksoft | 0:76dfa9657d9d | 105 | /** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types |
jksoft | 0:76dfa9657d9d | 106 | * @{ */ |
jksoft | 0:76dfa9657d9d | 107 | #define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */ |
jksoft | 0:76dfa9657d9d | 108 | #define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */ |
jksoft | 0:76dfa9657d9d | 109 | #define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */ |
jksoft | 0:76dfa9657d9d | 110 | /** @} */ |
jksoft | 0:76dfa9657d9d | 111 | |
jksoft | 0:76dfa9657d9d | 112 | |
jksoft | 0:76dfa9657d9d | 113 | /** @} */ |
jksoft | 0:76dfa9657d9d | 114 | |
jksoft | 0:76dfa9657d9d | 115 | /** @addtogroup BLE_GATTS_STRUCTURES Structures |
jksoft | 0:76dfa9657d9d | 116 | * @{ */ |
jksoft | 0:76dfa9657d9d | 117 | |
jksoft | 0:76dfa9657d9d | 118 | /** |
jksoft | 0:76dfa9657d9d | 119 | * @brief BLE GATTS init options |
jksoft | 0:76dfa9657d9d | 120 | */ |
jksoft | 0:76dfa9657d9d | 121 | typedef struct |
jksoft | 0:76dfa9657d9d | 122 | { |
jksoft | 0:76dfa9657d9d | 123 | uint8_t service_changed:1; /**< Include the Service Changed characteristic in the local attributes. */ |
jksoft | 0:76dfa9657d9d | 124 | } ble_gatts_enable_params_t; |
jksoft | 0:76dfa9657d9d | 125 | |
jksoft | 0:76dfa9657d9d | 126 | /**@brief Attribute metadata. */ |
jksoft | 0:76dfa9657d9d | 127 | typedef struct |
jksoft | 0:76dfa9657d9d | 128 | { |
jksoft | 0:76dfa9657d9d | 129 | ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ |
jksoft | 0:76dfa9657d9d | 130 | ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ |
jksoft | 0:76dfa9657d9d | 131 | uint8_t vlen :1; /**< Variable length attribute. */ |
jksoft | 0:76dfa9657d9d | 132 | uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/ |
jksoft | 0:76dfa9657d9d | 133 | uint8_t rd_auth :1; /**< Read Authorization and value will be requested from the application on every read operation. */ |
jksoft | 0:76dfa9657d9d | 134 | uint8_t wr_auth :1; /**< Write Authorization will be requested from the application on every Write Request operation (but not Write Command). */ |
jksoft | 0:76dfa9657d9d | 135 | } ble_gatts_attr_md_t; |
jksoft | 0:76dfa9657d9d | 136 | |
jksoft | 0:76dfa9657d9d | 137 | |
jksoft | 0:76dfa9657d9d | 138 | /**@brief GATT Attribute. */ |
jksoft | 0:76dfa9657d9d | 139 | typedef struct |
jksoft | 0:76dfa9657d9d | 140 | { |
jksoft | 0:76dfa9657d9d | 141 | ble_uuid_t* p_uuid; /**< Pointer to the attribute UUID. */ |
jksoft | 0:76dfa9657d9d | 142 | ble_gatts_attr_md_t* p_attr_md; /**< Pointer to the attribute metadata structure. */ |
jksoft | 0:76dfa9657d9d | 143 | uint16_t init_len; /**< Initial attribute value length in bytes. */ |
jksoft | 0:76dfa9657d9d | 144 | uint16_t init_offs; /**< Initial attribute value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */ |
jksoft | 0:76dfa9657d9d | 145 | uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */ |
jksoft | 0:76dfa9657d9d | 146 | uint8_t* p_value; /**< Pointer to the attribute data. Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer |
jksoft | 0:76dfa9657d9d | 147 | that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location. |
jksoft | 0:76dfa9657d9d | 148 | The stack may access that memory directly without the application's knowledge. */ |
jksoft | 0:76dfa9657d9d | 149 | } ble_gatts_attr_t; |
jksoft | 0:76dfa9657d9d | 150 | |
jksoft | 0:76dfa9657d9d | 151 | |
jksoft | 0:76dfa9657d9d | 152 | /**@brief GATT Attribute Context. */ |
jksoft | 0:76dfa9657d9d | 153 | typedef struct |
jksoft | 0:76dfa9657d9d | 154 | { |
jksoft | 0:76dfa9657d9d | 155 | ble_uuid_t srvc_uuid; /**< Service UUID. */ |
jksoft | 0:76dfa9657d9d | 156 | ble_uuid_t char_uuid; /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */ |
jksoft | 0:76dfa9657d9d | 157 | ble_uuid_t desc_uuid; /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */ |
jksoft | 0:76dfa9657d9d | 158 | uint16_t srvc_handle; /**< Service Handle. */ |
jksoft | 0:76dfa9657d9d | 159 | uint16_t value_handle; /**< Characteristic Handle if applicable (BLE_GATT_HANDLE_INVALID if N/A). */ |
jksoft | 0:76dfa9657d9d | 160 | uint8_t type; /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */ |
jksoft | 0:76dfa9657d9d | 161 | } ble_gatts_attr_context_t; |
jksoft | 0:76dfa9657d9d | 162 | |
jksoft | 0:76dfa9657d9d | 163 | |
jksoft | 0:76dfa9657d9d | 164 | /**@brief GATT Characteristic Presentation Format. */ |
jksoft | 0:76dfa9657d9d | 165 | typedef struct |
jksoft | 0:76dfa9657d9d | 166 | { |
jksoft | 0:76dfa9657d9d | 167 | uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */ |
jksoft | 0:76dfa9657d9d | 168 | int8_t exponent; /**< Exponent for integer data types. */ |
jksoft | 0:76dfa9657d9d | 169 | uint16_t unit; /**< UUID from Bluetooth Assigned Numbers. */ |
jksoft | 0:76dfa9657d9d | 170 | uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */ |
jksoft | 0:76dfa9657d9d | 171 | uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */ |
jksoft | 0:76dfa9657d9d | 172 | } ble_gatts_char_pf_t; |
jksoft | 0:76dfa9657d9d | 173 | |
jksoft | 0:76dfa9657d9d | 174 | |
jksoft | 0:76dfa9657d9d | 175 | /**@brief GATT Characteristic metadata. */ |
jksoft | 0:76dfa9657d9d | 176 | typedef struct |
jksoft | 0:76dfa9657d9d | 177 | { |
jksoft | 0:76dfa9657d9d | 178 | ble_gatt_char_props_t char_props; /**< Characteristic Properties. */ |
jksoft | 0:76dfa9657d9d | 179 | ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */ |
jksoft | 0:76dfa9657d9d | 180 | uint8_t* p_char_user_desc; /**< Pointer to a UTF-8, NULL if the descriptor is not required. */ |
jksoft | 0:76dfa9657d9d | 181 | uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */ |
jksoft | 0:76dfa9657d9d | 182 | uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */ |
jksoft | 0:76dfa9657d9d | 183 | ble_gatts_char_pf_t* p_char_pf; /**< Pointer to a presentation format structure or NULL if the descriptor is not required. */ |
jksoft | 0:76dfa9657d9d | 184 | ble_gatts_attr_md_t* p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */ |
jksoft | 0:76dfa9657d9d | 185 | ble_gatts_attr_md_t* p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */ |
jksoft | 0:76dfa9657d9d | 186 | ble_gatts_attr_md_t* p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */ |
jksoft | 0:76dfa9657d9d | 187 | } ble_gatts_char_md_t; |
jksoft | 0:76dfa9657d9d | 188 | |
jksoft | 0:76dfa9657d9d | 189 | |
jksoft | 0:76dfa9657d9d | 190 | /**@brief GATT Characteristic Definition Handles. */ |
jksoft | 0:76dfa9657d9d | 191 | typedef struct |
jksoft | 0:76dfa9657d9d | 192 | { |
jksoft | 0:76dfa9657d9d | 193 | uint16_t value_handle; /**< Handle to the characteristic value. */ |
jksoft | 0:76dfa9657d9d | 194 | uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or BLE_GATT_HANDLE_INVALID if not present. */ |
jksoft | 0:76dfa9657d9d | 195 | uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */ |
jksoft | 0:76dfa9657d9d | 196 | uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */ |
jksoft | 0:76dfa9657d9d | 197 | } ble_gatts_char_handles_t; |
jksoft | 0:76dfa9657d9d | 198 | |
jksoft | 0:76dfa9657d9d | 199 | |
jksoft | 0:76dfa9657d9d | 200 | /**@brief GATT HVx parameters. */ |
jksoft | 0:76dfa9657d9d | 201 | typedef struct |
jksoft | 0:76dfa9657d9d | 202 | { |
jksoft | 0:76dfa9657d9d | 203 | uint16_t handle; /**< Characteristic Value Handle. */ |
jksoft | 0:76dfa9657d9d | 204 | uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */ |
jksoft | 0:76dfa9657d9d | 205 | uint16_t offset; /**< Offset within the attribute value. */ |
jksoft | 0:76dfa9657d9d | 206 | uint16_t* p_len; /**< Length in bytes to be written, length in bytes written after successful return. */ |
jksoft | 0:76dfa9657d9d | 207 | uint8_t* p_data; /**< Actual data content, use NULL to use the current attribute value. */ |
jksoft | 0:76dfa9657d9d | 208 | } ble_gatts_hvx_params_t; |
jksoft | 0:76dfa9657d9d | 209 | |
jksoft | 0:76dfa9657d9d | 210 | /**@brief GATT Read Authorization parameters. */ |
jksoft | 0:76dfa9657d9d | 211 | typedef struct |
jksoft | 0:76dfa9657d9d | 212 | { |
jksoft | 0:76dfa9657d9d | 213 | uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */ |
jksoft | 0:76dfa9657d9d | 214 | uint8_t update : 1; /**< If set, data supplied in p_data will be used in the ATT response. */ |
jksoft | 0:76dfa9657d9d | 215 | uint16_t offset; /**< Offset of the attribute value being updated. */ |
jksoft | 0:76dfa9657d9d | 216 | uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */ |
jksoft | 0:76dfa9657d9d | 217 | uint8_t* p_data; /**< Pointer to new value used to update the attribute value. */ |
jksoft | 0:76dfa9657d9d | 218 | } ble_gatts_read_authorize_params_t; |
jksoft | 0:76dfa9657d9d | 219 | |
jksoft | 0:76dfa9657d9d | 220 | /**@brief GATT Write Authorisation parameters. */ |
jksoft | 0:76dfa9657d9d | 221 | typedef struct |
jksoft | 0:76dfa9657d9d | 222 | { |
jksoft | 0:76dfa9657d9d | 223 | uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */ |
jksoft | 0:76dfa9657d9d | 224 | } ble_gatts_write_authorize_params_t; |
jksoft | 0:76dfa9657d9d | 225 | |
jksoft | 0:76dfa9657d9d | 226 | /**@brief GATT Read or Write Authorize Reply parameters. */ |
jksoft | 0:76dfa9657d9d | 227 | typedef struct |
jksoft | 0:76dfa9657d9d | 228 | { |
jksoft | 0:76dfa9657d9d | 229 | uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */ |
jksoft | 0:76dfa9657d9d | 230 | union { |
jksoft | 0:76dfa9657d9d | 231 | ble_gatts_read_authorize_params_t read; /**< Read authorization parameters. */ |
jksoft | 0:76dfa9657d9d | 232 | ble_gatts_write_authorize_params_t write; /**< Write authorization parameters. */ |
jksoft | 0:76dfa9657d9d | 233 | } params; |
jksoft | 0:76dfa9657d9d | 234 | } ble_gatts_rw_authorize_reply_params_t; |
jksoft | 0:76dfa9657d9d | 235 | |
jksoft | 0:76dfa9657d9d | 236 | |
jksoft | 0:76dfa9657d9d | 237 | /** |
jksoft | 0:76dfa9657d9d | 238 | * @brief GATT Server Event IDs. |
jksoft | 0:76dfa9657d9d | 239 | */ |
jksoft | 0:76dfa9657d9d | 240 | enum BLE_GATTS_EVTS |
jksoft | 0:76dfa9657d9d | 241 | { |
jksoft | 0:76dfa9657d9d | 242 | BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. */ |
jksoft | 0:76dfa9657d9d | 243 | BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request. */ |
jksoft | 0:76dfa9657d9d | 244 | BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). */ |
jksoft | 0:76dfa9657d9d | 245 | BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. */ |
jksoft | 0:76dfa9657d9d | 246 | BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. */ |
jksoft | 0:76dfa9657d9d | 247 | BLE_GATTS_EVT_TIMEOUT /**< Timeout. */ |
jksoft | 0:76dfa9657d9d | 248 | }; |
jksoft | 0:76dfa9657d9d | 249 | |
jksoft | 0:76dfa9657d9d | 250 | |
jksoft | 0:76dfa9657d9d | 251 | /**@brief Event structure for BLE_GATTS_EVT_WRITE. */ |
jksoft | 0:76dfa9657d9d | 252 | typedef struct |
jksoft | 0:76dfa9657d9d | 253 | { |
jksoft | 0:76dfa9657d9d | 254 | uint16_t handle; /**< Attribute Handle. */ |
jksoft | 0:76dfa9657d9d | 255 | uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */ |
jksoft | 0:76dfa9657d9d | 256 | ble_gatts_attr_context_t context; /**< Attribute Context. */ |
jksoft | 0:76dfa9657d9d | 257 | uint16_t offset; /**< Offset for the write operation. */ |
jksoft | 0:76dfa9657d9d | 258 | uint16_t len; /**< Length of the incoming data. */ |
jksoft | 0:76dfa9657d9d | 259 | uint8_t data[1]; /**< Incoming data, variable length. */ |
jksoft | 0:76dfa9657d9d | 260 | } ble_gatts_evt_write_t; |
jksoft | 0:76dfa9657d9d | 261 | |
jksoft | 0:76dfa9657d9d | 262 | /**@brief Event structure for authorize read request. */ |
jksoft | 0:76dfa9657d9d | 263 | typedef struct |
jksoft | 0:76dfa9657d9d | 264 | { |
jksoft | 0:76dfa9657d9d | 265 | uint16_t handle; /**< Attribute Handle. */ |
jksoft | 0:76dfa9657d9d | 266 | ble_gatts_attr_context_t context; /**< Attribute Context. */ |
jksoft | 0:76dfa9657d9d | 267 | uint16_t offset; /**< Offset for the read operation. */ |
jksoft | 0:76dfa9657d9d | 268 | } ble_gatts_evt_read_t; |
jksoft | 0:76dfa9657d9d | 269 | |
jksoft | 0:76dfa9657d9d | 270 | /**@brief Event structure for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */ |
jksoft | 0:76dfa9657d9d | 271 | typedef struct |
jksoft | 0:76dfa9657d9d | 272 | { |
jksoft | 0:76dfa9657d9d | 273 | uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */ |
jksoft | 0:76dfa9657d9d | 274 | union { |
jksoft | 0:76dfa9657d9d | 275 | ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */ |
jksoft | 0:76dfa9657d9d | 276 | ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */ |
jksoft | 0:76dfa9657d9d | 277 | } request; |
jksoft | 0:76dfa9657d9d | 278 | } ble_gatts_evt_rw_authorize_request_t; |
jksoft | 0:76dfa9657d9d | 279 | |
jksoft | 0:76dfa9657d9d | 280 | /**@brief Event structure for BLE_GATTS_EVT_SYS_ATTR_MISSING. */ |
jksoft | 0:76dfa9657d9d | 281 | typedef struct |
jksoft | 0:76dfa9657d9d | 282 | { |
jksoft | 0:76dfa9657d9d | 283 | uint8_t hint; |
jksoft | 0:76dfa9657d9d | 284 | } ble_gatts_evt_sys_attr_missing_t; |
jksoft | 0:76dfa9657d9d | 285 | |
jksoft | 0:76dfa9657d9d | 286 | |
jksoft | 0:76dfa9657d9d | 287 | /**@brief Event structure for BLE_GATTS_EVT_HVC. */ |
jksoft | 0:76dfa9657d9d | 288 | typedef struct |
jksoft | 0:76dfa9657d9d | 289 | { |
jksoft | 0:76dfa9657d9d | 290 | uint16_t handle; /**< Attribute Handle. */ |
jksoft | 0:76dfa9657d9d | 291 | } ble_gatts_evt_hvc_t; |
jksoft | 0:76dfa9657d9d | 292 | |
jksoft | 0:76dfa9657d9d | 293 | /**@brief Event structure for BLE_GATTS_EVT_TIMEOUT. */ |
jksoft | 0:76dfa9657d9d | 294 | typedef struct |
jksoft | 0:76dfa9657d9d | 295 | { |
jksoft | 0:76dfa9657d9d | 296 | uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */ |
jksoft | 0:76dfa9657d9d | 297 | } ble_gatts_evt_timeout_t; |
jksoft | 0:76dfa9657d9d | 298 | |
jksoft | 0:76dfa9657d9d | 299 | |
jksoft | 0:76dfa9657d9d | 300 | /**@brief GATT Server event callback event structure. */ |
jksoft | 0:76dfa9657d9d | 301 | typedef struct |
jksoft | 0:76dfa9657d9d | 302 | { |
jksoft | 0:76dfa9657d9d | 303 | uint16_t conn_handle; /**< Connection Handle on which event occurred. */ |
jksoft | 0:76dfa9657d9d | 304 | union |
jksoft | 0:76dfa9657d9d | 305 | { |
jksoft | 0:76dfa9657d9d | 306 | ble_gatts_evt_write_t write; /**< Write Event Parameters. */ |
jksoft | 0:76dfa9657d9d | 307 | ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */ |
jksoft | 0:76dfa9657d9d | 308 | ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */ |
jksoft | 0:76dfa9657d9d | 309 | ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */ |
jksoft | 0:76dfa9657d9d | 310 | ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */ |
jksoft | 0:76dfa9657d9d | 311 | } params; |
jksoft | 0:76dfa9657d9d | 312 | } ble_gatts_evt_t; |
jksoft | 0:76dfa9657d9d | 313 | |
jksoft | 0:76dfa9657d9d | 314 | /** @} */ |
jksoft | 0:76dfa9657d9d | 315 | |
jksoft | 0:76dfa9657d9d | 316 | /** @addtogroup BLE_GATTS_FUNCTIONS Functions |
jksoft | 0:76dfa9657d9d | 317 | * @{ */ |
jksoft | 0:76dfa9657d9d | 318 | |
jksoft | 0:76dfa9657d9d | 319 | /**@brief Add a service declaration to the local server ATT table. |
jksoft | 0:76dfa9657d9d | 320 | * |
jksoft | 0:76dfa9657d9d | 321 | * @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES. |
jksoft | 0:76dfa9657d9d | 322 | * @param[in] p_uuid Pointer to service UUID. |
jksoft | 0:76dfa9657d9d | 323 | * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored. |
jksoft | 0:76dfa9657d9d | 324 | * |
jksoft | 0:76dfa9657d9d | 325 | * @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to |
jksoft | 0:76dfa9657d9d | 326 | * add a secondary service declaration that is not referenced by another service later in the ATT table. |
jksoft | 0:76dfa9657d9d | 327 | * |
jksoft | 0:76dfa9657d9d | 328 | * @return @ref NRF_SUCCESS Successfully added a service declaration. |
jksoft | 0:76dfa9657d9d | 329 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 330 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table. |
jksoft | 0:76dfa9657d9d | 331 | * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. |
jksoft | 0:76dfa9657d9d | 332 | * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation. |
jksoft | 0:76dfa9657d9d | 333 | */ |
jksoft | 0:76dfa9657d9d | 334 | SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const*const p_uuid, uint16_t *const p_handle)); |
jksoft | 0:76dfa9657d9d | 335 | |
jksoft | 0:76dfa9657d9d | 336 | |
jksoft | 0:76dfa9657d9d | 337 | /**@brief Add an include declaration to the local server ATT table. |
jksoft | 0:76dfa9657d9d | 338 | * |
jksoft | 0:76dfa9657d9d | 339 | * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential addition is supported at this time). |
jksoft | 0:76dfa9657d9d | 340 | * |
jksoft | 0:76dfa9657d9d | 341 | * @note The included service must already be present in the ATT table prior to this call. |
jksoft | 0:76dfa9657d9d | 342 | * |
jksoft | 0:76dfa9657d9d | 343 | * @param[in] service_handle Handle of the service where the included service is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. |
jksoft | 0:76dfa9657d9d | 344 | * @param[in] inc_srvc_handle Handle of the included service. |
jksoft | 0:76dfa9657d9d | 345 | * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored. |
jksoft | 0:76dfa9657d9d | 346 | * |
jksoft | 0:76dfa9657d9d | 347 | * @return @ref NRF_SUCCESS Successfully added an include declaration. |
jksoft | 0:76dfa9657d9d | 348 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 349 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services. |
jksoft | 0:76dfa9657d9d | 350 | * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation. |
jksoft | 0:76dfa9657d9d | 351 | * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed. |
jksoft | 0:76dfa9657d9d | 352 | * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation. |
jksoft | 0:76dfa9657d9d | 353 | * @return @ref NRF_ERROR_NOT_FOUND Attribute not found. |
jksoft | 0:76dfa9657d9d | 354 | */ |
jksoft | 0:76dfa9657d9d | 355 | SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *const p_include_handle)); |
jksoft | 0:76dfa9657d9d | 356 | |
jksoft | 0:76dfa9657d9d | 357 | |
jksoft | 0:76dfa9657d9d | 358 | /**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the local server ATT table. |
jksoft | 0:76dfa9657d9d | 359 | * |
jksoft | 0:76dfa9657d9d | 360 | * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential addition is supported at this time). |
jksoft | 0:76dfa9657d9d | 361 | * |
jksoft | 0:76dfa9657d9d | 362 | * @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits, |
jksoft | 0:76dfa9657d9d | 363 | * readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values. |
jksoft | 0:76dfa9657d9d | 364 | * |
jksoft | 0:76dfa9657d9d | 365 | * @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions. |
jksoft | 0:76dfa9657d9d | 366 | * |
jksoft | 0:76dfa9657d9d | 367 | * @param[in] service_handle Handle of the service where the characteristic is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. |
jksoft | 0:76dfa9657d9d | 368 | * @param[in] p_char_md Characteristic metadata. |
jksoft | 0:76dfa9657d9d | 369 | * @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value. |
jksoft | 0:76dfa9657d9d | 370 | * @param[out] p_handles Pointer to the structure where the assigned handles will be stored. |
jksoft | 0:76dfa9657d9d | 371 | * |
jksoft | 0:76dfa9657d9d | 372 | * @return @ref NRF_SUCCESS Successfully added a characteristic. |
jksoft | 0:76dfa9657d9d | 373 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 374 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints. |
jksoft | 0:76dfa9657d9d | 375 | * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required. |
jksoft | 0:76dfa9657d9d | 376 | * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. |
jksoft | 0:76dfa9657d9d | 377 | * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation. |
jksoft | 0:76dfa9657d9d | 378 | * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. |
jksoft | 0:76dfa9657d9d | 379 | */ |
jksoft | 0:76dfa9657d9d | 380 | SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const*const p_char_md, ble_gatts_attr_t const*const p_attr_char_value, ble_gatts_char_handles_t *const p_handles)); |
jksoft | 0:76dfa9657d9d | 381 | |
jksoft | 0:76dfa9657d9d | 382 | |
jksoft | 0:76dfa9657d9d | 383 | /**@brief Add a descriptor to the local server ATT table. |
jksoft | 0:76dfa9657d9d | 384 | * |
jksoft | 0:76dfa9657d9d | 385 | * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential addition is supported at this time). |
jksoft | 0:76dfa9657d9d | 386 | * |
jksoft | 0:76dfa9657d9d | 387 | * @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially. |
jksoft | 0:76dfa9657d9d | 388 | * @param[in] p_attr Pointer to the attribute structure. |
jksoft | 0:76dfa9657d9d | 389 | * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored. |
jksoft | 0:76dfa9657d9d | 390 | * |
jksoft | 0:76dfa9657d9d | 391 | * @return @ref NRF_SUCCESS Successfully added a descriptor. |
jksoft | 0:76dfa9657d9d | 392 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 393 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints. |
jksoft | 0:76dfa9657d9d | 394 | * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required. |
jksoft | 0:76dfa9657d9d | 395 | * @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack. |
jksoft | 0:76dfa9657d9d | 396 | * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation. |
jksoft | 0:76dfa9657d9d | 397 | * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. |
jksoft | 0:76dfa9657d9d | 398 | */ |
jksoft | 0:76dfa9657d9d | 399 | SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const * const p_attr, uint16_t* const p_handle)); |
jksoft | 0:76dfa9657d9d | 400 | |
jksoft | 0:76dfa9657d9d | 401 | /**@brief Set the value of a given attribute. |
jksoft | 0:76dfa9657d9d | 402 | * |
jksoft | 0:76dfa9657d9d | 403 | * @param[in] handle Attribute handle. |
jksoft | 0:76dfa9657d9d | 404 | * @param[in] offset Offset in bytes to write from. |
jksoft | 0:76dfa9657d9d | 405 | * @param[in,out] p_len Length in bytes to be written, length in bytes written after successful return. |
jksoft | 0:76dfa9657d9d | 406 | * @param[in] p_value Pointer to a buffer (at least len bytes long) containing the desired attribute value. If value is stored in user memory, only the attribute length is updated when p_value == NULL. |
jksoft | 0:76dfa9657d9d | 407 | * |
jksoft | 0:76dfa9657d9d | 408 | * @return @ref NRF_SUCCESS Successfully set the value of the attribute. |
jksoft | 0:76dfa9657d9d | 409 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 410 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. |
jksoft | 0:76dfa9657d9d | 411 | * @return @ref NRF_ERROR_NOT_FOUND Attribute not found. |
jksoft | 0:76dfa9657d9d | 412 | * @return @ref NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application. |
jksoft | 0:76dfa9657d9d | 413 | * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX. |
jksoft | 0:76dfa9657d9d | 414 | */ |
jksoft | 0:76dfa9657d9d | 415 | SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t handle, uint16_t offset, uint16_t* const p_len, uint8_t const * const p_value)); |
jksoft | 0:76dfa9657d9d | 416 | |
jksoft | 0:76dfa9657d9d | 417 | /**@brief Get the value of a given attribute. |
jksoft | 0:76dfa9657d9d | 418 | * |
jksoft | 0:76dfa9657d9d | 419 | * @param[in] handle Attribute handle. |
jksoft | 0:76dfa9657d9d | 420 | * @param[in] offset Offset in bytes to read from. |
jksoft | 0:76dfa9657d9d | 421 | * @param[in,out] p_len Length in bytes to be read, total length of attribute value (in bytes, starting from offset) after successful return. |
jksoft | 0:76dfa9657d9d | 422 | * @param[in,out] p_data Pointer to a buffer (at least len bytes long) where to store the attribute value. Set to NULL to obtain the complete length of attribute value. |
jksoft | 0:76dfa9657d9d | 423 | * |
jksoft | 0:76dfa9657d9d | 424 | * @note If the attribute value is longer than the size of the supplied buffer, |
jksoft | 0:76dfa9657d9d | 425 | * p_len will return the total attribute value length (excluding offset), |
jksoft | 0:76dfa9657d9d | 426 | * and not the number of bytes actually returned in p_data. |
jksoft | 0:76dfa9657d9d | 427 | * The application may use this information to allocate a suitable buffer size. |
jksoft | 0:76dfa9657d9d | 428 | * |
jksoft | 0:76dfa9657d9d | 429 | * @return @ref NRF_SUCCESS Successfully retrieved the value of the attribute. |
jksoft | 0:76dfa9657d9d | 430 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 431 | * @return @ref NRF_ERROR_NOT_FOUND Attribute not found. |
jksoft | 0:76dfa9657d9d | 432 | */ |
jksoft | 0:76dfa9657d9d | 433 | SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t handle, uint16_t offset, uint16_t *const p_len, uint8_t* const p_data)); |
jksoft | 0:76dfa9657d9d | 434 | |
jksoft | 0:76dfa9657d9d | 435 | /**@brief Notify or Indicate an attribute value. |
jksoft | 0:76dfa9657d9d | 436 | * |
jksoft | 0:76dfa9657d9d | 437 | * @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation |
jksoft | 0:76dfa9657d9d | 438 | * (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that |
jksoft | 0:76dfa9657d9d | 439 | * the application can atomically perform a value update and a server initiated transaction with a single API call. |
jksoft | 0:76dfa9657d9d | 440 | * If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC will be sent up as soon as the confirmation arrives from |
jksoft | 0:76dfa9657d9d | 441 | * the peer. |
jksoft | 0:76dfa9657d9d | 442 | * |
jksoft | 0:76dfa9657d9d | 443 | * @note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution. |
jksoft | 0:76dfa9657d9d | 444 | * When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and |
jksoft | 0:76dfa9657d9d | 445 | * @ref BLE_ERROR_NO_TX_BUFFERS the ATT table has been updated. |
jksoft | 0:76dfa9657d9d | 446 | * The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len). |
jksoft | 0:76dfa9657d9d | 447 | * |
jksoft | 0:76dfa9657d9d | 448 | * @note It is important to note that a notification will <b>consume an application buffer</b>, and will therefore |
jksoft | 0:76dfa9657d9d | 449 | * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the |
jksoft | 0:76dfa9657d9d | 450 | * standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation |
jksoft | 0:76dfa9657d9d | 451 | * has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details. |
jksoft | 0:76dfa9657d9d | 452 | * |
jksoft | 0:76dfa9657d9d | 453 | * @param[in] conn_handle Connection handle. |
jksoft | 0:76dfa9657d9d | 454 | * @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with |
jksoft | 0:76dfa9657d9d | 455 | * the contents pointed by it before sending the notification or indication. |
jksoft | 0:76dfa9657d9d | 456 | * |
jksoft | 0:76dfa9657d9d | 457 | * @return @ref NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value. |
jksoft | 0:76dfa9657d9d | 458 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
jksoft | 0:76dfa9657d9d | 459 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 460 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. |
jksoft | 0:76dfa9657d9d | 461 | * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate. |
jksoft | 0:76dfa9657d9d | 462 | * @return @ref BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated. |
jksoft | 0:76dfa9657d9d | 463 | * @return @ref NRF_ERROR_NOT_FOUND Attribute not found. |
jksoft | 0:76dfa9657d9d | 464 | * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied. |
jksoft | 0:76dfa9657d9d | 465 | * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD. |
jksoft | 0:76dfa9657d9d | 466 | * @return @ref NRF_ERROR_BUSY Procedure already in progress. |
jksoft | 0:76dfa9657d9d | 467 | * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value. |
jksoft | 0:76dfa9657d9d | 468 | * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications. |
jksoft | 0:76dfa9657d9d | 469 | */ |
jksoft | 0:76dfa9657d9d | 470 | SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const*const p_hvx_params)); |
jksoft | 0:76dfa9657d9d | 471 | |
jksoft | 0:76dfa9657d9d | 472 | /**@brief Indicate the Service Changed attribute value. |
jksoft | 0:76dfa9657d9d | 473 | * |
jksoft | 0:76dfa9657d9d | 474 | * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the attribute |
jksoft | 0:76dfa9657d9d | 475 | * table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will |
jksoft | 0:76dfa9657d9d | 476 | * be issued. |
jksoft | 0:76dfa9657d9d | 477 | * |
jksoft | 0:76dfa9657d9d | 478 | * @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here. |
jksoft | 0:76dfa9657d9d | 479 | * |
jksoft | 0:76dfa9657d9d | 480 | * @param[in] conn_handle Connection handle. |
jksoft | 0:76dfa9657d9d | 481 | * @param[in] start_handle Start of affected attribute handle range. |
jksoft | 0:76dfa9657d9d | 482 | * @param[in] end_handle End of affected attribute handle range. |
jksoft | 0:76dfa9657d9d | 483 | * |
jksoft | 0:76dfa9657d9d | 484 | * @return @ref NRF_SUCCESS Successfully queued the Service Changed indication for transmission. |
jksoft | 0:76dfa9657d9d | 485 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
jksoft | 0:76dfa9657d9d | 486 | * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. |
jksoft | 0:76dfa9657d9d | 487 | * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application. |
jksoft | 0:76dfa9657d9d | 488 | * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD. |
jksoft | 0:76dfa9657d9d | 489 | * @return @ref NRF_ERROR_BUSY Procedure already in progress. |
jksoft | 0:76dfa9657d9d | 490 | * @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value. |
jksoft | 0:76dfa9657d9d | 491 | */ |
jksoft | 0:76dfa9657d9d | 492 | SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle)); |
jksoft | 0:76dfa9657d9d | 493 | |
jksoft | 0:76dfa9657d9d | 494 | /**@brief Respond to a Read/Write authorization request. |
jksoft | 0:76dfa9657d9d | 495 | * |
jksoft | 0:76dfa9657d9d | 496 | * @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application. |
jksoft | 0:76dfa9657d9d | 497 | * |
jksoft | 0:76dfa9657d9d | 498 | * @param[in] conn_handle Connection handle. |
jksoft | 0:76dfa9657d9d | 499 | * @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application. |
jksoft | 0:76dfa9657d9d | 500 | * |
jksoft | 0:76dfa9657d9d | 501 | * @return @ref NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, ATT table updated. |
jksoft | 0:76dfa9657d9d | 502 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
jksoft | 0:76dfa9657d9d | 503 | * @return @ref NRF_ERROR_INVALID_STATE No authorization request pending. |
jksoft | 0:76dfa9657d9d | 504 | * @return @ref NRF_ERROR_INVALID_PARAM Authorization op invalid, |
jksoft | 0:76dfa9657d9d | 505 | * or for Read Authorization reply: requested handles not replied with, |
jksoft | 0:76dfa9657d9d | 506 | * or for Write Authorization reply: handle supplied does not match requested handle. |
jksoft | 0:76dfa9657d9d | 507 | */ |
jksoft | 0:76dfa9657d9d | 508 | SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const*const p_rw_authorize_reply_params)); |
jksoft | 0:76dfa9657d9d | 509 | |
jksoft | 0:76dfa9657d9d | 510 | |
jksoft | 0:76dfa9657d9d | 511 | /**@brief Update persistent system attribute information. |
jksoft | 0:76dfa9657d9d | 512 | * |
jksoft | 0:76dfa9657d9d | 513 | * @details Supply to the stack information about persistent system attributes. |
jksoft | 0:76dfa9657d9d | 514 | * This call is legal in the connected state only, and is usually |
jksoft | 0:76dfa9657d9d | 515 | * made immediately after a connection is established and the bond identified. |
jksoft | 0:76dfa9657d9d | 516 | * usually as a response to a BLE_GATTS_EVT_SYS_ATTR_MISSING. |
jksoft | 0:76dfa9657d9d | 517 | * |
jksoft | 0:76dfa9657d9d | 518 | * p_sysattrs may point directly to the application's stored copy of the struct. |
jksoft | 0:76dfa9657d9d | 519 | * If the pointer is NULL, the system attribute info is initialized, assuming that |
jksoft | 0:76dfa9657d9d | 520 | * the application does not have any previously saved data for this bond. |
jksoft | 0:76dfa9657d9d | 521 | * |
jksoft | 0:76dfa9657d9d | 522 | * @note The state of persistent system attributes is reset upon connection and then remembered for its duration. |
jksoft | 0:76dfa9657d9d | 523 | * |
jksoft | 0:76dfa9657d9d | 524 | * @note If this call returns with an error code different from @ref NRF_SUCCESS, the storage of persistent system attributes may have been completed only partially. |
jksoft | 0:76dfa9657d9d | 525 | * This means that the state of the attribute table is undefined, and the application should either provide a new set of attributes using this same call or |
jksoft | 0:76dfa9657d9d | 526 | * reset the SoftDevice to return to a known state. |
jksoft | 0:76dfa9657d9d | 527 | * |
jksoft | 0:76dfa9657d9d | 528 | * @param[in] conn_handle Connection handle. |
jksoft | 0:76dfa9657d9d | 529 | * @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL. |
jksoft | 0:76dfa9657d9d | 530 | * @param[in] len Size of data pointed by p_sys_attr_data, in octets. |
jksoft | 0:76dfa9657d9d | 531 | * |
jksoft | 0:76dfa9657d9d | 532 | * @return @ref NRF_SUCCESS Successfully set the system attribute information. |
jksoft | 0:76dfa9657d9d | 533 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
jksoft | 0:76dfa9657d9d | 534 | * @return @ref NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get. |
jksoft | 0:76dfa9657d9d | 535 | * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation. |
jksoft | 0:76dfa9657d9d | 536 | */ |
jksoft | 0:76dfa9657d9d | 537 | SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const*const p_sys_attr_data, uint16_t len)); |
jksoft | 0:76dfa9657d9d | 538 | |
jksoft | 0:76dfa9657d9d | 539 | |
jksoft | 0:76dfa9657d9d | 540 | /**@brief Retrieve persistent system attribute information from the stack. |
jksoft | 0:76dfa9657d9d | 541 | * |
jksoft | 0:76dfa9657d9d | 542 | * @details This call is used to retrieve information about values to be stored perisistently by the application |
jksoft | 0:76dfa9657d9d | 543 | * after a connection has been terminated. When a new connection is made to the same bond, the values |
jksoft | 0:76dfa9657d9d | 544 | * should be restored using @ref sd_ble_gatts_sys_attr_set. |
jksoft | 0:76dfa9657d9d | 545 | * The data should be read before any new advertising is started, or any new connection established. The connection handle for |
jksoft | 0:76dfa9657d9d | 546 | * the previous now defunct connection will remain valid until a new one is created to allow this API call to refer to it. |
jksoft | 0:76dfa9657d9d | 547 | * |
jksoft | 0:76dfa9657d9d | 548 | * @param[in] conn_handle Connection handle of the recently terminated connection. |
jksoft | 0:76dfa9657d9d | 549 | * @param[in] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to |
jksoft | 0:76dfa9657d9d | 550 | * obtain the length of the data |
jksoft | 0:76dfa9657d9d | 551 | * @param[in,out] p_len Size of application buffer if p_sys_attr_data is not NULL. Unconditially updated to actual length of system attribute data. |
jksoft | 0:76dfa9657d9d | 552 | * |
jksoft | 0:76dfa9657d9d | 553 | * @return @ref NRF_SUCCESS Successfully retrieved the system attribute information. |
jksoft | 0:76dfa9657d9d | 554 | * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. |
jksoft | 0:76dfa9657d9d | 555 | * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. |
jksoft | 0:76dfa9657d9d | 556 | * @return @ref NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer. |
jksoft | 0:76dfa9657d9d | 557 | */ |
jksoft | 0:76dfa9657d9d | 558 | SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t * const p_sys_attr_data, uint16_t* const p_len)); |
jksoft | 0:76dfa9657d9d | 559 | |
jksoft | 0:76dfa9657d9d | 560 | /** @} */ |
jksoft | 0:76dfa9657d9d | 561 | |
jksoft | 0:76dfa9657d9d | 562 | #endif // BLE_GATTS_H__ |
jksoft | 0:76dfa9657d9d | 563 | |
jksoft | 0:76dfa9657d9d | 564 | /** |
jksoft | 0:76dfa9657d9d | 565 | @} |
jksoft | 0:76dfa9657d9d | 566 | */ |