Committer:
jinu
Date:
Thu Feb 09 06:08:17 2017 +0000
Revision:
0:6ba9b94b8997
NRF51 serialization libraries for mDot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jinu 0:6ba9b94b8997 1 /* Copyright (c) Nordic Semiconductor ASA
jinu 0:6ba9b94b8997 2 * All rights reserved.
jinu 0:6ba9b94b8997 3 *
jinu 0:6ba9b94b8997 4 * Redistribution and use in source and binary forms, with or without modification,
jinu 0:6ba9b94b8997 5 * are permitted provided that the following conditions are met:
jinu 0:6ba9b94b8997 6 *
jinu 0:6ba9b94b8997 7 * 1. Redistributions of source code must retain the above copyright notice, this
jinu 0:6ba9b94b8997 8 * list of conditions and the following disclaimer.
jinu 0:6ba9b94b8997 9 *
jinu 0:6ba9b94b8997 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this
jinu 0:6ba9b94b8997 11 * list of conditions and the following disclaimer in the documentation and/or
jinu 0:6ba9b94b8997 12 * other materials provided with the distribution.
jinu 0:6ba9b94b8997 13 *
jinu 0:6ba9b94b8997 14 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
jinu 0:6ba9b94b8997 15 * contributors to this software may be used to endorse or promote products
jinu 0:6ba9b94b8997 16 * derived from this software without specific prior written permission.
jinu 0:6ba9b94b8997 17 *
jinu 0:6ba9b94b8997 18 * 4. This software must only be used in a processor manufactured by Nordic
jinu 0:6ba9b94b8997 19 * Semiconductor ASA, or in a processor manufactured by a third party that
jinu 0:6ba9b94b8997 20 * is used in combination with a processor manufactured by Nordic Semiconductor.
jinu 0:6ba9b94b8997 21 *
jinu 0:6ba9b94b8997 22 *
jinu 0:6ba9b94b8997 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
jinu 0:6ba9b94b8997 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
jinu 0:6ba9b94b8997 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
jinu 0:6ba9b94b8997 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
jinu 0:6ba9b94b8997 27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
jinu 0:6ba9b94b8997 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
jinu 0:6ba9b94b8997 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
jinu 0:6ba9b94b8997 30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
jinu 0:6ba9b94b8997 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
jinu 0:6ba9b94b8997 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jinu 0:6ba9b94b8997 33 */
jinu 0:6ba9b94b8997 34
jinu 0:6ba9b94b8997 35 #include <stdint.h>
jinu 0:6ba9b94b8997 36 #include "ble_gattc.h"
jinu 0:6ba9b94b8997 37 #include "ble_gattc_app.h"
jinu 0:6ba9b94b8997 38 #include "ble_rpc_defines.h"
jinu 0:6ba9b94b8997 39 #include "ble_encode_transport.h"
jinu 0:6ba9b94b8997 40 #include "hal_transport_config.h"
jinu 0:6ba9b94b8997 41 #include "app_error.h"
jinu 0:6ba9b94b8997 42
jinu 0:6ba9b94b8997 43 /**@brief Command response callback function for @ref sd_ble_gattc_primary_services_discover BLE command.
jinu 0:6ba9b94b8997 44 *
jinu 0:6ba9b94b8997 45 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 46 *
jinu 0:6ba9b94b8997 47 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 48 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 49 *
jinu 0:6ba9b94b8997 50 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 51 */
jinu 0:6ba9b94b8997 52 static uint32_t gattc_primary_services_discover_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 53 {
jinu 0:6ba9b94b8997 54 uint32_t result_code;
jinu 0:6ba9b94b8997 55
jinu 0:6ba9b94b8997 56 const uint32_t err_code = ble_gattc_primary_services_discover_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 57 // @note: Should never fail.
jinu 0:6ba9b94b8997 58 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 59
jinu 0:6ba9b94b8997 60 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 61
jinu 0:6ba9b94b8997 62 return result_code;
jinu 0:6ba9b94b8997 63 }
jinu 0:6ba9b94b8997 64
jinu 0:6ba9b94b8997 65 uint32_t sd_ble_gattc_primary_services_discover(uint16_t conn_handle,
jinu 0:6ba9b94b8997 66 uint16_t start_handle,
jinu 0:6ba9b94b8997 67 ble_uuid_t const *const p_srvc_uuid)
jinu 0:6ba9b94b8997 68 {
jinu 0:6ba9b94b8997 69 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 70
jinu 0:6ba9b94b8997 71 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 72 // documentation.
jinu 0:6ba9b94b8997 73
jinu 0:6ba9b94b8997 74 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 75 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 76
jinu 0:6ba9b94b8997 77 const uint32_t err_code = ble_gattc_primary_services_discover_req_enc(conn_handle,
jinu 0:6ba9b94b8997 78 start_handle,
jinu 0:6ba9b94b8997 79 p_srvc_uuid,
jinu 0:6ba9b94b8997 80 &(p_buffer[1]),
jinu 0:6ba9b94b8997 81 &buffer_length);
jinu 0:6ba9b94b8997 82 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 83
jinu 0:6ba9b94b8997 84 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 85 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 86 (++buffer_length),
jinu 0:6ba9b94b8997 87 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 88 gattc_primary_services_discover_rsp_dec);
jinu 0:6ba9b94b8997 89
jinu 0:6ba9b94b8997 90 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 91 }
jinu 0:6ba9b94b8997 92
jinu 0:6ba9b94b8997 93 /**@brief Command response callback function for @ref sd_ble_gattc_relationships_discover BLE command.
jinu 0:6ba9b94b8997 94 *
jinu 0:6ba9b94b8997 95 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 96 *
jinu 0:6ba9b94b8997 97 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 98 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 99 *
jinu 0:6ba9b94b8997 100 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 101 */
jinu 0:6ba9b94b8997 102 static uint32_t gattc_relationships_discover_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 103 {
jinu 0:6ba9b94b8997 104 uint32_t result_code;
jinu 0:6ba9b94b8997 105
jinu 0:6ba9b94b8997 106 const uint32_t err_code = ble_gattc_relationships_discover_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 107 // @note: Should never fail.
jinu 0:6ba9b94b8997 108 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 109
jinu 0:6ba9b94b8997 110 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 111
jinu 0:6ba9b94b8997 112 return result_code;
jinu 0:6ba9b94b8997 113 }
jinu 0:6ba9b94b8997 114
jinu 0:6ba9b94b8997 115 uint32_t sd_ble_gattc_relationships_discover(uint16_t conn_handle,
jinu 0:6ba9b94b8997 116 ble_gattc_handle_range_t const * const p_handle_range)
jinu 0:6ba9b94b8997 117 {
jinu 0:6ba9b94b8997 118 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 119
jinu 0:6ba9b94b8997 120 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 121 // documentation.
jinu 0:6ba9b94b8997 122
jinu 0:6ba9b94b8997 123 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 124 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 125
jinu 0:6ba9b94b8997 126 const uint32_t err_code = ble_gattc_relationships_discover_req_enc(conn_handle,
jinu 0:6ba9b94b8997 127 p_handle_range,
jinu 0:6ba9b94b8997 128 &(p_buffer[1]),
jinu 0:6ba9b94b8997 129 &buffer_length);
jinu 0:6ba9b94b8997 130 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 131
jinu 0:6ba9b94b8997 132 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 133 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 134 (++buffer_length),
jinu 0:6ba9b94b8997 135 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 136 gattc_relationships_discover_rsp_dec);
jinu 0:6ba9b94b8997 137
jinu 0:6ba9b94b8997 138 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 139 }
jinu 0:6ba9b94b8997 140
jinu 0:6ba9b94b8997 141 /**@brief Command response callback function for @ref sd_ble_gattc_characteristics_discover BLE command.
jinu 0:6ba9b94b8997 142 *
jinu 0:6ba9b94b8997 143 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 144 *
jinu 0:6ba9b94b8997 145 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 146 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 147 *
jinu 0:6ba9b94b8997 148 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 149 */
jinu 0:6ba9b94b8997 150 static uint32_t gattc_characteristics_discover_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 151 {
jinu 0:6ba9b94b8997 152 uint32_t result_code;
jinu 0:6ba9b94b8997 153
jinu 0:6ba9b94b8997 154 const uint32_t err_code = ble_gattc_characteristics_discover_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 155 // @note: Should never fail.
jinu 0:6ba9b94b8997 156 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 157
jinu 0:6ba9b94b8997 158 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 159
jinu 0:6ba9b94b8997 160 return result_code;
jinu 0:6ba9b94b8997 161 }
jinu 0:6ba9b94b8997 162
jinu 0:6ba9b94b8997 163 uint32_t sd_ble_gattc_characteristics_discover(uint16_t conn_handle,
jinu 0:6ba9b94b8997 164 ble_gattc_handle_range_t const * const p_handle_range)
jinu 0:6ba9b94b8997 165 {
jinu 0:6ba9b94b8997 166 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 167
jinu 0:6ba9b94b8997 168 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 169 // documentation.
jinu 0:6ba9b94b8997 170
jinu 0:6ba9b94b8997 171 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 172 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 173
jinu 0:6ba9b94b8997 174 const uint32_t err_code = ble_gattc_characteristics_discover_req_enc(conn_handle,
jinu 0:6ba9b94b8997 175 p_handle_range,
jinu 0:6ba9b94b8997 176 &(p_buffer[1]),
jinu 0:6ba9b94b8997 177 &buffer_length);
jinu 0:6ba9b94b8997 178 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 179
jinu 0:6ba9b94b8997 180 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 181 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 182 (++buffer_length),
jinu 0:6ba9b94b8997 183 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 184 gattc_characteristics_discover_rsp_dec);
jinu 0:6ba9b94b8997 185
jinu 0:6ba9b94b8997 186 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 187 }
jinu 0:6ba9b94b8997 188
jinu 0:6ba9b94b8997 189 /**@brief Command response callback function for @ref sd_ble_gattc_descriptors_discover BLE command.
jinu 0:6ba9b94b8997 190 *
jinu 0:6ba9b94b8997 191 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 192 *
jinu 0:6ba9b94b8997 193 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 194 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 195 *
jinu 0:6ba9b94b8997 196 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 197 */
jinu 0:6ba9b94b8997 198 static uint32_t gattc_descriptors_discover_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 199 {
jinu 0:6ba9b94b8997 200 uint32_t result_code;
jinu 0:6ba9b94b8997 201
jinu 0:6ba9b94b8997 202 const uint32_t err_code = ble_gattc_descriptors_discover_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 203 // @note: Should never fail.
jinu 0:6ba9b94b8997 204 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 205
jinu 0:6ba9b94b8997 206 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 207
jinu 0:6ba9b94b8997 208 return result_code;
jinu 0:6ba9b94b8997 209 }
jinu 0:6ba9b94b8997 210
jinu 0:6ba9b94b8997 211 uint32_t sd_ble_gattc_descriptors_discover(uint16_t conn_handle,
jinu 0:6ba9b94b8997 212 ble_gattc_handle_range_t const * const p_handle_range)
jinu 0:6ba9b94b8997 213 {
jinu 0:6ba9b94b8997 214 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 215
jinu 0:6ba9b94b8997 216 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 217 // documentation.
jinu 0:6ba9b94b8997 218
jinu 0:6ba9b94b8997 219 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 220 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 221
jinu 0:6ba9b94b8997 222 const uint32_t err_code = ble_gattc_descriptors_discover_req_enc(conn_handle,
jinu 0:6ba9b94b8997 223 p_handle_range,
jinu 0:6ba9b94b8997 224 &(p_buffer[1]),
jinu 0:6ba9b94b8997 225 &buffer_length);
jinu 0:6ba9b94b8997 226 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 227
jinu 0:6ba9b94b8997 228 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 229 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 230 (++buffer_length),
jinu 0:6ba9b94b8997 231 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 232 gattc_descriptors_discover_rsp_dec);
jinu 0:6ba9b94b8997 233
jinu 0:6ba9b94b8997 234 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 235 }
jinu 0:6ba9b94b8997 236
jinu 0:6ba9b94b8997 237 /**@brief Command response callback function for @ref sd_ble_gattc_char_value_by_uuid_read BLE command.
jinu 0:6ba9b94b8997 238 *
jinu 0:6ba9b94b8997 239 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 240 *
jinu 0:6ba9b94b8997 241 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 242 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 243 *
jinu 0:6ba9b94b8997 244 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 245 */
jinu 0:6ba9b94b8997 246 static uint32_t gattc_char_value_by_uuid_read_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 247 {
jinu 0:6ba9b94b8997 248 uint32_t result_code;
jinu 0:6ba9b94b8997 249
jinu 0:6ba9b94b8997 250 const uint32_t err_code = ble_gattc_char_value_by_uuid_read_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 251 // @note: Should never fail.
jinu 0:6ba9b94b8997 252 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 253
jinu 0:6ba9b94b8997 254 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 255
jinu 0:6ba9b94b8997 256 return result_code;
jinu 0:6ba9b94b8997 257 }
jinu 0:6ba9b94b8997 258
jinu 0:6ba9b94b8997 259 uint32_t sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle,
jinu 0:6ba9b94b8997 260 ble_uuid_t const *const p_uuid,
jinu 0:6ba9b94b8997 261 ble_gattc_handle_range_t const * const p_handle_range)
jinu 0:6ba9b94b8997 262 {
jinu 0:6ba9b94b8997 263 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 264
jinu 0:6ba9b94b8997 265 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 266 // documentation.
jinu 0:6ba9b94b8997 267
jinu 0:6ba9b94b8997 268 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 269 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 270
jinu 0:6ba9b94b8997 271 const uint32_t err_code = ble_gattc_char_value_by_uuid_read_req_enc(conn_handle,
jinu 0:6ba9b94b8997 272 p_uuid,
jinu 0:6ba9b94b8997 273 p_handle_range,
jinu 0:6ba9b94b8997 274 &(p_buffer[1]),
jinu 0:6ba9b94b8997 275 &buffer_length);
jinu 0:6ba9b94b8997 276 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 277
jinu 0:6ba9b94b8997 278 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 279 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 280 (++buffer_length),
jinu 0:6ba9b94b8997 281 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 282 gattc_char_value_by_uuid_read_rsp_dec);
jinu 0:6ba9b94b8997 283
jinu 0:6ba9b94b8997 284 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 285 }
jinu 0:6ba9b94b8997 286
jinu 0:6ba9b94b8997 287 /**@brief Command response callback function for @ref sd_ble_gattc_read BLE command.
jinu 0:6ba9b94b8997 288 *
jinu 0:6ba9b94b8997 289 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 290 *
jinu 0:6ba9b94b8997 291 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 292 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 293 *
jinu 0:6ba9b94b8997 294 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 295 */
jinu 0:6ba9b94b8997 296 static uint32_t gattc_read_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 297 {
jinu 0:6ba9b94b8997 298 uint32_t result_code;
jinu 0:6ba9b94b8997 299
jinu 0:6ba9b94b8997 300 const uint32_t err_code = ble_gattc_read_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 301 // @note: Should never fail.
jinu 0:6ba9b94b8997 302 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 303
jinu 0:6ba9b94b8997 304 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 305
jinu 0:6ba9b94b8997 306 return result_code;
jinu 0:6ba9b94b8997 307 }
jinu 0:6ba9b94b8997 308
jinu 0:6ba9b94b8997 309 uint32_t sd_ble_gattc_read(uint16_t conn_handle,
jinu 0:6ba9b94b8997 310 uint16_t handle,
jinu 0:6ba9b94b8997 311 uint16_t offset)
jinu 0:6ba9b94b8997 312 {
jinu 0:6ba9b94b8997 313 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 314
jinu 0:6ba9b94b8997 315 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 316 // documentation.
jinu 0:6ba9b94b8997 317
jinu 0:6ba9b94b8997 318 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 319 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 320
jinu 0:6ba9b94b8997 321 const uint32_t err_code = ble_gattc_read_req_enc(conn_handle,
jinu 0:6ba9b94b8997 322 handle,
jinu 0:6ba9b94b8997 323 offset,
jinu 0:6ba9b94b8997 324 &(p_buffer[1]),
jinu 0:6ba9b94b8997 325 &buffer_length);
jinu 0:6ba9b94b8997 326 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 327
jinu 0:6ba9b94b8997 328 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 329 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 330 (++buffer_length),
jinu 0:6ba9b94b8997 331 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 332 gattc_read_rsp_dec);
jinu 0:6ba9b94b8997 333
jinu 0:6ba9b94b8997 334 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 335 }
jinu 0:6ba9b94b8997 336
jinu 0:6ba9b94b8997 337 /**@brief Command response callback function for @ref sd_ble_gattc_char_values_read BLE command.
jinu 0:6ba9b94b8997 338 *
jinu 0:6ba9b94b8997 339 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 340 *
jinu 0:6ba9b94b8997 341 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 342 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 343 *
jinu 0:6ba9b94b8997 344 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 345 */
jinu 0:6ba9b94b8997 346 static uint32_t gattc_char_values_read_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 347 {
jinu 0:6ba9b94b8997 348 uint32_t result_code;
jinu 0:6ba9b94b8997 349
jinu 0:6ba9b94b8997 350 const uint32_t err_code = ble_gattc_char_values_read_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 351 // @note: Should never fail.
jinu 0:6ba9b94b8997 352 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 353
jinu 0:6ba9b94b8997 354 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 355
jinu 0:6ba9b94b8997 356 return result_code;
jinu 0:6ba9b94b8997 357 }
jinu 0:6ba9b94b8997 358
jinu 0:6ba9b94b8997 359 uint32_t sd_ble_gattc_char_values_read(uint16_t conn_handle,
jinu 0:6ba9b94b8997 360 uint16_t const * const p_handles,
jinu 0:6ba9b94b8997 361 uint16_t handle_count)
jinu 0:6ba9b94b8997 362 {
jinu 0:6ba9b94b8997 363 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 364
jinu 0:6ba9b94b8997 365 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 366 // documentation.
jinu 0:6ba9b94b8997 367
jinu 0:6ba9b94b8997 368 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 369 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 370
jinu 0:6ba9b94b8997 371 const uint32_t err_code = ble_gattc_char_values_read_req_enc(conn_handle,
jinu 0:6ba9b94b8997 372 p_handles,
jinu 0:6ba9b94b8997 373 handle_count,
jinu 0:6ba9b94b8997 374 &(p_buffer[1]),
jinu 0:6ba9b94b8997 375 &buffer_length);
jinu 0:6ba9b94b8997 376 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 377
jinu 0:6ba9b94b8997 378 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 379 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 380 (++buffer_length),
jinu 0:6ba9b94b8997 381 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 382 gattc_char_values_read_rsp_dec);
jinu 0:6ba9b94b8997 383
jinu 0:6ba9b94b8997 384 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 385 }
jinu 0:6ba9b94b8997 386
jinu 0:6ba9b94b8997 387 /**@brief Command response callback function for @ref sd_ble_gattc_write BLE command.
jinu 0:6ba9b94b8997 388 *
jinu 0:6ba9b94b8997 389 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 390 *
jinu 0:6ba9b94b8997 391 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 392 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 393 *
jinu 0:6ba9b94b8997 394 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 395 */
jinu 0:6ba9b94b8997 396 static uint32_t gattc_write_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 397 {
jinu 0:6ba9b94b8997 398 uint32_t result_code;
jinu 0:6ba9b94b8997 399
jinu 0:6ba9b94b8997 400 const uint32_t err_code = ble_gattc_write_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 401 // @note: Should never fail.
jinu 0:6ba9b94b8997 402 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 403
jinu 0:6ba9b94b8997 404 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 405
jinu 0:6ba9b94b8997 406 return result_code;
jinu 0:6ba9b94b8997 407 }
jinu 0:6ba9b94b8997 408
jinu 0:6ba9b94b8997 409 uint32_t sd_ble_gattc_write(uint16_t conn_handle,
jinu 0:6ba9b94b8997 410 ble_gattc_write_params_t const *const p_write_params)
jinu 0:6ba9b94b8997 411 {
jinu 0:6ba9b94b8997 412 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 413
jinu 0:6ba9b94b8997 414 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 415 // documentation.
jinu 0:6ba9b94b8997 416
jinu 0:6ba9b94b8997 417 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 418 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 419
jinu 0:6ba9b94b8997 420 const uint32_t err_code = ble_gattc_write_req_enc(conn_handle,
jinu 0:6ba9b94b8997 421 p_write_params,
jinu 0:6ba9b94b8997 422 &(p_buffer[1]),
jinu 0:6ba9b94b8997 423 &buffer_length);
jinu 0:6ba9b94b8997 424 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 425
jinu 0:6ba9b94b8997 426 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 427 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 428 (++buffer_length),
jinu 0:6ba9b94b8997 429 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 430 gattc_write_rsp_dec);
jinu 0:6ba9b94b8997 431
jinu 0:6ba9b94b8997 432 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 433 }
jinu 0:6ba9b94b8997 434
jinu 0:6ba9b94b8997 435 /**@brief Command response callback function for @ref sd_ble_gattc_hv_confirm BLE command.
jinu 0:6ba9b94b8997 436 *
jinu 0:6ba9b94b8997 437 * Callback for decoding the command response return code.
jinu 0:6ba9b94b8997 438 *
jinu 0:6ba9b94b8997 439 * @param[in] p_buffer Pointer to begin of command response buffer.
jinu 0:6ba9b94b8997 440 * @param[in] length Length of data in bytes.
jinu 0:6ba9b94b8997 441 *
jinu 0:6ba9b94b8997 442 * @return Decoded command response return code.
jinu 0:6ba9b94b8997 443 */
jinu 0:6ba9b94b8997 444 static uint32_t gattc_hv_confirm_rsp_dec(const uint8_t * p_buffer, uint32_t length)
jinu 0:6ba9b94b8997 445 {
jinu 0:6ba9b94b8997 446 uint32_t result_code;
jinu 0:6ba9b94b8997 447
jinu 0:6ba9b94b8997 448 const uint32_t err_code = ble_gattc_hv_confirm_rsp_dec(p_buffer, length, &result_code);
jinu 0:6ba9b94b8997 449 // @note: Should never fail.
jinu 0:6ba9b94b8997 450 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 451
jinu 0:6ba9b94b8997 452 ble_encode_transport_tx_free();
jinu 0:6ba9b94b8997 453
jinu 0:6ba9b94b8997 454 return result_code;
jinu 0:6ba9b94b8997 455 }
jinu 0:6ba9b94b8997 456
jinu 0:6ba9b94b8997 457 uint32_t sd_ble_gattc_hv_confirm(uint16_t conn_handle,
jinu 0:6ba9b94b8997 458 uint16_t handle)
jinu 0:6ba9b94b8997 459 {
jinu 0:6ba9b94b8997 460 uint8_t * p_buffer = ble_encode_transport_tx_alloc();
jinu 0:6ba9b94b8997 461
jinu 0:6ba9b94b8997 462 // @note: No NULL check required as error checked by called module as defined in API
jinu 0:6ba9b94b8997 463 // documentation.
jinu 0:6ba9b94b8997 464
jinu 0:6ba9b94b8997 465 p_buffer[0] = BLE_RPC_PKT_CMD;
jinu 0:6ba9b94b8997 466 uint32_t buffer_length = HCI_TRANSPORT_PKT_DATA_SIZE - 1u;
jinu 0:6ba9b94b8997 467
jinu 0:6ba9b94b8997 468 const uint32_t err_code = ble_gattc_hv_confirm_req_enc(conn_handle,
jinu 0:6ba9b94b8997 469 handle,
jinu 0:6ba9b94b8997 470 &(p_buffer[1]),
jinu 0:6ba9b94b8997 471 &buffer_length);
jinu 0:6ba9b94b8997 472 APP_ERROR_CHECK(err_code);
jinu 0:6ba9b94b8997 473
jinu 0:6ba9b94b8997 474 // @note: Increment buffer length as internally managed packet type field must be included.
jinu 0:6ba9b94b8997 475 ble_encode_transport_cmd_write(p_buffer,
jinu 0:6ba9b94b8997 476 (++buffer_length),
jinu 0:6ba9b94b8997 477 BLE_ENCODE_WRITE_MODE_RESP,
jinu 0:6ba9b94b8997 478 gattc_hv_confirm_rsp_dec);
jinu 0:6ba9b94b8997 479
jinu 0:6ba9b94b8997 480 return NRF_SUCCESS;
jinu 0:6ba9b94b8997 481 }
jinu 0:6ba9b94b8997 482