Nicolas Borla / Mbed OS ROME2_Robot_Firmware
Committer:
boro
Date:
Mon Mar 16 13:12:31 2020 +0000
Revision:
0:4beb2ea291ec
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boro 0:4beb2ea291ec 1 /* mbed Microcontroller Library
boro 0:4beb2ea291ec 2 * Copyright (c) 2017-2017 ARM Limited
boro 0:4beb2ea291ec 3 *
boro 0:4beb2ea291ec 4 * Licensed under the Apache License, Version 2.0 (the "License");
boro 0:4beb2ea291ec 5 * you may not use this file except in compliance with the License.
boro 0:4beb2ea291ec 6 * You may obtain a copy of the License at
boro 0:4beb2ea291ec 7 *
boro 0:4beb2ea291ec 8 * http://www.apache.org/licenses/LICENSE-2.0
boro 0:4beb2ea291ec 9 *
boro 0:4beb2ea291ec 10 * Unless required by applicable law or agreed to in writing, software
boro 0:4beb2ea291ec 11 * distributed under the License is distributed on an "AS IS" BASIS,
boro 0:4beb2ea291ec 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
boro 0:4beb2ea291ec 13 * See the License for the specific language governing permissions and
boro 0:4beb2ea291ec 14 * limitations under the License.
boro 0:4beb2ea291ec 15 */
boro 0:4beb2ea291ec 16
boro 0:4beb2ea291ec 17 #ifndef BLE_PAL_ATTCLIENT_H_
boro 0:4beb2ea291ec 18 #define BLE_PAL_ATTCLIENT_H_
boro 0:4beb2ea291ec 19
boro 0:4beb2ea291ec 20 #include "ble/UUID.h"
boro 0:4beb2ea291ec 21 #include "ble/BLETypes.h"
boro 0:4beb2ea291ec 22 #include "ble/ArrayView.h"
boro 0:4beb2ea291ec 23 #include "ble/blecommon.h"
boro 0:4beb2ea291ec 24 #include "platform/Callback.h"
boro 0:4beb2ea291ec 25 #include "AttServerMessage.h"
boro 0:4beb2ea291ec 26
boro 0:4beb2ea291ec 27 namespace ble {
boro 0:4beb2ea291ec 28 namespace pal {
boro 0:4beb2ea291ec 29
boro 0:4beb2ea291ec 30 /**
boro 0:4beb2ea291ec 31 * Send attribute protocol requests to an ATT server. It also handle reception
boro 0:4beb2ea291ec 32 * of ATT response and server indication/notification.
boro 0:4beb2ea291ec 33 *
boro 0:4beb2ea291ec 34 * Every request send and response or response event received is for a specified
boro 0:4beb2ea291ec 35 * connection.
boro 0:4beb2ea291ec 36 *
boro 0:4beb2ea291ec 37 * @warning This class should not be used outside mbed BLE, availability is not
boro 0:4beb2ea291ec 38 * guaranteed for all ports.
boro 0:4beb2ea291ec 39 *
boro 0:4beb2ea291ec 40 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F
boro 0:4beb2ea291ec 41 */
boro 0:4beb2ea291ec 42 struct AttClient {
boro 0:4beb2ea291ec 43 /**
boro 0:4beb2ea291ec 44 * Initialization of the instance. An implementation can use this function
boro 0:4beb2ea291ec 45 * to initialise the subsystems needed to realize the ATT operations of this
boro 0:4beb2ea291ec 46 * interface.
boro 0:4beb2ea291ec 47 *
boro 0:4beb2ea291ec 48 * This function has to be called before any other operations.
boro 0:4beb2ea291ec 49 *
boro 0:4beb2ea291ec 50 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 51 * appropriate error otherwise.
boro 0:4beb2ea291ec 52 */
boro 0:4beb2ea291ec 53 virtual ble_error_t initialize() = 0;
boro 0:4beb2ea291ec 54
boro 0:4beb2ea291ec 55 /**
boro 0:4beb2ea291ec 56 * Termination of the instance. An implementation can use this function
boro 0:4beb2ea291ec 57 * to release the subsystems initialised to realise the ATT operations of
boro 0:4beb2ea291ec 58 * this interface.
boro 0:4beb2ea291ec 59 *
boro 0:4beb2ea291ec 60 * After a call to this function, initialise should be called again to
boro 0:4beb2ea291ec 61 * allow usage of the interface.
boro 0:4beb2ea291ec 62 *
boro 0:4beb2ea291ec 63 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 64 * appropriate error otherwise.
boro 0:4beb2ea291ec 65 */
boro 0:4beb2ea291ec 66 virtual ble_error_t terminate() = 0;
boro 0:4beb2ea291ec 67
boro 0:4beb2ea291ec 68 /**
boro 0:4beb2ea291ec 69 * Send an exchange MTU request which negotiate the size of the MTU used by
boro 0:4beb2ea291ec 70 * the connection.
boro 0:4beb2ea291ec 71 *
boro 0:4beb2ea291ec 72 * First the client send to the server the maximum rx mtu that it can receive
boro 0:4beb2ea291ec 73 * then the client reply with the maximum rx mtu it can receive.
boro 0:4beb2ea291ec 74 *
boro 0:4beb2ea291ec 75 * The mtu choosen for the connection is the minimum of the client Rx mtu
boro 0:4beb2ea291ec 76 * and server Rx mtu values.
boro 0:4beb2ea291ec 77 *
boro 0:4beb2ea291ec 78 * If an error occured then the mtu used remains the default value.
boro 0:4beb2ea291ec 79 *
boro 0:4beb2ea291ec 80 * @param connection The handle of the connection to send this request to.
boro 0:4beb2ea291ec 81 *
boro 0:4beb2ea291ec 82 * @return BLE_ERROR_NONE if the request has been succesfully sent or the
boro 0:4beb2ea291ec 83 * appropriate error otherwise.
boro 0:4beb2ea291ec 84 *
boro 0:4beb2ea291ec 85 * @see ble::pal::AttExchangeMTUResponse The type of response received from
boro 0:4beb2ea291ec 86 * the server
boro 0:4beb2ea291ec 87 * @see ble::pal::AttErrorResponse::REQUEST_NOT_SUPPORTED The error code
boro 0:4beb2ea291ec 88 * returned by the server in case of error.
boro 0:4beb2ea291ec 89 *
boro 0:4beb2ea291ec 90 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.2.1
boro 0:4beb2ea291ec 91 */
boro 0:4beb2ea291ec 92 virtual ble_error_t exchange_mtu_request(connection_handle_t connection) = 0;
boro 0:4beb2ea291ec 93
boro 0:4beb2ea291ec 94 /**
boro 0:4beb2ea291ec 95 * Acquire the size of the mtu for a given connection.
boro 0:4beb2ea291ec 96 *
boro 0:4beb2ea291ec 97 * @param connection The handle of the connection for which the the MTU size
boro 0:4beb2ea291ec 98 * should be acquired.
boro 0:4beb2ea291ec 99 *
boro 0:4beb2ea291ec 100 * @param mtu_size Output parameter which will contain the MTU size.
boro 0:4beb2ea291ec 101 *
boro 0:4beb2ea291ec 102 * @return BLE_ERROR_NONE if the MTU size has been acquired or the
boro 0:4beb2ea291ec 103 * appropriate error otherwise.
boro 0:4beb2ea291ec 104 */
boro 0:4beb2ea291ec 105 virtual ble_error_t get_mtu_size(
boro 0:4beb2ea291ec 106 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 107 uint16_t& mtu_size
boro 0:4beb2ea291ec 108 ) = 0;
boro 0:4beb2ea291ec 109
boro 0:4beb2ea291ec 110 /**
boro 0:4beb2ea291ec 111 * Send a find information request to a server in order to obtain the
boro 0:4beb2ea291ec 112 * mapping of attribute handles with their associated types.
boro 0:4beb2ea291ec 113 *
boro 0:4beb2ea291ec 114 * The server will reply with a ble::pal::AttFindInformationResponse
boro 0:4beb2ea291ec 115 * containing at least one [attribute handle, attribute type] pair. If the
boro 0:4beb2ea291ec 116 * last handle in the response is not equal to the end handle of the finding
boro 0:4beb2ea291ec 117 * range then this request can be issued again with an updated range (begin
boro 0:4beb2ea291ec 118 * equal to last handle received + 1) to discover the remaining attributes.
boro 0:4beb2ea291ec 119 *
boro 0:4beb2ea291ec 120 * To discover the whole ATT server, the first find information request
boro 0:4beb2ea291ec 121 * should have a discovery range of [0x0001 - 0xFFFF].
boro 0:4beb2ea291ec 122 *
boro 0:4beb2ea291ec 123 * The server can send a ble::pal::AttErrorResponse with the code
boro 0:4beb2ea291ec 124 * ble::pal::AttErrorResponse::ATTRIBUTE_NOT_FOUND if no attributes have
boro 0:4beb2ea291ec 125 * been found in the range specified. The attribute handle in the response
boro 0:4beb2ea291ec 126 * is then equal to the first handle of the discovery range.
boro 0:4beb2ea291ec 127 *
boro 0:4beb2ea291ec 128 * If the range is malformed the server will reply a
boro 0:4beb2ea291ec 129 * ble::pal::AttErrorResponse with the error code ble::pal::INVALID_HANDLE.
boro 0:4beb2ea291ec 130 *
boro 0:4beb2ea291ec 131 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 132 * request to.
boro 0:4beb2ea291ec 133 * @param discovery_range The attribute range where handle-type informations
boro 0:4beb2ea291ec 134 * should be discovered.
boro 0:4beb2ea291ec 135 *
boro 0:4beb2ea291ec 136 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 137 * appropriate error otherwise.
boro 0:4beb2ea291ec 138 *
boro 0:4beb2ea291ec 139 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.3.1
boro 0:4beb2ea291ec 140 */
boro 0:4beb2ea291ec 141 virtual ble_error_t find_information_request(
boro 0:4beb2ea291ec 142 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 143 attribute_handle_range_t discovery_range
boro 0:4beb2ea291ec 144 ) = 0;
boro 0:4beb2ea291ec 145
boro 0:4beb2ea291ec 146 /**
boro 0:4beb2ea291ec 147 * Send a Find By Type Value Request which retrieve the handles of attributes
boro 0:4beb2ea291ec 148 * that have known 16-bit UUID attribute type and known attribute value.
boro 0:4beb2ea291ec 149 *
boro 0:4beb2ea291ec 150 * The server should reply with a ble::pal::AttFindByTypeValueResponse
boro 0:4beb2ea291ec 151 * containing the handle (or handle range in case of grouping attributes) of
boro 0:4beb2ea291ec 152 * the attribute found.
boro 0:4beb2ea291ec 153 *
boro 0:4beb2ea291ec 154 * If not all attributes can be contained in the response it is necessary to
boro 0:4beb2ea291ec 155 * send again this request with an updated range to continue the discovery.
boro 0:4beb2ea291ec 156 *
boro 0:4beb2ea291ec 157 * The server can send a ble::pal::AttErrorResponse with the code
boro 0:4beb2ea291ec 158 * ble::pal::AttErrorResponse::ATTRIBUTE_NOT_FOUND if no attributes have
boro 0:4beb2ea291ec 159 * been found in the range specified. The attribute handle in the response
boro 0:4beb2ea291ec 160 * is then equal to the first handle of the discovery range.
boro 0:4beb2ea291ec 161 *
boro 0:4beb2ea291ec 162 * If the range is malformed the server will reply a
boro 0:4beb2ea291ec 163 * ble::pal::AttErrorResponse with the error code ble::pal::INVALID_HANDLE.
boro 0:4beb2ea291ec 164 *
boro 0:4beb2ea291ec 165 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 166 * request to.
boro 0:4beb2ea291ec 167 * @param discovery_range The handle range where attributes with type and
boro 0:4beb2ea291ec 168 * value are searched.
boro 0:4beb2ea291ec 169 * @param type The type of attribute to find (it is a 16 bit UUID).
boro 0:4beb2ea291ec 170 * @param value The value of the attributes to found.
boro 0:4beb2ea291ec 171 *
boro 0:4beb2ea291ec 172 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 173 * appropriate error otherwise.
boro 0:4beb2ea291ec 174 *
boro 0:4beb2ea291ec 175 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.3.3
boro 0:4beb2ea291ec 176 */
boro 0:4beb2ea291ec 177 virtual ble_error_t find_by_type_value_request(
boro 0:4beb2ea291ec 178 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 179 attribute_handle_range_t discovery_range,
boro 0:4beb2ea291ec 180 uint16_t type,
boro 0:4beb2ea291ec 181 const ArrayView<const uint8_t>& value
boro 0:4beb2ea291ec 182 ) = 0;
boro 0:4beb2ea291ec 183
boro 0:4beb2ea291ec 184 /**
boro 0:4beb2ea291ec 185 * Send a Read By Type Request used to obtain the values of attributes where
boro 0:4beb2ea291ec 186 * the attribute type is known but the handle is not known.
boro 0:4beb2ea291ec 187 *
boro 0:4beb2ea291ec 188 * If attributes with the type requested are present in the range, the server
boro 0:4beb2ea291ec 189 * should reply with a ble::pal::AttReadByTypeResponse. If the response does
boro 0:4beb2ea291ec 190 * not cover the full range, the request should be sent again with an updated
boro 0:4beb2ea291ec 191 * range.
boro 0:4beb2ea291ec 192 *
boro 0:4beb2ea291ec 193 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 194 * error code depends on the situation:
boro 0:4beb2ea291ec 195 * - ble::pal::AttErrorResponse::ATTRIBUTE_NOT_FOUND: If there is no
boro 0:4beb2ea291ec 196 * attributes matching type in the range.
boro 0:4beb2ea291ec 197 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the range is
boro 0:4beb2ea291ec 198 * invalid.
boro 0:4beb2ea291ec 199 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 200 * security is not sufficient.
boro 0:4beb2ea291ec 201 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 202 * authorization is not sufficient.
boro 0:4beb2ea291ec 203 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 204 * client has an insufficient encryption key size.
boro 0:4beb2ea291ec 205 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 206 * has not enabled encryption.
boro 0:4beb2ea291ec 207 * - ble::pal::AttErrorResponse::READ_NOT_PERMITTED: If the attribute
boro 0:4beb2ea291ec 208 * value cannot be read.
boro 0:4beb2ea291ec 209 *
boro 0:4beb2ea291ec 210 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 211 * request to.
boro 0:4beb2ea291ec 212 * @param read_range The handle range where attributes with the given type
boro 0:4beb2ea291ec 213 * should be read.
boro 0:4beb2ea291ec 214 * @param type The type of attributes to read.
boro 0:4beb2ea291ec 215 *
boro 0:4beb2ea291ec 216 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 217 * appropriate error otherwise.
boro 0:4beb2ea291ec 218 *
boro 0:4beb2ea291ec 219 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.1
boro 0:4beb2ea291ec 220 */
boro 0:4beb2ea291ec 221 virtual ble_error_t read_by_type_request(
boro 0:4beb2ea291ec 222 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 223 attribute_handle_range_t read_range,
boro 0:4beb2ea291ec 224 const UUID& type
boro 0:4beb2ea291ec 225 ) = 0;
boro 0:4beb2ea291ec 226
boro 0:4beb2ea291ec 227 /**
boro 0:4beb2ea291ec 228 * Send a Read Request to read the value of an attribute in the server.
boro 0:4beb2ea291ec 229 *
boro 0:4beb2ea291ec 230 * In case of success, the server will reply with a ble::pal::AttReadResponse.
boro 0:4beb2ea291ec 231 * containing the value of the attribute. If the length of the value in the
boro 0:4beb2ea291ec 232 * response is equal to (mtu - 1) then the remaining part of the value can
boro 0:4beb2ea291ec 233 * be obtained by a read_blob_request.
boro 0:4beb2ea291ec 234 *
boro 0:4beb2ea291ec 235 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 236 * error code depends on the situation:
boro 0:4beb2ea291ec 237 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the attribute handle
boro 0:4beb2ea291ec 238 * is invalid.
boro 0:4beb2ea291ec 239 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 240 * security is not sufficient.
boro 0:4beb2ea291ec 241 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 242 * authorization is not sufficient.
boro 0:4beb2ea291ec 243 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 244 * client has an insufficient encryption key size.
boro 0:4beb2ea291ec 245 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 246 * has not enabled encryption.
boro 0:4beb2ea291ec 247 * - ble::pal::AttErrorResponse::READ_NOT_PERMITTED: If the attribute
boro 0:4beb2ea291ec 248 * value cannot be read.
boro 0:4beb2ea291ec 249 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 250 *
boro 0:4beb2ea291ec 251 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 252 * request to.
boro 0:4beb2ea291ec 253 * @param attribute_handle The handle of the attribute to read.
boro 0:4beb2ea291ec 254 *
boro 0:4beb2ea291ec 255 * @return BLE_ERROR_NONE if the request has been successfully sent or the
boro 0:4beb2ea291ec 256 * appropriate error otherwise.
boro 0:4beb2ea291ec 257 *
boro 0:4beb2ea291ec 258 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.3
boro 0:4beb2ea291ec 259 */
boro 0:4beb2ea291ec 260 virtual ble_error_t read_request(
boro 0:4beb2ea291ec 261 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 262 attribute_handle_t attribute_handle
boro 0:4beb2ea291ec 263 ) = 0;
boro 0:4beb2ea291ec 264
boro 0:4beb2ea291ec 265 /**
boro 0:4beb2ea291ec 266 * Send a read blob request to a server to read a part of the value of an
boro 0:4beb2ea291ec 267 * attribute at a given offset.
boro 0:4beb2ea291ec 268 *
boro 0:4beb2ea291ec 269 * In case of success, the server will reply with a ble::pal::AttReadBlobResponse
boro 0:4beb2ea291ec 270 * containing the value read. If the value of the attribute starting at the
boro 0:4beb2ea291ec 271 * offset requested is longer than (mtu - 1) octets then only the first
boro 0:4beb2ea291ec 272 * (mtu - 1) octets will be present in the response.
boro 0:4beb2ea291ec 273 * The remaining octets can be acquired by another Read Blob Request with an
boro 0:4beb2ea291ec 274 * updated index.
boro 0:4beb2ea291ec 275 *
boro 0:4beb2ea291ec 276 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 277 * error code depends on the situation:
boro 0:4beb2ea291ec 278 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the attribute handle
boro 0:4beb2ea291ec 279 * is invalid.
boro 0:4beb2ea291ec 280 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 281 * security is not sufficient.
boro 0:4beb2ea291ec 282 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 283 * authorization is not sufficient.
boro 0:4beb2ea291ec 284 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 285 * client has an insufficient encryption key size.
boro 0:4beb2ea291ec 286 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 287 * has not enabled encryption.
boro 0:4beb2ea291ec 288 * - ble::pal::AttErrorResponse::READ_NOT_PERMITTED: If the attribute
boro 0:4beb2ea291ec 289 * value cannot be read.
boro 0:4beb2ea291ec 290 * - ble::pal::AttErrorResponse::INVALID_OFFSET: If the offset is greater
boro 0:4beb2ea291ec 291 * than the attribute length.
boro 0:4beb2ea291ec 292 * - ble::pal::AttErrorResponse::ATTRIBUTE_NOT_LONG: If the attribute
boro 0:4beb2ea291ec 293 * value has a length that is less than or equal to (mtu - 1).
boro 0:4beb2ea291ec 294 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 295 *
boro 0:4beb2ea291ec 296 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 297 * request to.
boro 0:4beb2ea291ec 298 * @param attribute_handle The handle of the attribute to read.
boro 0:4beb2ea291ec 299 * @param offset The offset of the first octet to read.
boro 0:4beb2ea291ec 300 *
boro 0:4beb2ea291ec 301 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 302 * appropriate error otherwise.
boro 0:4beb2ea291ec 303 *
boro 0:4beb2ea291ec 304 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.5
boro 0:4beb2ea291ec 305 */
boro 0:4beb2ea291ec 306 virtual ble_error_t read_blob_request(
boro 0:4beb2ea291ec 307 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 308 attribute_handle_t attribute_handle,
boro 0:4beb2ea291ec 309 uint16_t offset
boro 0:4beb2ea291ec 310 ) = 0;
boro 0:4beb2ea291ec 311
boro 0:4beb2ea291ec 312 /**
boro 0:4beb2ea291ec 313 * Send a read multiple request to the server. It is used to read two or more
boro 0:4beb2ea291ec 314 * attributes values at once.
boro 0:4beb2ea291ec 315 *
boro 0:4beb2ea291ec 316 * In case of success, the server will reply with a
boro 0:4beb2ea291ec 317 * ble::pal::AttReadMultipleResponse containing the concatenation of the
boro 0:4beb2ea291ec 318 * values read. Given that values are concatained, all attributes values
boro 0:4beb2ea291ec 319 * should be of fixed size except for the last one. The concatained value
boro 0:4beb2ea291ec 320 * is also truncated to (mtu - 1) if it doesn't fit in the response.
boro 0:4beb2ea291ec 321 *
boro 0:4beb2ea291ec 322 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 323 * error code depends on the situation:
boro 0:4beb2ea291ec 324 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If any of the attribute
boro 0:4beb2ea291ec 325 * handle is invalid.
boro 0:4beb2ea291ec 326 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 327 * security is not sufficient to read any of the attribute.
boro 0:4beb2ea291ec 328 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 329 * authorization is not sufficient to read any of the attribute.
boro 0:4beb2ea291ec 330 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 331 * client has an insufficient encryption key size to read any of the
boro 0:4beb2ea291ec 332 * attributes.
boro 0:4beb2ea291ec 333 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 334 * has not enabled encryption required to read any of the attributes.
boro 0:4beb2ea291ec 335 * - ble::pal::AttErrorResponse::READ_NOT_PERMITTED: If any of the
boro 0:4beb2ea291ec 336 * attributes value cannot be read.
boro 0:4beb2ea291ec 337 * The first attribute causing the error is reporter in the handle_in_error
boro 0:4beb2ea291ec 338 * field in the error response.
boro 0:4beb2ea291ec 339 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 340 *
boro 0:4beb2ea291ec 341 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 342 * request to.
boro 0:4beb2ea291ec 343 * @param attribute_handles Set of attribute handles to read.
boro 0:4beb2ea291ec 344 *
boro 0:4beb2ea291ec 345 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 346 * appropriate error otherwise.
boro 0:4beb2ea291ec 347 *
boro 0:4beb2ea291ec 348 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.7
boro 0:4beb2ea291ec 349 */
boro 0:4beb2ea291ec 350 virtual ble_error_t read_multiple_request(
boro 0:4beb2ea291ec 351 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 352 const ArrayView<const attribute_handle_t>& attribute_handles
boro 0:4beb2ea291ec 353 ) = 0;
boro 0:4beb2ea291ec 354
boro 0:4beb2ea291ec 355 /**
boro 0:4beb2ea291ec 356 * Send a read by group type request to the server. It is used to get
boro 0:4beb2ea291ec 357 * informations about grouping attribute of a given type on a server.
boro 0:4beb2ea291ec 358 *
boro 0:4beb2ea291ec 359 * The server will reply with a ble::pal::ReadByGroupTypeResponse containing
boro 0:4beb2ea291ec 360 * informations about the grouping attribute found. Informations are:
boro 0:4beb2ea291ec 361 * - handle of the grouping attribute.
boro 0:4beb2ea291ec 362 * - last handle of the group .
boro 0:4beb2ea291ec 363 * - attribute value.
boro 0:4beb2ea291ec 364 *
boro 0:4beb2ea291ec 365 * If the last handle received is not the last handle of the discovery range
boro 0:4beb2ea291ec 366 * then it is necessary to send another request with a discovery range
boro 0:4beb2ea291ec 367 * updated to: [last handle + 1 : end].
boro 0:4beb2ea291ec 368 *
boro 0:4beb2ea291ec 369 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 370 * error code depends on the situation:
boro 0:4beb2ea291ec 371 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the range of handle
boro 0:4beb2ea291ec 372 * provided is invalid.
boro 0:4beb2ea291ec 373 * - ble::pal::AttErrorResponse::UNSUPPORTED_GROUP_TYPE: if the group type
boro 0:4beb2ea291ec 374 * is not a supported grouping attribute.
boro 0:4beb2ea291ec 375 * - ble::pal::AttErrorResponse::ATTRIBUTE_NOT_FOUND: If no attribute with
boro 0:4beb2ea291ec 376 * the given type exists within the range provided.
boro 0:4beb2ea291ec 377 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 378 * security is not sufficient to read the requested attribute.
boro 0:4beb2ea291ec 379 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 380 * authorization is not sufficient to read the requested attribute.
boro 0:4beb2ea291ec 381 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 382 * client has an insufficient encryption key size to read the requested
boro 0:4beb2ea291ec 383 * attributes.
boro 0:4beb2ea291ec 384 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 385 * has not enabled encryption required to read the requested attributes.
boro 0:4beb2ea291ec 386 * - ble::pal::AttErrorResponse::READ_NOT_PERMITTED: If any of the
boro 0:4beb2ea291ec 387 * attributes value cannot be read.
boro 0:4beb2ea291ec 388 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 389 *
boro 0:4beb2ea291ec 390 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 391 * request to.
boro 0:4beb2ea291ec 392 * @param read_range Range where this request apply.
boro 0:4beb2ea291ec 393 * @param group_type Type of the grouping attribute to find and read.
boro 0:4beb2ea291ec 394 *
boro 0:4beb2ea291ec 395 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 396 * appropriate error otherwise.
boro 0:4beb2ea291ec 397 *
boro 0:4beb2ea291ec 398 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.9
boro 0:4beb2ea291ec 399 */
boro 0:4beb2ea291ec 400 virtual ble_error_t read_by_group_type_request(
boro 0:4beb2ea291ec 401 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 402 attribute_handle_range_t read_range,
boro 0:4beb2ea291ec 403 const UUID& group_type
boro 0:4beb2ea291ec 404 ) = 0;
boro 0:4beb2ea291ec 405
boro 0:4beb2ea291ec 406 /**
boro 0:4beb2ea291ec 407 * Send a write request to the server to write the value of an attribute.
boro 0:4beb2ea291ec 408 *
boro 0:4beb2ea291ec 409 * In case of success, the server will reply with a
boro 0:4beb2ea291ec 410 * ble::pal::AttWriteResponse to acknowledge that the write operation went
boro 0:4beb2ea291ec 411 * well.
boro 0:4beb2ea291ec 412 *
boro 0:4beb2ea291ec 413 * If the attribute value has a variable length, then the attribute value
boro 0:4beb2ea291ec 414 * shall be truncated or lengthened to match the length of the value in the
boro 0:4beb2ea291ec 415 * request.
boro 0:4beb2ea291ec 416 *
boro 0:4beb2ea291ec 417 * If the attribute value has a fixed length and the Attribute Value parameter length
boro 0:4beb2ea291ec 418 * is less than or equal to the length of the attribute value, the octets of the
boro 0:4beb2ea291ec 419 * attribute value parameter length shall be written; all other octets in this attribute
boro 0:4beb2ea291ec 420 * value shall be unchanged.
boro 0:4beb2ea291ec 421 *
boro 0:4beb2ea291ec 422 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 423 * error code depends on the situation:
boro 0:4beb2ea291ec 424 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the handle to write is
boro 0:4beb2ea291ec 425 * invalid.
boro 0:4beb2ea291ec 426 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 427 * security is not sufficient to write the requested attribute.
boro 0:4beb2ea291ec 428 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 429 * authorization is not sufficient to write the requested attribute.
boro 0:4beb2ea291ec 430 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 431 * client has an insufficient encryption key size to write the requested
boro 0:4beb2ea291ec 432 * attributes.
boro 0:4beb2ea291ec 433 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 434 * has not enabled encryption required to write the requested attributes.
boro 0:4beb2ea291ec 435 * - ble::pal::AttErrorResponse::WRITE_NOT_PERMITTED: If the attribute
boro 0:4beb2ea291ec 436 * value cannot be written due to permission.
boro 0:4beb2ea291ec 437 * - ble::pal::AttErrorResponse::INVALID_ATTRIBUTE_VALUE_LENGTH: If the
boro 0:4beb2ea291ec 438 * value to write exceeds the maximum valid length or of the attribute
boro 0:4beb2ea291ec 439 * value; whether the attribute has a variable length value or a fixed
boro 0:4beb2ea291ec 440 * length value.
boro 0:4beb2ea291ec 441 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 442 *
boro 0:4beb2ea291ec 443 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 444 * request to.
boro 0:4beb2ea291ec 445 * @param attribute_handle Handle of the attribute to write.
boro 0:4beb2ea291ec 446 * @param value Value to write. It can't be longer than (mtu - 3).
boro 0:4beb2ea291ec 447 *
boro 0:4beb2ea291ec 448 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 449 * appropriate error otherwise.
boro 0:4beb2ea291ec 450 *
boro 0:4beb2ea291ec 451 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.1
boro 0:4beb2ea291ec 452 */
boro 0:4beb2ea291ec 453 virtual ble_error_t write_request(
boro 0:4beb2ea291ec 454 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 455 attribute_handle_t attribute_handle,
boro 0:4beb2ea291ec 456 const ArrayView<const uint8_t>& value
boro 0:4beb2ea291ec 457 ) = 0;
boro 0:4beb2ea291ec 458
boro 0:4beb2ea291ec 459 /**
boro 0:4beb2ea291ec 460 * Send a write command to the server. A write command is similar to a write
boro 0:4beb2ea291ec 461 * request except that it won't receive any response from the server
boro 0:4beb2ea291ec 462 *
boro 0:4beb2ea291ec 463 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 464 * request to.
boro 0:4beb2ea291ec 465 * @param attribute_handle Handle of the attribute to write.
boro 0:4beb2ea291ec 466 * @param value Value to write. It can't be longer than (mtu - 3).
boro 0:4beb2ea291ec 467 *
boro 0:4beb2ea291ec 468 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 469 * appropriate error otherwise.
boro 0:4beb2ea291ec 470 *
boro 0:4beb2ea291ec 471 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.3
boro 0:4beb2ea291ec 472 */
boro 0:4beb2ea291ec 473 virtual ble_error_t write_command(
boro 0:4beb2ea291ec 474 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 475 attribute_handle_t attribute_handle,
boro 0:4beb2ea291ec 476 const ArrayView<const uint8_t>& value
boro 0:4beb2ea291ec 477 ) = 0;
boro 0:4beb2ea291ec 478
boro 0:4beb2ea291ec 479 /**
boro 0:4beb2ea291ec 480 * Send a signed write command to the server. Behaviour is similar to a write
boro 0:4beb2ea291ec 481 * command except that 12 bytes of the mtu are reserved for the authentication
boro 0:4beb2ea291ec 482 * signature.
boro 0:4beb2ea291ec 483 *
boro 0:4beb2ea291ec 484 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 485 * request to.
boro 0:4beb2ea291ec 486 * @param attribute_handle Handle of the attribute to write.
boro 0:4beb2ea291ec 487 * @param value Value to write. It can't be longer than (mtu - 15).
boro 0:4beb2ea291ec 488 *
boro 0:4beb2ea291ec 489 * @note the authentication signature to send with this request is
boro 0:4beb2ea291ec 490 * computed by the implementation following the rules defined in BLUETOOTH
boro 0:4beb2ea291ec 491 * SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.3.1.
boro 0:4beb2ea291ec 492 *
boro 0:4beb2ea291ec 493 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 494 * appropriate error otherwise.
boro 0:4beb2ea291ec 495 *
boro 0:4beb2ea291ec 496 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.4
boro 0:4beb2ea291ec 497 */
boro 0:4beb2ea291ec 498 virtual ble_error_t signed_write_command(
boro 0:4beb2ea291ec 499 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 500 attribute_handle_t attribute_handle,
boro 0:4beb2ea291ec 501 const ArrayView<const uint8_t>& value
boro 0:4beb2ea291ec 502 ) = 0;
boro 0:4beb2ea291ec 503
boro 0:4beb2ea291ec 504 /**
boro 0:4beb2ea291ec 505 * The Prepare Write Request is used to request the server to prepare to
boro 0:4beb2ea291ec 506 * write the value of an attribute. The client can send multiple prepare
boro 0:4beb2ea291ec 507 * write request which will be put in a queue until the client send an
boro 0:4beb2ea291ec 508 * Execute Write Request which will execute sequentially the write request
boro 0:4beb2ea291ec 509 * in the queue.
boro 0:4beb2ea291ec 510 *
boro 0:4beb2ea291ec 511 * In case of success the server will respond with a
boro 0:4beb2ea291ec 512 * ble::pal::AttPrepareWriteResponse containing the values (attribute handle,
boro 0:4beb2ea291ec 513 * offset and value) present in the write request.
boro 0:4beb2ea291ec 514 *
boro 0:4beb2ea291ec 515 * If a prepare write request is rejected by the server, the state queue of
boro 0:4beb2ea291ec 516 * the prepare write request queue remains unaltered.
boro 0:4beb2ea291ec 517 *
boro 0:4beb2ea291ec 518 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 519 * error code depends on the situation:
boro 0:4beb2ea291ec 520 * - ble::pal::AttErrorResponse::INVALID_HANDLE: If the handle to write is
boro 0:4beb2ea291ec 521 * invalid.
boro 0:4beb2ea291ec 522 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHENTICATION: If the client
boro 0:4beb2ea291ec 523 * security is not sufficient to write the requested attribute.
boro 0:4beb2ea291ec 524 * - ble::pal::AttErrorResponse::INSUFFICIENT_AUTHORIZATION: If the client
boro 0:4beb2ea291ec 525 * authorization is not sufficient to write the requested attribute.
boro 0:4beb2ea291ec 526 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION_KEY_SIZE: If the
boro 0:4beb2ea291ec 527 * client has an insufficient encryption key size to write the requested
boro 0:4beb2ea291ec 528 * attributes.
boro 0:4beb2ea291ec 529 * - ble::pal::AttErrorResponse::INSUFFICIENT_ENCRYPTION: If the client
boro 0:4beb2ea291ec 530 * has not enabled encryption required to write the requested attributes.
boro 0:4beb2ea291ec 531 * - ble::pal::AttErrorResponse::WRITE_NOT_PERMITTED: If the attribute
boro 0:4beb2ea291ec 532 * value cannot be written due to permission.
boro 0:4beb2ea291ec 533 * - ble::pal::PREPARE_QUEUE_FULL: If the queue of prepare write request
boro 0:4beb2ea291ec 534 * is full.
boro 0:4beb2ea291ec 535 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 536 *
boro 0:4beb2ea291ec 537 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 538 * request to.
boro 0:4beb2ea291ec 539 * @param attribute_handle The handle of the attribute to be written.
boro 0:4beb2ea291ec 540 * @param offset The offset of the first octet to be written.
boro 0:4beb2ea291ec 541 * @param value The value of the attribute to be written. It can't be longer
boro 0:4beb2ea291ec 542 * than (mtu - 5).
boro 0:4beb2ea291ec 543 *
boro 0:4beb2ea291ec 544 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 545 * appropriate error otherwise.
boro 0:4beb2ea291ec 546 *
boro 0:4beb2ea291ec 547 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.6.1
boro 0:4beb2ea291ec 548 *
boro 0:4beb2ea291ec 549 */
boro 0:4beb2ea291ec 550 virtual ble_error_t prepare_write_request(
boro 0:4beb2ea291ec 551 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 552 attribute_handle_t attribute_handle,
boro 0:4beb2ea291ec 553 uint16_t offset,
boro 0:4beb2ea291ec 554 const ArrayView<const uint8_t>& value
boro 0:4beb2ea291ec 555 ) = 0;
boro 0:4beb2ea291ec 556
boro 0:4beb2ea291ec 557 /**
boro 0:4beb2ea291ec 558 * Send an Execute Write Request to the server. This request will instruct
boro 0:4beb2ea291ec 559 * the server to execute or cancel the prepare write requests currently held
boro 0:4beb2ea291ec 560 * in the prepare queue from this client.
boro 0:4beb2ea291ec 561 *
boro 0:4beb2ea291ec 562 * If the execute parameter is set to true, the server should execute the
boro 0:4beb2ea291ec 563 * request held in the queue. If the parameter is equal to false then the
boro 0:4beb2ea291ec 564 * server should cancel the requests in the queue.
boro 0:4beb2ea291ec 565 *
boro 0:4beb2ea291ec 566 * In case of success, the server will respond with a
boro 0:4beb2ea291ec 567 * ble::pal::AttExecuteWriteResponse indicating that the request was correctly
boro 0:4beb2ea291ec 568 * handled.
boro 0:4beb2ea291ec 569 *
boro 0:4beb2ea291ec 570 * In case of error, the server will send a ble::pal::AttErrorResponse. The
boro 0:4beb2ea291ec 571 * error code depends on the situation:
boro 0:4beb2ea291ec 572 * - ble::pal::AttErrorResponse::INVALID_OFFSET: If the value offset is
boro 0:4beb2ea291ec 573 * greater than the current length of the attribute to write.
boro 0:4beb2ea291ec 574 * - ble::pal::AttErrorResponse::INVALID_ATTRIBUTE_VALUE_LENGTH: If the
boro 0:4beb2ea291ec 575 * length of the value write exceeds the length of the attribute value
boro 0:4beb2ea291ec 576 * about to be written.
boro 0:4beb2ea291ec 577 * Higher layer can also set an application error code (0x80 - 0x9F).
boro 0:4beb2ea291ec 578 *
boro 0:4beb2ea291ec 579 * The error response will contains the attribute handle which as caused the
boro 0:4beb2ea291ec 580 * error and the remaining of the prepare queue is discarded. The state of
boro 0:4beb2ea291ec 581 * the attributes that were to be written from the prepare queue is not
boro 0:4beb2ea291ec 582 * defined in this case.
boro 0:4beb2ea291ec 583 *
boro 0:4beb2ea291ec 584 * @param connection_handle The handle of the connection to send this
boro 0:4beb2ea291ec 585 * request to.
boro 0:4beb2ea291ec 586 * @param execute Boolean indicating if the prepare queue should be executed
boro 0:4beb2ea291ec 587 * or cleared.
boro 0:4beb2ea291ec 588 *
boro 0:4beb2ea291ec 589 * @return BLE_ERROR_NONE if the request has been successfully sent or an
boro 0:4beb2ea291ec 590 * appropriate error otherwise.
boro 0:4beb2ea291ec 591 *
boro 0:4beb2ea291ec 592 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.6.3
boro 0:4beb2ea291ec 593 */
boro 0:4beb2ea291ec 594 virtual ble_error_t execute_write_request(
boro 0:4beb2ea291ec 595 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 596 bool execute
boro 0:4beb2ea291ec 597 ) = 0;
boro 0:4beb2ea291ec 598
boro 0:4beb2ea291ec 599 /**
boro 0:4beb2ea291ec 600 * Register a callback which will handle messages from the server.
boro 0:4beb2ea291ec 601 *
boro 0:4beb2ea291ec 602 * @param cb The callback object which will handle messages from the server.
boro 0:4beb2ea291ec 603 * It accept two parameters in input: The handle of the connection where the
boro 0:4beb2ea291ec 604 * message was received and the message received. Real type of the message
boro 0:4beb2ea291ec 605 * can be obtained from its opcode.
boro 0:4beb2ea291ec 606 */
boro 0:4beb2ea291ec 607 void when_server_message_received(
boro 0:4beb2ea291ec 608 mbed::Callback<void(connection_handle_t, const AttServerMessage&)> cb
boro 0:4beb2ea291ec 609 ) {
boro 0:4beb2ea291ec 610 _server_message_cb = cb;
boro 0:4beb2ea291ec 611 }
boro 0:4beb2ea291ec 612
boro 0:4beb2ea291ec 613 /**
boro 0:4beb2ea291ec 614 * Register a callback handling transaction timeout.
boro 0:4beb2ea291ec 615 *
boro 0:4beb2ea291ec 616 * @param cb The callback handling timeout of a transaction. It accepts as
boro 0:4beb2ea291ec 617 * a parameter the connection handle involved in the timeout.
boro 0:4beb2ea291ec 618 *
boro 0:4beb2ea291ec 619 * @note No more attribute protocol requests, commands, indication or
boro 0:4beb2ea291ec 620 * notification shall be sent over a connection implied in a transaction
boro 0:4beb2ea291ec 621 * timeout. To send a new ATT message, the conenction should be
boro 0:4beb2ea291ec 622 * reestablished.
boro 0:4beb2ea291ec 623 */
boro 0:4beb2ea291ec 624 void when_transaction_timeout(
boro 0:4beb2ea291ec 625 mbed::Callback<void(connection_handle_t)> cb
boro 0:4beb2ea291ec 626 ) {
boro 0:4beb2ea291ec 627 _transaction_timeout_cb = cb;
boro 0:4beb2ea291ec 628 }
boro 0:4beb2ea291ec 629
boro 0:4beb2ea291ec 630 protected:
boro 0:4beb2ea291ec 631 AttClient() { }
boro 0:4beb2ea291ec 632
boro 0:4beb2ea291ec 633 virtual ~AttClient() { }
boro 0:4beb2ea291ec 634
boro 0:4beb2ea291ec 635 /**
boro 0:4beb2ea291ec 636 * Upon server message reception an implementation shall call this function.
boro 0:4beb2ea291ec 637 *
boro 0:4beb2ea291ec 638 * @param connection_handle The handle of the connection which has received
boro 0:4beb2ea291ec 639 * the server message.
boro 0:4beb2ea291ec 640 * @param server_message The message received from the server.
boro 0:4beb2ea291ec 641 */
boro 0:4beb2ea291ec 642 void on_server_event(
boro 0:4beb2ea291ec 643 connection_handle_t connection_handle,
boro 0:4beb2ea291ec 644 const AttServerMessage& server_message
boro 0:4beb2ea291ec 645 ) {
boro 0:4beb2ea291ec 646 if (_server_message_cb) {
boro 0:4beb2ea291ec 647 _server_message_cb(connection_handle, server_message);
boro 0:4beb2ea291ec 648 }
boro 0:4beb2ea291ec 649 }
boro 0:4beb2ea291ec 650
boro 0:4beb2ea291ec 651 /**
boro 0:4beb2ea291ec 652 * Upon transaction timeout an implementation shall call this function.
boro 0:4beb2ea291ec 653 *
boro 0:4beb2ea291ec 654 * @param connection_handle The handle of the connection of the transaction
boro 0:4beb2ea291ec 655 * which has times out.
boro 0:4beb2ea291ec 656 *
boro 0:4beb2ea291ec 657 * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.3.3
boro 0:4beb2ea291ec 658 */
boro 0:4beb2ea291ec 659 void on_transaction_timeout(
boro 0:4beb2ea291ec 660 connection_handle_t connection_handle
boro 0:4beb2ea291ec 661 ) {
boro 0:4beb2ea291ec 662 if (_transaction_timeout_cb) {
boro 0:4beb2ea291ec 663 _transaction_timeout_cb(connection_handle);
boro 0:4beb2ea291ec 664 }
boro 0:4beb2ea291ec 665 }
boro 0:4beb2ea291ec 666
boro 0:4beb2ea291ec 667 private:
boro 0:4beb2ea291ec 668 /**
boro 0:4beb2ea291ec 669 * Callback called when the client receive a message from the server.
boro 0:4beb2ea291ec 670 */
boro 0:4beb2ea291ec 671 mbed::Callback<void(connection_handle_t, const AttServerMessage&)> _server_message_cb;
boro 0:4beb2ea291ec 672
boro 0:4beb2ea291ec 673 /**
boro 0:4beb2ea291ec 674 * Callback called when a transaction times out.
boro 0:4beb2ea291ec 675 */
boro 0:4beb2ea291ec 676 mbed::Callback<void(connection_handle_t)> _transaction_timeout_cb;
boro 0:4beb2ea291ec 677
boro 0:4beb2ea291ec 678 // Disallow copy construction and copy assignment.
boro 0:4beb2ea291ec 679 AttClient(const AttClient&);
boro 0:4beb2ea291ec 680 AttClient& operator=(const AttClient&);
boro 0:4beb2ea291ec 681 };
boro 0:4beb2ea291ec 682
boro 0:4beb2ea291ec 683
boro 0:4beb2ea291ec 684 } // namespace pal
boro 0:4beb2ea291ec 685 } // namespace ble
boro 0:4beb2ea291ec 686
boro 0:4beb2ea291ec 687 #endif /* BLE_PAL_ATTCLIENT_H_ */