Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/features/FEATURE_BLE/ble/pal/PalGattClient.h@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2017-2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #ifndef BLE_PAL_GATT_CLIENT_H_ |
kadonotakashi | 0:8fdf9a60065b | 18 | #define BLE_PAL_GATT_CLIENT_H_ |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | #include "ble/UUID.h" |
kadonotakashi | 0:8fdf9a60065b | 21 | #include "ble/BLETypes.h" |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "ble/ArrayView.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "ble/blecommon.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | |
kadonotakashi | 0:8fdf9a60065b | 25 | #include "platform/Callback.h" |
kadonotakashi | 0:8fdf9a60065b | 26 | |
kadonotakashi | 0:8fdf9a60065b | 27 | #include "AttServerMessage.h" |
kadonotakashi | 0:8fdf9a60065b | 28 | |
kadonotakashi | 0:8fdf9a60065b | 29 | namespace ble { |
kadonotakashi | 0:8fdf9a60065b | 30 | namespace pal { |
kadonotakashi | 0:8fdf9a60065b | 31 | |
kadonotakashi | 0:8fdf9a60065b | 32 | /** |
kadonotakashi | 0:8fdf9a60065b | 33 | * Adaptation layer for a GATT client. |
kadonotakashi | 0:8fdf9a60065b | 34 | * |
kadonotakashi | 0:8fdf9a60065b | 35 | * Define the primitive necessary to implement a proper GATT client. These |
kadonotakashi | 0:8fdf9a60065b | 36 | * primitives are sometime GATT procedure, ATT procedure or a bit of both. |
kadonotakashi | 0:8fdf9a60065b | 37 | * |
kadonotakashi | 0:8fdf9a60065b | 38 | * In general, discovery procedures follow strictly GATT formulation while |
kadonotakashi | 0:8fdf9a60065b | 39 | * attribute manipulation procedures (read/write) follow the ATT formulation |
kadonotakashi | 0:8fdf9a60065b | 40 | * to avoid multiple identical implementation for characteristic values and |
kadonotakashi | 0:8fdf9a60065b | 41 | * characteristic descriptors value, it also fill a hole leave by the |
kadonotakashi | 0:8fdf9a60065b | 42 | * specification which doesn't define any GATT procedure to get the UUID of an |
kadonotakashi | 0:8fdf9a60065b | 43 | * included service with a 128 bit UUID. |
kadonotakashi | 0:8fdf9a60065b | 44 | * |
kadonotakashi | 0:8fdf9a60065b | 45 | * Complementary informations around ATT procedures can be found in the Section |
kadonotakashi | 0:8fdf9a60065b | 46 | * 3.4 of the Vol3, Part F of the Bluetooth specification while more informations |
kadonotakashi | 0:8fdf9a60065b | 47 | * around the GATT procedures can be found in the Section 4 of the Vol 3, Part |
kadonotakashi | 0:8fdf9a60065b | 48 | * G of the Bluetooth specification. |
kadonotakashi | 0:8fdf9a60065b | 49 | * |
kadonotakashi | 0:8fdf9a60065b | 50 | * Complete and compliant Gatt Client used by developer is realized at an higher |
kadonotakashi | 0:8fdf9a60065b | 51 | * level using the primitives defined in this adaptation layer. |
kadonotakashi | 0:8fdf9a60065b | 52 | * |
kadonotakashi | 0:8fdf9a60065b | 53 | * If a stack expose the complete ATT layer then it is possible to provide an |
kadonotakashi | 0:8fdf9a60065b | 54 | * implementation for GattClient by subclassing the AttClient class and use |
kadonotakashi | 0:8fdf9a60065b | 55 | * the class AttClientToGattClientAdapter |
kadonotakashi | 0:8fdf9a60065b | 56 | */ |
kadonotakashi | 0:8fdf9a60065b | 57 | class GattClient { |
kadonotakashi | 0:8fdf9a60065b | 58 | |
kadonotakashi | 0:8fdf9a60065b | 59 | public: |
kadonotakashi | 0:8fdf9a60065b | 60 | /** |
kadonotakashi | 0:8fdf9a60065b | 61 | * Initialisation of the instance. An implementation can use this function |
kadonotakashi | 0:8fdf9a60065b | 62 | * to initialise the subsystems needed to realize the operations of this |
kadonotakashi | 0:8fdf9a60065b | 63 | * interface. |
kadonotakashi | 0:8fdf9a60065b | 64 | * |
kadonotakashi | 0:8fdf9a60065b | 65 | * This function has to be called before any other operations. |
kadonotakashi | 0:8fdf9a60065b | 66 | * |
kadonotakashi | 0:8fdf9a60065b | 67 | * @return BLE_ERROR_NONE if the request has been successfully sent or the |
kadonotakashi | 0:8fdf9a60065b | 68 | * appropriate error otherwise. |
kadonotakashi | 0:8fdf9a60065b | 69 | */ |
kadonotakashi | 0:8fdf9a60065b | 70 | virtual ble_error_t initialize() = 0; |
kadonotakashi | 0:8fdf9a60065b | 71 | |
kadonotakashi | 0:8fdf9a60065b | 72 | /** |
kadonotakashi | 0:8fdf9a60065b | 73 | * Termination of the instance. An implementation can use this function |
kadonotakashi | 0:8fdf9a60065b | 74 | * to release the subsystems initialised to realise the operations of |
kadonotakashi | 0:8fdf9a60065b | 75 | * this interface. |
kadonotakashi | 0:8fdf9a60065b | 76 | * |
kadonotakashi | 0:8fdf9a60065b | 77 | * After a call to this function, initialise should be called again to |
kadonotakashi | 0:8fdf9a60065b | 78 | * allow usage of the interface. |
kadonotakashi | 0:8fdf9a60065b | 79 | * |
kadonotakashi | 0:8fdf9a60065b | 80 | * @return BLE_ERROR_NONE if the request has been successfully sent or the |
kadonotakashi | 0:8fdf9a60065b | 81 | * appropriate error otherwise. |
kadonotakashi | 0:8fdf9a60065b | 82 | */ |
kadonotakashi | 0:8fdf9a60065b | 83 | virtual ble_error_t terminate() = 0; |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | /** |
kadonotakashi | 0:8fdf9a60065b | 86 | * Negotiate the mtu to use by this connection. |
kadonotakashi | 0:8fdf9a60065b | 87 | * First the client send to the server the maximum rx mtu that it can receive |
kadonotakashi | 0:8fdf9a60065b | 88 | * then the client reply with the maximum rx mtu it can receive. |
kadonotakashi | 0:8fdf9a60065b | 89 | * The mtu chosen for the connection is the minimum of the client Rx mtu |
kadonotakashi | 0:8fdf9a60065b | 90 | * and server Rx mtu values. |
kadonotakashi | 0:8fdf9a60065b | 91 | * |
kadonotakashi | 0:8fdf9a60065b | 92 | * If an error occurred then the mtu used remains the default value. |
kadonotakashi | 0:8fdf9a60065b | 93 | * |
kadonotakashi | 0:8fdf9a60065b | 94 | * The server will reply to this request with an AttExchangeMTUResponse in |
kadonotakashi | 0:8fdf9a60065b | 95 | * case of success or AttErrorResponse in case of failure. |
kadonotakashi | 0:8fdf9a60065b | 96 | * |
kadonotakashi | 0:8fdf9a60065b | 97 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.3.1 |
kadonotakashi | 0:8fdf9a60065b | 98 | * |
kadonotakashi | 0:8fdf9a60065b | 99 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 100 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 101 | */ |
kadonotakashi | 0:8fdf9a60065b | 102 | virtual ble_error_t exchange_mtu(connection_handle_t connection) = 0; |
kadonotakashi | 0:8fdf9a60065b | 103 | |
kadonotakashi | 0:8fdf9a60065b | 104 | /** |
kadonotakashi | 0:8fdf9a60065b | 105 | * Acquire the size of the mtu for a given connection. |
kadonotakashi | 0:8fdf9a60065b | 106 | * |
kadonotakashi | 0:8fdf9a60065b | 107 | * @param connection The handle of the connection for which the the MTU size |
kadonotakashi | 0:8fdf9a60065b | 108 | * should be acquired. |
kadonotakashi | 0:8fdf9a60065b | 109 | * |
kadonotakashi | 0:8fdf9a60065b | 110 | * @param mtu_size Output parameter which will contain the MTU size. |
kadonotakashi | 0:8fdf9a60065b | 111 | * |
kadonotakashi | 0:8fdf9a60065b | 112 | * @return BLE_ERROR_NONE if the MTU size has been acquired or the |
kadonotakashi | 0:8fdf9a60065b | 113 | * appropriate error otherwise. |
kadonotakashi | 0:8fdf9a60065b | 114 | */ |
kadonotakashi | 0:8fdf9a60065b | 115 | virtual ble_error_t get_mtu_size( |
kadonotakashi | 0:8fdf9a60065b | 116 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 117 | uint16_t& mtu_size |
kadonotakashi | 0:8fdf9a60065b | 118 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 119 | |
kadonotakashi | 0:8fdf9a60065b | 120 | /** |
kadonotakashi | 0:8fdf9a60065b | 121 | * Discover primary services in the range [begin - 0xFFFF]. |
kadonotakashi | 0:8fdf9a60065b | 122 | * |
kadonotakashi | 0:8fdf9a60065b | 123 | * If services exists in the range provided, the server will reply with a |
kadonotakashi | 0:8fdf9a60065b | 124 | * ReadByGoupType response where for each attribute_data exposed: |
kadonotakashi | 0:8fdf9a60065b | 125 | * - attribute_handle is the service attribute handle |
kadonotakashi | 0:8fdf9a60065b | 126 | * - end_group_handle is the last handle of the service |
kadonotakashi | 0:8fdf9a60065b | 127 | * - attribute_value is the UUID of the service. |
kadonotakashi | 0:8fdf9a60065b | 128 | * |
kadonotakashi | 0:8fdf9a60065b | 129 | * If the end of the range is not reached, this procedure can be relaunched |
kadonotakashi | 0:8fdf9a60065b | 130 | * with the last handle of the last service discovered plus one as the |
kadonotakashi | 0:8fdf9a60065b | 131 | * beginning of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 132 | * |
kadonotakashi | 0:8fdf9a60065b | 133 | * If there is not services left to discover in the range, the server can |
kadonotakashi | 0:8fdf9a60065b | 134 | * either: |
kadonotakashi | 0:8fdf9a60065b | 135 | * * Reply with an ErrorResponse with the Error code set to ATTRIBUTE_NOT_FOUND |
kadonotakashi | 0:8fdf9a60065b | 136 | * * Set the end handle of the last service to 0xFFFF. |
kadonotakashi | 0:8fdf9a60065b | 137 | * |
kadonotakashi | 0:8fdf9a60065b | 138 | * @note This function realize a partial implementation of the Discover All |
kadonotakashi | 0:8fdf9a60065b | 139 | * Primary Services procedure. The complete implementation of the procedure |
kadonotakashi | 0:8fdf9a60065b | 140 | * is realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 141 | * @note This function issue a Read By Group Type ATT request where the |
kadonotakashi | 0:8fdf9a60065b | 142 | * type parameter is equal to Primary Service and the Ending Handle parameter |
kadonotakashi | 0:8fdf9a60065b | 143 | * is equal to 0xFFFF. |
kadonotakashi | 0:8fdf9a60065b | 144 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.4.1 |
kadonotakashi | 0:8fdf9a60065b | 145 | * |
kadonotakashi | 0:8fdf9a60065b | 146 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 147 | * @param begin The beginning of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 148 | * |
kadonotakashi | 0:8fdf9a60065b | 149 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 150 | */ |
kadonotakashi | 0:8fdf9a60065b | 151 | virtual ble_error_t discover_primary_service( |
kadonotakashi | 0:8fdf9a60065b | 152 | connection_handle_t connection, |
kadonotakashi | 0:8fdf9a60065b | 153 | attribute_handle_t discovery_range_begining |
kadonotakashi | 0:8fdf9a60065b | 154 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 155 | |
kadonotakashi | 0:8fdf9a60065b | 156 | /** |
kadonotakashi | 0:8fdf9a60065b | 157 | * Discover primary services by UUID in the range [discovery_range_begining - 0xFFFF]. |
kadonotakashi | 0:8fdf9a60065b | 158 | * |
kadonotakashi | 0:8fdf9a60065b | 159 | * If services exists in the range provided, the server will reply with a |
kadonotakashi | 0:8fdf9a60065b | 160 | * FindByTypeValueResponse containing the attribute range of each service |
kadonotakashi | 0:8fdf9a60065b | 161 | * discovered. |
kadonotakashi | 0:8fdf9a60065b | 162 | * |
kadonotakashi | 0:8fdf9a60065b | 163 | * If the end of the range is not reached, this procedure can be relaunched |
kadonotakashi | 0:8fdf9a60065b | 164 | * with the last handle of the last service discovered plus one as the |
kadonotakashi | 0:8fdf9a60065b | 165 | * beginning of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 166 | * |
kadonotakashi | 0:8fdf9a60065b | 167 | * If there is not services left to discover in the range, the server can |
kadonotakashi | 0:8fdf9a60065b | 168 | * either: |
kadonotakashi | 0:8fdf9a60065b | 169 | * * Reply with an ErrorResponse with the Error code set to ATTRIBUTE_NOT_FOUND |
kadonotakashi | 0:8fdf9a60065b | 170 | * * Set the end handle of the last service to 0xFFFF. |
kadonotakashi | 0:8fdf9a60065b | 171 | * |
kadonotakashi | 0:8fdf9a60065b | 172 | * @note This function realize a partial implementation of the Discover |
kadonotakashi | 0:8fdf9a60065b | 173 | * Primary Service by Service UUID procedure. The complete implementation of |
kadonotakashi | 0:8fdf9a60065b | 174 | * the procedure is realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 175 | * @note This function issue a Find By Type Value ATT request where the |
kadonotakashi | 0:8fdf9a60065b | 176 | * type parameter is equal to Primary Service and the Ending Handle |
kadonotakashi | 0:8fdf9a60065b | 177 | * parameter is equal to 0xFFFF. |
kadonotakashi | 0:8fdf9a60065b | 178 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.4.2 |
kadonotakashi | 0:8fdf9a60065b | 179 | * |
kadonotakashi | 0:8fdf9a60065b | 180 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 181 | * @param begin The beginning of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 182 | * @param uuid The UUID of the service to discover. |
kadonotakashi | 0:8fdf9a60065b | 183 | * |
kadonotakashi | 0:8fdf9a60065b | 184 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 185 | */ |
kadonotakashi | 0:8fdf9a60065b | 186 | virtual ble_error_t discover_primary_service_by_service_uuid( |
kadonotakashi | 0:8fdf9a60065b | 187 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 188 | attribute_handle_t discovery_range_beginning, |
kadonotakashi | 0:8fdf9a60065b | 189 | const UUID& uuid |
kadonotakashi | 0:8fdf9a60065b | 190 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 191 | |
kadonotakashi | 0:8fdf9a60065b | 192 | /** |
kadonotakashi | 0:8fdf9a60065b | 193 | * Find included services within a service. |
kadonotakashi | 0:8fdf9a60065b | 194 | * |
kadonotakashi | 0:8fdf9a60065b | 195 | * If services are included in the service range then the server will reply |
kadonotakashi | 0:8fdf9a60065b | 196 | * with a ReadByTypeResponse where for each attribute record: |
kadonotakashi | 0:8fdf9a60065b | 197 | * - attribute_handle The handle where the service is included within the |
kadonotakashi | 0:8fdf9a60065b | 198 | * service definition. |
kadonotakashi | 0:8fdf9a60065b | 199 | * - attribute_data Contains two handles defining the range of the included. |
kadonotakashi | 0:8fdf9a60065b | 200 | * If the service found have a 16 bit uuid then its UUID is also included |
kadonotakashi | 0:8fdf9a60065b | 201 | * in the attribute data. |
kadonotakashi | 0:8fdf9a60065b | 202 | * |
kadonotakashi | 0:8fdf9a60065b | 203 | * If the end of the service range is not reached, this procedure can be |
kadonotakashi | 0:8fdf9a60065b | 204 | * relaunched with the handle of the last included service discovered plus |
kadonotakashi | 0:8fdf9a60065b | 205 | * one as the beginning of the new discovery range. |
kadonotakashi | 0:8fdf9a60065b | 206 | * |
kadonotakashi | 0:8fdf9a60065b | 207 | * The procedure is complete when either: |
kadonotakashi | 0:8fdf9a60065b | 208 | * - The server reply with an ErrorResponse with the Error code set to |
kadonotakashi | 0:8fdf9a60065b | 209 | * ATTRIBUTE_NOT_FOUND |
kadonotakashi | 0:8fdf9a60065b | 210 | * - An included service handle returned is equal to the end of the range. |
kadonotakashi | 0:8fdf9a60065b | 211 | * |
kadonotakashi | 0:8fdf9a60065b | 212 | * If the service UUID is a 128 bits one then it is necessary to issue a read |
kadonotakashi | 0:8fdf9a60065b | 213 | * attribute request on the first handle of the service discovered to get it. |
kadonotakashi | 0:8fdf9a60065b | 214 | * |
kadonotakashi | 0:8fdf9a60065b | 215 | * @note This function realize a partial implementation of the Find Included |
kadonotakashi | 0:8fdf9a60065b | 216 | * Services procedure. The complete implementation of the procedure is |
kadonotakashi | 0:8fdf9a60065b | 217 | * realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 218 | * @note This function issue a Read By Type ATT request where the |
kadonotakashi | 0:8fdf9a60065b | 219 | * type parameter is equal to Include. |
kadonotakashi | 0:8fdf9a60065b | 220 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.5.1 |
kadonotakashi | 0:8fdf9a60065b | 221 | * |
kadonotakashi | 0:8fdf9a60065b | 222 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 223 | * @param service_range The range of the service where service inclusion has |
kadonotakashi | 0:8fdf9a60065b | 224 | * to be discovered. |
kadonotakashi | 0:8fdf9a60065b | 225 | * |
kadonotakashi | 0:8fdf9a60065b | 226 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 227 | */ |
kadonotakashi | 0:8fdf9a60065b | 228 | virtual ble_error_t find_included_service( |
kadonotakashi | 0:8fdf9a60065b | 229 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 230 | attribute_handle_range_t service_range |
kadonotakashi | 0:8fdf9a60065b | 231 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 232 | |
kadonotakashi | 0:8fdf9a60065b | 233 | /** |
kadonotakashi | 0:8fdf9a60065b | 234 | * Find characteristic declarations within a service definition. |
kadonotakashi | 0:8fdf9a60065b | 235 | * |
kadonotakashi | 0:8fdf9a60065b | 236 | * If characteristic declarations are found within the range then the server |
kadonotakashi | 0:8fdf9a60065b | 237 | * should reply with a ReadByTypeResponse where for each attribute record: |
kadonotakashi | 0:8fdf9a60065b | 238 | * - attribute_handle is the handle of the characteristic definition |
kadonotakashi | 0:8fdf9a60065b | 239 | * - attribute_data contains the the following values attached to the |
kadonotakashi | 0:8fdf9a60065b | 240 | * characteristic : |
kadonotakashi | 0:8fdf9a60065b | 241 | * + properties: the properties of the characteristic. |
kadonotakashi | 0:8fdf9a60065b | 242 | * + value handle: the handle of the value of the characteristic. |
kadonotakashi | 0:8fdf9a60065b | 243 | * + uuid: the UUID of the characteristic. |
kadonotakashi | 0:8fdf9a60065b | 244 | * |
kadonotakashi | 0:8fdf9a60065b | 245 | * The procedure is considered complete when the server send an ErrorResponse |
kadonotakashi | 0:8fdf9a60065b | 246 | * with the ErrorCode set to ATTRIBUTE_NOT_FOUND or a ReadByType response |
kadonotakashi | 0:8fdf9a60065b | 247 | * has an attribute_handle set to the end of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 248 | * |
kadonotakashi | 0:8fdf9a60065b | 249 | * If the procedure is not complete after a server response, it should be |
kadonotakashi | 0:8fdf9a60065b | 250 | * relaunched with an updated range starting at the last attribute_handle |
kadonotakashi | 0:8fdf9a60065b | 251 | * discovered plus one. |
kadonotakashi | 0:8fdf9a60065b | 252 | * |
kadonotakashi | 0:8fdf9a60065b | 253 | * @note This function realize a partial implementation of the Discover All |
kadonotakashi | 0:8fdf9a60065b | 254 | * Characteristics of a Service procedure. The complete implementation of |
kadonotakashi | 0:8fdf9a60065b | 255 | * the procedure is realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 256 | * @note This function issue a Read By Type ATT request where the type |
kadonotakashi | 0:8fdf9a60065b | 257 | * parameter is equal to Characteristic. |
kadonotakashi | 0:8fdf9a60065b | 258 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.6.1 |
kadonotakashi | 0:8fdf9a60065b | 259 | * |
kadonotakashi | 0:8fdf9a60065b | 260 | * @note The GATT procedure Discover Characteristics by UUID is implemented |
kadonotakashi | 0:8fdf9a60065b | 261 | * at a higher level using this function as a base. |
kadonotakashi | 0:8fdf9a60065b | 262 | * |
kadonotakashi | 0:8fdf9a60065b | 263 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 264 | * @param discovery_range The range of attributes where the characteristics |
kadonotakashi | 0:8fdf9a60065b | 265 | * are discovered. It should be contained within a service. |
kadonotakashi | 0:8fdf9a60065b | 266 | * |
kadonotakashi | 0:8fdf9a60065b | 267 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 268 | */ |
kadonotakashi | 0:8fdf9a60065b | 269 | virtual ble_error_t discover_characteristics_of_a_service( |
kadonotakashi | 0:8fdf9a60065b | 270 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 271 | attribute_handle_range_t discovery_range |
kadonotakashi | 0:8fdf9a60065b | 272 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 273 | |
kadonotakashi | 0:8fdf9a60065b | 274 | /** |
kadonotakashi | 0:8fdf9a60065b | 275 | * Discover characteristic descriptors of a characteristic. |
kadonotakashi | 0:8fdf9a60065b | 276 | * |
kadonotakashi | 0:8fdf9a60065b | 277 | * If descriptors are found within the range provided then the server should |
kadonotakashi | 0:8fdf9a60065b | 278 | * reply with a FindInformationResponse containing a list of |
kadonotakashi | 0:8fdf9a60065b | 279 | * attribute_handle_t, UUID pairs where the attribute handle is the |
kadonotakashi | 0:8fdf9a60065b | 280 | * descriptor handle and UUID is the UUID of the descriptor. |
kadonotakashi | 0:8fdf9a60065b | 281 | * |
kadonotakashi | 0:8fdf9a60065b | 282 | * The procedure is complete when the server send an ErrorResponse with the |
kadonotakashi | 0:8fdf9a60065b | 283 | * error code ATTRIBUTE_NOT_FOUND or the FindInformationResponse has an |
kadonotakashi | 0:8fdf9a60065b | 284 | * attribute handle that is equal to the end handle of the discovery range. |
kadonotakashi | 0:8fdf9a60065b | 285 | * |
kadonotakashi | 0:8fdf9a60065b | 286 | * @note This function realize a partial implementation of the Discover All |
kadonotakashi | 0:8fdf9a60065b | 287 | * Characteristics Descriptors procedure. The complete implementation of |
kadonotakashi | 0:8fdf9a60065b | 288 | * the procedure is realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 289 | * @note This function issue a Find Information ATT request.. |
kadonotakashi | 0:8fdf9a60065b | 290 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.7.1 |
kadonotakashi | 0:8fdf9a60065b | 291 | * |
kadonotakashi | 0:8fdf9a60065b | 292 | * @note It should be possible to use this function to issue a regular |
kadonotakashi | 0:8fdf9a60065b | 293 | * ATT Find Information Request. |
kadonotakashi | 0:8fdf9a60065b | 294 | * |
kadonotakashi | 0:8fdf9a60065b | 295 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 296 | * @param descriptors_discovery_range The range of attributes where the |
kadonotakashi | 0:8fdf9a60065b | 297 | * descriptors are discovered. The first handle shall be no less than the |
kadonotakashi | 0:8fdf9a60065b | 298 | * characteristic value handle plus one and the last handle shall be no more |
kadonotakashi | 0:8fdf9a60065b | 299 | * than the last handle of the characteristic. |
kadonotakashi | 0:8fdf9a60065b | 300 | * |
kadonotakashi | 0:8fdf9a60065b | 301 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 302 | */ |
kadonotakashi | 0:8fdf9a60065b | 303 | virtual ble_error_t discover_characteristics_descriptors( |
kadonotakashi | 0:8fdf9a60065b | 304 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 305 | attribute_handle_range_t descriptors_discovery_range |
kadonotakashi | 0:8fdf9a60065b | 306 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 307 | |
kadonotakashi | 0:8fdf9a60065b | 308 | /** |
kadonotakashi | 0:8fdf9a60065b | 309 | * Read the value of an attribute. |
kadonotakashi | 0:8fdf9a60065b | 310 | * |
kadonotakashi | 0:8fdf9a60065b | 311 | * The server will reply with an AttReadResponse. In case of error, the |
kadonotakashi | 0:8fdf9a60065b | 312 | * server will reply with an AttErrorResponse. |
kadonotakashi | 0:8fdf9a60065b | 313 | * |
kadonotakashi | 0:8fdf9a60065b | 314 | * @note This function issue an ATT Read Request. |
kadonotakashi | 0:8fdf9a60065b | 315 | * |
kadonotakashi | 0:8fdf9a60065b | 316 | * @note: This function is the base function for the read Characteristic |
kadonotakashi | 0:8fdf9a60065b | 317 | * Value and Read Characteristic Descriptor GATT procedures. It can also |
kadonotakashi | 0:8fdf9a60065b | 318 | * be used to read the 128 bit UUID of a service discovered with |
kadonotakashi | 0:8fdf9a60065b | 319 | * find_included_service. |
kadonotakashi | 0:8fdf9a60065b | 320 | * |
kadonotakashi | 0:8fdf9a60065b | 321 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.8.1 |
kadonotakashi | 0:8fdf9a60065b | 322 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.12.1 |
kadonotakashi | 0:8fdf9a60065b | 323 | * |
kadonotakashi | 0:8fdf9a60065b | 324 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 325 | * @param attribute_handle Handle of the attribute to read. |
kadonotakashi | 0:8fdf9a60065b | 326 | * |
kadonotakashi | 0:8fdf9a60065b | 327 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 328 | */ |
kadonotakashi | 0:8fdf9a60065b | 329 | virtual ble_error_t read_attribute_value( |
kadonotakashi | 0:8fdf9a60065b | 330 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 331 | attribute_handle_t attribute_handle |
kadonotakashi | 0:8fdf9a60065b | 332 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 333 | |
kadonotakashi | 0:8fdf9a60065b | 334 | /** |
kadonotakashi | 0:8fdf9a60065b | 335 | * Read a characteristic value using its UUID (type). |
kadonotakashi | 0:8fdf9a60065b | 336 | * |
kadonotakashi | 0:8fdf9a60065b | 337 | * The server will respond a ReadByTypeResponse containing a sequence of |
kadonotakashi | 0:8fdf9a60065b | 338 | * attribute handle and attribute value pairs. |
kadonotakashi | 0:8fdf9a60065b | 339 | * To read remaining attributes, the client should launch a new request |
kadonotakashi | 0:8fdf9a60065b | 340 | * with an updated range. |
kadonotakashi | 0:8fdf9a60065b | 341 | * |
kadonotakashi | 0:8fdf9a60065b | 342 | * The procedure is considered complete when the server respond with an |
kadonotakashi | 0:8fdf9a60065b | 343 | * ErrorResponse containing the ErrorCode ATTRIBUTE_NOT_FOUND or when an |
kadonotakashi | 0:8fdf9a60065b | 344 | * handle in the ReadByTypeResponse is equal to the end of the discovered |
kadonotakashi | 0:8fdf9a60065b | 345 | * range. |
kadonotakashi | 0:8fdf9a60065b | 346 | * |
kadonotakashi | 0:8fdf9a60065b | 347 | * @note This function realize a partial implementation of the Read Using |
kadonotakashi | 0:8fdf9a60065b | 348 | * Characteristics Characteristic procedure. The complete implementation of |
kadonotakashi | 0:8fdf9a60065b | 349 | * the procedure is realized at an higher level. |
kadonotakashi | 0:8fdf9a60065b | 350 | * @note This function issue a Read By Type ATT request. |
kadonotakashi | 0:8fdf9a60065b | 351 | * @note BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.8.2 |
kadonotakashi | 0:8fdf9a60065b | 352 | * |
kadonotakashi | 0:8fdf9a60065b | 353 | * @note It should be possible to use this function to issue a regular |
kadonotakashi | 0:8fdf9a60065b | 354 | * ATT Read By Type Request. |
kadonotakashi | 0:8fdf9a60065b | 355 | * |
kadonotakashi | 0:8fdf9a60065b | 356 | * @param connection The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 357 | * @param attribute_range Range of the handle where an attribute with |
kadonotakashi | 0:8fdf9a60065b | 358 | * uuid as type is present. |
kadonotakashi | 0:8fdf9a60065b | 359 | * @param uuid UUID of the characteristic(s) to read. |
kadonotakashi | 0:8fdf9a60065b | 360 | * |
kadonotakashi | 0:8fdf9a60065b | 361 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 362 | */ |
kadonotakashi | 0:8fdf9a60065b | 363 | virtual ble_error_t read_using_characteristic_uuid( |
kadonotakashi | 0:8fdf9a60065b | 364 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 365 | attribute_handle_range_t read_range, |
kadonotakashi | 0:8fdf9a60065b | 366 | const UUID& uuid |
kadonotakashi | 0:8fdf9a60065b | 367 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 368 | |
kadonotakashi | 0:8fdf9a60065b | 369 | /** |
kadonotakashi | 0:8fdf9a60065b | 370 | * Read a partial value of an attribute. |
kadonotakashi | 0:8fdf9a60065b | 371 | * |
kadonotakashi | 0:8fdf9a60065b | 372 | * The server will respond with a ReadBlobResponse containing the data read |
kadonotakashi | 0:8fdf9a60065b | 373 | * or an ErrorResponse in case of error. |
kadonotakashi | 0:8fdf9a60065b | 374 | * |
kadonotakashi | 0:8fdf9a60065b | 375 | * The procedure is not complete as long as the value in response have the |
kadonotakashi | 0:8fdf9a60065b | 376 | * same size as the mtu minus one. If the procedure is not complete, it can |
kadonotakashi | 0:8fdf9a60065b | 377 | * be launch again with an updated offset to read the remaining part of the |
kadonotakashi | 0:8fdf9a60065b | 378 | * attribute value. |
kadonotakashi | 0:8fdf9a60065b | 379 | * |
kadonotakashi | 0:8fdf9a60065b | 380 | * @note This function issue an ATT Read Blob Request. |
kadonotakashi | 0:8fdf9a60065b | 381 | * |
kadonotakashi | 0:8fdf9a60065b | 382 | * @note: This function is the base function for the Read Long |
kadonotakashi | 0:8fdf9a60065b | 383 | * Characteristic Value and Read Long Characteristic Descriptor GATT |
kadonotakashi | 0:8fdf9a60065b | 384 | * procedures. |
kadonotakashi | 0:8fdf9a60065b | 385 | * |
kadonotakashi | 0:8fdf9a60065b | 386 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.8.3 |
kadonotakashi | 0:8fdf9a60065b | 387 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.12.2 |
kadonotakashi | 0:8fdf9a60065b | 388 | * |
kadonotakashi | 0:8fdf9a60065b | 389 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 390 | * @param attribute_handle Handle of the attribute to read. |
kadonotakashi | 0:8fdf9a60065b | 391 | * @param offset Beginning offset for the read operation. |
kadonotakashi | 0:8fdf9a60065b | 392 | * |
kadonotakashi | 0:8fdf9a60065b | 393 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 394 | */ |
kadonotakashi | 0:8fdf9a60065b | 395 | virtual ble_error_t read_attribute_blob( |
kadonotakashi | 0:8fdf9a60065b | 396 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 397 | attribute_handle_t attribute_handle, |
kadonotakashi | 0:8fdf9a60065b | 398 | uint16_t offset |
kadonotakashi | 0:8fdf9a60065b | 399 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 400 | |
kadonotakashi | 0:8fdf9a60065b | 401 | /** |
kadonotakashi | 0:8fdf9a60065b | 402 | * Read atomically multiple characteristics values. |
kadonotakashi | 0:8fdf9a60065b | 403 | * |
kadonotakashi | 0:8fdf9a60065b | 404 | * The server will respond with a ReadMultiple response containing the |
kadonotakashi | 0:8fdf9a60065b | 405 | * concatenation of the values of the characteristics. |
kadonotakashi | 0:8fdf9a60065b | 406 | * |
kadonotakashi | 0:8fdf9a60065b | 407 | * @note values might be truncated |
kadonotakashi | 0:8fdf9a60065b | 408 | * |
kadonotakashi | 0:8fdf9a60065b | 409 | * In case of error, the server should respond a with an ErrorResponse. |
kadonotakashi | 0:8fdf9a60065b | 410 | * |
kadonotakashi | 0:8fdf9a60065b | 411 | * @note This function issue an ATT Read Multiple Request. |
kadonotakashi | 0:8fdf9a60065b | 412 | * |
kadonotakashi | 0:8fdf9a60065b | 413 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.8.4 |
kadonotakashi | 0:8fdf9a60065b | 414 | * |
kadonotakashi | 0:8fdf9a60065b | 415 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 416 | * @param characteristic_value_handles Handle of the characteristic values |
kadonotakashi | 0:8fdf9a60065b | 417 | * to read. |
kadonotakashi | 0:8fdf9a60065b | 418 | * |
kadonotakashi | 0:8fdf9a60065b | 419 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 420 | */ |
kadonotakashi | 0:8fdf9a60065b | 421 | virtual ble_error_t read_multiple_characteristic_values( |
kadonotakashi | 0:8fdf9a60065b | 422 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 423 | const ArrayView<const attribute_handle_t>& characteristic_value_handles |
kadonotakashi | 0:8fdf9a60065b | 424 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 425 | |
kadonotakashi | 0:8fdf9a60065b | 426 | /** |
kadonotakashi | 0:8fdf9a60065b | 427 | * Send a write command to the server. |
kadonotakashi | 0:8fdf9a60065b | 428 | * |
kadonotakashi | 0:8fdf9a60065b | 429 | * @note This function issue an ATT Write Command. |
kadonotakashi | 0:8fdf9a60065b | 430 | * |
kadonotakashi | 0:8fdf9a60065b | 431 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.1 |
kadonotakashi | 0:8fdf9a60065b | 432 | * |
kadonotakashi | 0:8fdf9a60065b | 433 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 434 | * @param attribute_handle Handle of the attribute to write. |
kadonotakashi | 0:8fdf9a60065b | 435 | * @param value The value to write. |
kadonotakashi | 0:8fdf9a60065b | 436 | * |
kadonotakashi | 0:8fdf9a60065b | 437 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 438 | */ |
kadonotakashi | 0:8fdf9a60065b | 439 | virtual ble_error_t write_without_response( |
kadonotakashi | 0:8fdf9a60065b | 440 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 441 | attribute_handle_t characteristic_value_handle, |
kadonotakashi | 0:8fdf9a60065b | 442 | const ArrayView<const uint8_t>& value |
kadonotakashi | 0:8fdf9a60065b | 443 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 444 | |
kadonotakashi | 0:8fdf9a60065b | 445 | /** |
kadonotakashi | 0:8fdf9a60065b | 446 | * Send a Signed Write without Response command to the server. |
kadonotakashi | 0:8fdf9a60065b | 447 | * |
kadonotakashi | 0:8fdf9a60065b | 448 | * @note This function issue an ATT Write Command with the signed flag and |
kadonotakashi | 0:8fdf9a60065b | 449 | * the signature. |
kadonotakashi | 0:8fdf9a60065b | 450 | * |
kadonotakashi | 0:8fdf9a60065b | 451 | * @note signature is calculated by the stack. |
kadonotakashi | 0:8fdf9a60065b | 452 | * |
kadonotakashi | 0:8fdf9a60065b | 453 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.2 |
kadonotakashi | 0:8fdf9a60065b | 454 | * |
kadonotakashi | 0:8fdf9a60065b | 455 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 456 | * @param attribute_handle Handle of the attribute to write. |
kadonotakashi | 0:8fdf9a60065b | 457 | * @param value The value to write. |
kadonotakashi | 0:8fdf9a60065b | 458 | * |
kadonotakashi | 0:8fdf9a60065b | 459 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 460 | */ |
kadonotakashi | 0:8fdf9a60065b | 461 | virtual ble_error_t signed_write_without_response( |
kadonotakashi | 0:8fdf9a60065b | 462 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 463 | attribute_handle_t characteristic_value_handle, |
kadonotakashi | 0:8fdf9a60065b | 464 | const ArrayView<const uint8_t>& value |
kadonotakashi | 0:8fdf9a60065b | 465 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 466 | |
kadonotakashi | 0:8fdf9a60065b | 467 | /** |
kadonotakashi | 0:8fdf9a60065b | 468 | * Send a write request to the server. |
kadonotakashi | 0:8fdf9a60065b | 469 | * |
kadonotakashi | 0:8fdf9a60065b | 470 | * The server should respond with a WriteResponse in case of success or an |
kadonotakashi | 0:8fdf9a60065b | 471 | * ErrorResponse in case of error. |
kadonotakashi | 0:8fdf9a60065b | 472 | * |
kadonotakashi | 0:8fdf9a60065b | 473 | * @note This function issue an ATT Write Request. |
kadonotakashi | 0:8fdf9a60065b | 474 | * |
kadonotakashi | 0:8fdf9a60065b | 475 | * @note: This function is the base function for the Write Characteristic |
kadonotakashi | 0:8fdf9a60065b | 476 | * Value and Write Characteristic Descriptors GATT procedures. |
kadonotakashi | 0:8fdf9a60065b | 477 | * |
kadonotakashi | 0:8fdf9a60065b | 478 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.3 |
kadonotakashi | 0:8fdf9a60065b | 479 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.12.3 |
kadonotakashi | 0:8fdf9a60065b | 480 | * |
kadonotakashi | 0:8fdf9a60065b | 481 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 482 | * @param attribute_handle Handle of the attribute to write. |
kadonotakashi | 0:8fdf9a60065b | 483 | * @param value The value to write. |
kadonotakashi | 0:8fdf9a60065b | 484 | * |
kadonotakashi | 0:8fdf9a60065b | 485 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 486 | */ |
kadonotakashi | 0:8fdf9a60065b | 487 | virtual ble_error_t write_attribute( |
kadonotakashi | 0:8fdf9a60065b | 488 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 489 | attribute_handle_t attribute_handle, |
kadonotakashi | 0:8fdf9a60065b | 490 | const ArrayView<const uint8_t>& value |
kadonotakashi | 0:8fdf9a60065b | 491 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 492 | |
kadonotakashi | 0:8fdf9a60065b | 493 | /** |
kadonotakashi | 0:8fdf9a60065b | 494 | * Send a prepare write request to the server. |
kadonotakashi | 0:8fdf9a60065b | 495 | * |
kadonotakashi | 0:8fdf9a60065b | 496 | * The write request will go into a queue until the client execute or cancel |
kadonotakashi | 0:8fdf9a60065b | 497 | * the request with an execute write request which will write all the values |
kadonotakashi | 0:8fdf9a60065b | 498 | * in the queue atomically. |
kadonotakashi | 0:8fdf9a60065b | 499 | * |
kadonotakashi | 0:8fdf9a60065b | 500 | * The server should respond with a PrepareWriteResponse containing the |
kadonotakashi | 0:8fdf9a60065b | 501 | * content of the request in case of success and an ErrorResponse in case of |
kadonotakashi | 0:8fdf9a60065b | 502 | * error. |
kadonotakashi | 0:8fdf9a60065b | 503 | * |
kadonotakashi | 0:8fdf9a60065b | 504 | * If an ErrorResponse is received it doesn't invalidate what is already in |
kadonotakashi | 0:8fdf9a60065b | 505 | * the queue. |
kadonotakashi | 0:8fdf9a60065b | 506 | * |
kadonotakashi | 0:8fdf9a60065b | 507 | * @note This function issue an ATT Prepare Write Request. |
kadonotakashi | 0:8fdf9a60065b | 508 | * |
kadonotakashi | 0:8fdf9a60065b | 509 | * @note: This function is one of the base function for the Write Long |
kadonotakashi | 0:8fdf9a60065b | 510 | * Characteristic Value and Reliable Writes GATT procedures. |
kadonotakashi | 0:8fdf9a60065b | 511 | * |
kadonotakashi | 0:8fdf9a60065b | 512 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.4 |
kadonotakashi | 0:8fdf9a60065b | 513 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.5 |
kadonotakashi | 0:8fdf9a60065b | 514 | * |
kadonotakashi | 0:8fdf9a60065b | 515 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 516 | * @param attribute_handle Handle of the attribute to write. |
kadonotakashi | 0:8fdf9a60065b | 517 | * @param value The value to write. |
kadonotakashi | 0:8fdf9a60065b | 518 | * @param offset offset where the value should be written. |
kadonotakashi | 0:8fdf9a60065b | 519 | * |
kadonotakashi | 0:8fdf9a60065b | 520 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 521 | */ |
kadonotakashi | 0:8fdf9a60065b | 522 | virtual ble_error_t queue_prepare_write( |
kadonotakashi | 0:8fdf9a60065b | 523 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 524 | attribute_handle_t characteristic_value_handle, |
kadonotakashi | 0:8fdf9a60065b | 525 | const ArrayView<const uint8_t>& value, |
kadonotakashi | 0:8fdf9a60065b | 526 | uint16_t offset |
kadonotakashi | 0:8fdf9a60065b | 527 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 528 | |
kadonotakashi | 0:8fdf9a60065b | 529 | /** |
kadonotakashi | 0:8fdf9a60065b | 530 | * Send a request to the server to execute the queue of prepared write |
kadonotakashi | 0:8fdf9a60065b | 531 | * requests. |
kadonotakashi | 0:8fdf9a60065b | 532 | * |
kadonotakashi | 0:8fdf9a60065b | 533 | * The server should respond with an ExecuteWriteResponse in case of success |
kadonotakashi | 0:8fdf9a60065b | 534 | * and an Error response in case of failure. |
kadonotakashi | 0:8fdf9a60065b | 535 | * |
kadonotakashi | 0:8fdf9a60065b | 536 | * @note This function issue an ATT Execute Write Request. |
kadonotakashi | 0:8fdf9a60065b | 537 | * |
kadonotakashi | 0:8fdf9a60065b | 538 | * @note: This function is one of the base function for the Write Long |
kadonotakashi | 0:8fdf9a60065b | 539 | * Characteristic Value and Reliable Writes GATT procedures. |
kadonotakashi | 0:8fdf9a60065b | 540 | * |
kadonotakashi | 0:8fdf9a60065b | 541 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.4 |
kadonotakashi | 0:8fdf9a60065b | 542 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.9.5 |
kadonotakashi | 0:8fdf9a60065b | 543 | * |
kadonotakashi | 0:8fdf9a60065b | 544 | * @param connection_handle The handle of the connection to send this request to. |
kadonotakashi | 0:8fdf9a60065b | 545 | * @param execute If true, execute the write request queue otherwise cancel it. |
kadonotakashi | 0:8fdf9a60065b | 546 | * |
kadonotakashi | 0:8fdf9a60065b | 547 | * @return BLE_ERROR_NONE or an appropriate error. |
kadonotakashi | 0:8fdf9a60065b | 548 | */ |
kadonotakashi | 0:8fdf9a60065b | 549 | virtual ble_error_t execute_write_queue( |
kadonotakashi | 0:8fdf9a60065b | 550 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 551 | bool execute |
kadonotakashi | 0:8fdf9a60065b | 552 | ) = 0; |
kadonotakashi | 0:8fdf9a60065b | 553 | |
kadonotakashi | 0:8fdf9a60065b | 554 | /** |
kadonotakashi | 0:8fdf9a60065b | 555 | * Register a callback which will handle messages from the server. |
kadonotakashi | 0:8fdf9a60065b | 556 | * |
kadonotakashi | 0:8fdf9a60065b | 557 | * @param cb The callback object which will handle messages from the server. |
kadonotakashi | 0:8fdf9a60065b | 558 | * It accept two parameters in input: The handle of the connection where the |
kadonotakashi | 0:8fdf9a60065b | 559 | * message was received and the message received. Real type of the message |
kadonotakashi | 0:8fdf9a60065b | 560 | * can be obtained from its opcode. |
kadonotakashi | 0:8fdf9a60065b | 561 | */ |
kadonotakashi | 0:8fdf9a60065b | 562 | void when_server_message_received( |
kadonotakashi | 0:8fdf9a60065b | 563 | mbed::Callback<void(connection_handle_t, const AttServerMessage&)> cb |
kadonotakashi | 0:8fdf9a60065b | 564 | ) { |
kadonotakashi | 0:8fdf9a60065b | 565 | _server_message_cb = cb; |
kadonotakashi | 0:8fdf9a60065b | 566 | } |
kadonotakashi | 0:8fdf9a60065b | 567 | |
kadonotakashi | 0:8fdf9a60065b | 568 | /** |
kadonotakashi | 0:8fdf9a60065b | 569 | * Register a callback handling transaction timeout. |
kadonotakashi | 0:8fdf9a60065b | 570 | * |
kadonotakashi | 0:8fdf9a60065b | 571 | * @param cb The callback handling timeout of a transaction. It accepts as |
kadonotakashi | 0:8fdf9a60065b | 572 | * a parameter the connection handle involved in the timeout. |
kadonotakashi | 0:8fdf9a60065b | 573 | * |
kadonotakashi | 0:8fdf9a60065b | 574 | * @note No more attribute protocol requests, commands, indication or |
kadonotakashi | 0:8fdf9a60065b | 575 | * notification shall be sent over a connection implied in a transaction |
kadonotakashi | 0:8fdf9a60065b | 576 | * timeout. To send a new ATT message, the conenction should be |
kadonotakashi | 0:8fdf9a60065b | 577 | * reestablished. |
kadonotakashi | 0:8fdf9a60065b | 578 | */ |
kadonotakashi | 0:8fdf9a60065b | 579 | void when_transaction_timeout( |
kadonotakashi | 0:8fdf9a60065b | 580 | mbed::Callback<void(connection_handle_t)> cb |
kadonotakashi | 0:8fdf9a60065b | 581 | ) { |
kadonotakashi | 0:8fdf9a60065b | 582 | _transaction_timeout_cb = cb; |
kadonotakashi | 0:8fdf9a60065b | 583 | } |
kadonotakashi | 0:8fdf9a60065b | 584 | |
kadonotakashi | 0:8fdf9a60065b | 585 | protected: |
kadonotakashi | 0:8fdf9a60065b | 586 | GattClient() { } |
kadonotakashi | 0:8fdf9a60065b | 587 | |
kadonotakashi | 0:8fdf9a60065b | 588 | virtual ~GattClient() { } |
kadonotakashi | 0:8fdf9a60065b | 589 | |
kadonotakashi | 0:8fdf9a60065b | 590 | /** |
kadonotakashi | 0:8fdf9a60065b | 591 | * Upon server message reception an implementation shall call this function. |
kadonotakashi | 0:8fdf9a60065b | 592 | * |
kadonotakashi | 0:8fdf9a60065b | 593 | * @param connection_handle The handle of the connection which has received |
kadonotakashi | 0:8fdf9a60065b | 594 | * the server message. |
kadonotakashi | 0:8fdf9a60065b | 595 | * @param server_message The message received from the server. |
kadonotakashi | 0:8fdf9a60065b | 596 | */ |
kadonotakashi | 0:8fdf9a60065b | 597 | void on_server_event( |
kadonotakashi | 0:8fdf9a60065b | 598 | connection_handle_t connection_handle, |
kadonotakashi | 0:8fdf9a60065b | 599 | const AttServerMessage& server_message |
kadonotakashi | 0:8fdf9a60065b | 600 | ) { |
kadonotakashi | 0:8fdf9a60065b | 601 | if (_server_message_cb) { |
kadonotakashi | 0:8fdf9a60065b | 602 | _server_message_cb(connection_handle, server_message); |
kadonotakashi | 0:8fdf9a60065b | 603 | } |
kadonotakashi | 0:8fdf9a60065b | 604 | } |
kadonotakashi | 0:8fdf9a60065b | 605 | |
kadonotakashi | 0:8fdf9a60065b | 606 | /** |
kadonotakashi | 0:8fdf9a60065b | 607 | * Upon transaction timeout an implementation shall call this function. |
kadonotakashi | 0:8fdf9a60065b | 608 | * |
kadonotakashi | 0:8fdf9a60065b | 609 | * @param connection_handle The handle of the connection of the transaction |
kadonotakashi | 0:8fdf9a60065b | 610 | * which has times out. |
kadonotakashi | 0:8fdf9a60065b | 611 | * |
kadonotakashi | 0:8fdf9a60065b | 612 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.3.3 |
kadonotakashi | 0:8fdf9a60065b | 613 | * @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part G Section 4.4.14 |
kadonotakashi | 0:8fdf9a60065b | 614 | */ |
kadonotakashi | 0:8fdf9a60065b | 615 | void on_transaction_timeout( |
kadonotakashi | 0:8fdf9a60065b | 616 | connection_handle_t connection_handle |
kadonotakashi | 0:8fdf9a60065b | 617 | ) { |
kadonotakashi | 0:8fdf9a60065b | 618 | if (_transaction_timeout_cb) { |
kadonotakashi | 0:8fdf9a60065b | 619 | _transaction_timeout_cb(connection_handle); |
kadonotakashi | 0:8fdf9a60065b | 620 | } |
kadonotakashi | 0:8fdf9a60065b | 621 | } |
kadonotakashi | 0:8fdf9a60065b | 622 | |
kadonotakashi | 0:8fdf9a60065b | 623 | private: |
kadonotakashi | 0:8fdf9a60065b | 624 | /** |
kadonotakashi | 0:8fdf9a60065b | 625 | * Callback called when the client receive a message from the server. |
kadonotakashi | 0:8fdf9a60065b | 626 | */ |
kadonotakashi | 0:8fdf9a60065b | 627 | mbed::Callback<void(connection_handle_t, const AttServerMessage&)> _server_message_cb; |
kadonotakashi | 0:8fdf9a60065b | 628 | |
kadonotakashi | 0:8fdf9a60065b | 629 | /** |
kadonotakashi | 0:8fdf9a60065b | 630 | * Callback called when a transaction times out. |
kadonotakashi | 0:8fdf9a60065b | 631 | */ |
kadonotakashi | 0:8fdf9a60065b | 632 | mbed::Callback<void(connection_handle_t)> _transaction_timeout_cb; |
kadonotakashi | 0:8fdf9a60065b | 633 | |
kadonotakashi | 0:8fdf9a60065b | 634 | // Disallow copy construction and copy assignment. |
kadonotakashi | 0:8fdf9a60065b | 635 | GattClient(const GattClient&); |
kadonotakashi | 0:8fdf9a60065b | 636 | GattClient& operator=(const GattClient&); |
kadonotakashi | 0:8fdf9a60065b | 637 | }; |
kadonotakashi | 0:8fdf9a60065b | 638 | |
kadonotakashi | 0:8fdf9a60065b | 639 | } // namespace pal |
kadonotakashi | 0:8fdf9a60065b | 640 | } // namespace ble |
kadonotakashi | 0:8fdf9a60065b | 641 | |
kadonotakashi | 0:8fdf9a60065b | 642 | #endif /* BLE_PAL_GATT_CLIENT_H_ */ |