robo 8080
/
BLE_TEST_konashi
konashi/SBBLEのテスト
Fork of BLE_LoopbackUART by
Embed:
(wiki syntax)
Show/hide line numbers
ble_gattc.h
00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is confidential property of Nordic Semiconductor. The use, 00004 * copying, transfer or disclosure of such information is prohibited except by express written 00005 * agreement with Nordic Semiconductor. 00006 * 00007 */ 00008 /** 00009 @addtogroup BLE_GATTC Generic Attribute Profile (GATT) Client 00010 @{ 00011 @brief Definitions and prototypes for the GATT Client interface. 00012 */ 00013 00014 #ifndef BLE_GATTC_H__ 00015 #define BLE_GATTC_H__ 00016 00017 #include "ble_gatt.h" 00018 #include "ble_types.h" 00019 #include "ble_ranges.h" 00020 #include "nrf_svc.h" 00021 00022 /** @addtogroup BLE_GATTC_ENUMERATIONS Enumerations 00023 * @{ */ 00024 00025 /**@brief GATTC API SVC numbers. */ 00026 enum BLE_GATTC_SVCS 00027 { 00028 SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER = BLE_GATTC_SVC_BASE, /**< Primary Service Discovery. */ 00029 SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, /**< Relationship Discovery. */ 00030 SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, /**< Characteristic Discovery. */ 00031 SD_BLE_GATTC_DESCRIPTORS_DISCOVER, /**< Characteristic Descriptor Discovery. */ 00032 SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, /**< Read Characteristic Value by UUID. */ 00033 SD_BLE_GATTC_READ, /**< Generic read. */ 00034 SD_BLE_GATTC_CHAR_VALUES_READ, /**< Read multiple Characteristic Values. */ 00035 SD_BLE_GATTC_WRITE, /**< Generic write. */ 00036 SD_BLE_GATTC_HV_CONFIRM /**< Handle Value Confirmation. */ 00037 }; 00038 00039 /** @} */ 00040 00041 /** @addtogroup BLE_GATTC_DEFINES Defines 00042 * @{ */ 00043 00044 /** @defgroup BLE_ERRORS_GATTC SVC return values specific to GATTC 00045 * @{ */ 00046 #define BLE_ERROR_GATTC_PROC_NOT_PERMITTED (NRF_GATTC_ERR_BASE + 0x000) 00047 /** @} */ 00048 00049 /**@brief Last Attribute Handle. */ 00050 #define BLE_GATTC_HANDLE_END 0xFFFF 00051 00052 /** @} */ 00053 00054 /** @addtogroup BLE_GATTC_STRUCTURES Structures 00055 * @{ */ 00056 00057 /**@brief Operation Handle Range. */ 00058 typedef struct 00059 { 00060 uint16_t start_handle; /**< Start Handle. */ 00061 uint16_t end_handle; /**< End Handle. */ 00062 } ble_gattc_handle_range_t; 00063 00064 00065 /**@brief GATT service. */ 00066 typedef struct 00067 { 00068 ble_uuid_t uuid; /**< Service UUID. */ 00069 ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */ 00070 } ble_gattc_service_t; 00071 00072 00073 /**@brief GATT include. */ 00074 typedef struct 00075 { 00076 uint16_t handle; /**< Include Handle. */ 00077 ble_gattc_service_t included_srvc; /**< Handle of the included service. */ 00078 } ble_gattc_include_t; 00079 00080 00081 /**@brief GATT characteristic. */ 00082 typedef struct 00083 { 00084 ble_uuid_t uuid; /**< Characteristic UUID. */ 00085 ble_gatt_char_props_t char_props; /**< Characteristic Properties. */ 00086 uint8_t char_ext_props : 1; /**< Extended properties present. */ 00087 uint16_t handle_decl; /**< Handle of the Characteristic Declaration. */ 00088 uint16_t handle_value; /**< Handle of the Characteristic Value. */ 00089 } ble_gattc_char_t; 00090 00091 00092 /**@brief GATT descriptor. */ 00093 typedef struct 00094 { 00095 uint16_t handle; /**< Descriptor Handle. */ 00096 ble_uuid_t uuid; /**< Descriptor UUID. */ 00097 } ble_gattc_desc_t; 00098 00099 00100 /**@brief Write Parameters. */ 00101 typedef struct 00102 { 00103 uint8_t write_op; /**< Write Operation to be performed, see @ref BLE_GATT_WRITE_OPS. */ 00104 uint16_t handle; /**< Handle to the attribute to be written. */ 00105 uint16_t offset; /**< Offset in bytes. @note For WRITE_CMD and WRITE_REQ, offset must be 0. */ 00106 uint16_t len; /**< Length of data in bytes. */ 00107 uint8_t* p_value; /**< Pointer to the value data. */ 00108 uint8_t flags; /**< Flags, see @ref BLE_GATT_EXEC_WRITE_FLAGS. */ 00109 } ble_gattc_write_params_t; 00110 00111 00112 /** 00113 * @brief GATT Client Event IDs. 00114 */ 00115 enum BLE_GATTC_EVTS 00116 { 00117 BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP = BLE_GATTC_EVT_BASE, /**< Primary Service Discovery Response event. */ 00118 BLE_GATTC_EVT_REL_DISC_RSP, /**< Relationship Discovery Response event. */ 00119 BLE_GATTC_EVT_CHAR_DISC_RSP, /**< Characteristic Discovery Response event. */ 00120 BLE_GATTC_EVT_DESC_DISC_RSP, /**< Descriptor Discovery Response event. */ 00121 BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, /**< Read By UUID Response event. */ 00122 BLE_GATTC_EVT_READ_RSP, /**< Read Response event. */ 00123 BLE_GATTC_EVT_CHAR_VALS_READ_RSP, /**< Read multiple Response event. */ 00124 BLE_GATTC_EVT_WRITE_RSP, /**< Write Response event. */ 00125 BLE_GATTC_EVT_HVX, /**< Handle Value Notification or Indication event. */ 00126 BLE_GATTC_EVT_TIMEOUT /**< Timeout event. */ 00127 }; 00128 00129 /**@brief Event structure for BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. */ 00130 typedef struct 00131 { 00132 uint16_t count; /**< Service count. */ 00133 ble_gattc_service_t services[1]; /**< Service data, variable length. */ 00134 } ble_gattc_evt_prim_srvc_disc_rsp_t; 00135 00136 /**@brief Event structure for BLE_GATTC_EVT_REL_DISC_RSP. */ 00137 typedef struct 00138 { 00139 uint16_t count; /**< Include count. */ 00140 ble_gattc_include_t includes[1]; /**< Include data, variable length. */ 00141 } ble_gattc_evt_rel_disc_rsp_t; 00142 00143 /**@brief Event structure for BLE_GATTC_EVT_CHAR_DISC_RSP. */ 00144 typedef struct 00145 { 00146 uint16_t count; /**< Characteristic count. */ 00147 ble_gattc_char_t chars[1]; /**< Characteristic data, variable length. */ 00148 } ble_gattc_evt_char_disc_rsp_t; 00149 00150 /**@brief Event structure for BLE_GATTC_EVT_DESC_DISC_RSP. */ 00151 typedef struct 00152 { 00153 uint16_t count; /**< Descriptor count. */ 00154 ble_gattc_desc_t descs[1]; /**< Descriptor data, variable length. */ 00155 } ble_gattc_evt_desc_disc_rsp_t; 00156 00157 /**@brief GATT read by UUID handle value pair. */ 00158 typedef struct 00159 { 00160 uint16_t handle; /**< Attribute Handle. */ 00161 uint8_t *p_value; /**< Pointer to value, variable length (length available as value_len in ble_gattc_evt_read_by_uuid_rsp_t). 00162 Please note that this pointer is absolute to the memory provided by the user when retrieving the event, 00163 so it will effectively point to a location inside the handle_value array. */ 00164 } ble_gattc_handle_value_t; 00165 00166 /**@brief Event structure for BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP. */ 00167 typedef struct 00168 { 00169 uint16_t count; /**< Handle-Value Pair Count. */ 00170 uint16_t value_len; /**< Length of the value in Handle-Value(s) list. */ 00171 ble_gattc_handle_value_t handle_value[1]; /**< Handle-Value(s) list, variable length. */ 00172 } ble_gattc_evt_char_val_by_uuid_read_rsp_t; 00173 00174 /**@brief Event structure for BLE_GATTC_EVT_READ_RSP. */ 00175 typedef struct 00176 { 00177 uint16_t handle; /**< Attribute Handle. */ 00178 uint16_t offset; /**< Offset of the attribute data. */ 00179 uint16_t len; /**< Attribute data length. */ 00180 uint8_t data[1]; /**< Attribute data, variable length. */ 00181 } ble_gattc_evt_read_rsp_t; 00182 00183 /**@brief Event structure for BLE_GATTC_EVT_CHAR_VALS_READ_RSP. */ 00184 typedef struct 00185 { 00186 uint16_t len; /**< Concatenated Attribute values length. */ 00187 uint8_t values[1]; /**< Attribute values, variable length. */ 00188 } ble_gattc_evt_char_vals_read_rsp_t; 00189 00190 /**@brief Event structure for BLE_GATTC_EVT_WRITE_RSP. */ 00191 typedef struct 00192 { 00193 uint16_t handle; /**< Attribute Handle. */ 00194 uint8_t write_op; /**< Type of write operation, see @ref BLE_GATT_WRITE_OPS. */ 00195 uint16_t offset; /**< Data Offset. */ 00196 uint16_t len; /**< Data length. */ 00197 uint8_t data[1]; /**< Data, variable length. */ 00198 } ble_gattc_evt_write_rsp_t; 00199 00200 /**@brief Event structure for BLE_GATTC_EVT_HVX. */ 00201 typedef struct 00202 { 00203 uint16_t handle; /**< Handle to which the HVx operation applies. */ 00204 uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */ 00205 uint16_t len; /**< Attribute data length. */ 00206 uint8_t data[1]; /**< Attribute data, variable length. */ 00207 } ble_gattc_evt_hvx_t; 00208 00209 /**@brief Event structure for BLE_GATTC_EVT_TIMEOUT. */ 00210 typedef struct 00211 { 00212 uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */ 00213 } ble_gattc_evt_timeout_t; 00214 00215 /**@brief GATTC event type. */ 00216 typedef struct 00217 { 00218 uint16_t conn_handle; /**< Connection Handle on which event occured. */ 00219 uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */ 00220 uint16_t error_handle; /**< In case of error: The handle causing the error. In all other cases BLE_GATT_HANDLE_INVALID. */ 00221 union 00222 { 00223 ble_gattc_evt_prim_srvc_disc_rsp_t prim_srvc_disc_rsp; /**< Primary Service Discovery Response Event Parameters. */ 00224 ble_gattc_evt_rel_disc_rsp_t rel_disc_rsp; /**< Relationship Discovery Response Event Parameters. */ 00225 ble_gattc_evt_char_disc_rsp_t char_disc_rsp; /**< Characteristic Discovery Response Event Parameters. */ 00226 ble_gattc_evt_desc_disc_rsp_t desc_disc_rsp; /**< Descriptor Discovery Response Event Parameters. */ 00227 ble_gattc_evt_char_val_by_uuid_read_rsp_t char_val_by_uuid_read_rsp; /**< Characteristic Value Read by UUID Response Event Parameters. */ 00228 ble_gattc_evt_read_rsp_t read_rsp; /**< Read Response Event Parameters. */ 00229 ble_gattc_evt_char_vals_read_rsp_t char_vals_read_rsp; /**< Characteristic Values Read Response Event Parameters. */ 00230 ble_gattc_evt_write_rsp_t write_rsp; /**< Write Response Event Parameters. */ 00231 ble_gattc_evt_hvx_t hvx; /**< Handle Value Notification/Indication Event Parameters. */ 00232 ble_gattc_evt_timeout_t timeout; /**< Timeout Event Parameters. */ 00233 } params; /**< Event Parameters. @note Only valid if @ref gatt_status == BLE_GATT_STATUS_SUCCESS. */ 00234 } ble_gattc_evt_t; 00235 /** @} */ 00236 00237 /** @addtogroup BLE_GATTC_FUNCTIONS Functions 00238 * @{ */ 00239 00240 /**@brief Initiate or continue a GATT Primary Service Discovery procedure. 00241 * 00242 * @details This function initiates a Primary Service discovery, starting from the supplied handle. 00243 * If the last service has not been reached, this must be called again with an updated start handle value to continue the search. 00244 * 00245 * @note If any of the discovered services have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with 00246 * type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event. 00247 * 00248 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00249 * @param[in] start_handle Handle to start searching from. 00250 * @param[in] p_srvc_uuid Pointer to the service UUID to be found. If it is NULL, all primary services will be returned. 00251 * 00252 * @return @ref NRF_SUCCESS Successfully started or resumed the Primary Service Discovery procedure. 00253 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00254 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00255 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00256 */ 00257 SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const * const p_srvc_uuid)); 00258 00259 00260 /**@brief Initiate or continue a GATT Relationship Discovery procedure. 00261 * 00262 * @details This function initiates the Find Included Services sub-procedure. If the last included service has not been reached, 00263 * this must be called again with an updated handle range to continue the search. 00264 * 00265 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00266 * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on. 00267 * 00268 * @return @ref NRF_SUCCESS Successfully started or resumed the Relationship Discovery procedure. 00269 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00270 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00271 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00272 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00273 */ 00274 SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range)); 00275 00276 00277 /**@brief Initiate or continue a GATT Characteristic Discovery procedure. 00278 * 00279 * @details This function initiates a Characteristic discovery procedure. If the last Characteristic has not been reached, 00280 * this must be called again with an updated handle range to continue the discovery. 00281 * 00282 * @note If any of the discovered characteristics have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with 00283 * type BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event. 00284 * 00285 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00286 * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on. 00287 * 00288 * @return @ref NRF_SUCCESS Successfully started or resumed the Characteristic Discovery procedure. 00289 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00290 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00291 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00292 */ 00293 SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range)); 00294 00295 00296 /**@brief Initiate or continue a GATT Characteristic Descriptor Discovery procedure. 00297 * 00298 * @details This function initiates the Characteristic Descriptor discovery procedure. If the last Descriptor has not been reached, 00299 * this must be called again with an updated handle range to continue the discovery. 00300 * 00301 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00302 * @param[in] p_handle_range A pointer to the range of handles of the Characteristic to perform this procedure on. 00303 * 00304 * @return @ref NRF_SUCCESS Successfully started or resumed the Descriptor Discovery procedure. 00305 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00306 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00307 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00308 */ 00309 SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * const p_handle_range)); 00310 00311 00312 /**@brief Initiate or continue a GATT Read using Characteristic UUID procedure. 00313 * 00314 * @details This function initiates the Read using Characteristic UUID procedure. If the last Characteristic has not been reached, 00315 * this must be called again with an updated handle range to continue the discovery. 00316 * 00317 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00318 * @param[in] p_uuid Pointer to a Characteristic value UUID to read. 00319 * @param[in] p_handle_range A pointer to the range of handles to perform this procedure on. 00320 * 00321 * @return @ref NRF_SUCCESS Successfully started or resumed the Read using Characteristic UUID procedure. 00322 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00323 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00324 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00325 */ 00326 SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const * const p_uuid, ble_gattc_handle_range_t const * const p_handle_range)); 00327 00328 00329 /**@brief Initiate or continue a GATT Read (Long) Characteristic or Descriptor procedure. 00330 * 00331 * @details This function initiates a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor 00332 * to be read is longer than GATT_MTU - 1, this function must be called multiple times with appropriate offset to read the 00333 * complete value. 00334 * 00335 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00336 * @param[in] handle The handle of the attribute to be read. 00337 * @param[in] offset Offset into the attribute value to be read. 00338 * 00339 * @return @ref NRF_SUCCESS Successfully started or resumed the Read (Long) procedure. 00340 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00341 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00342 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00343 */ 00344 SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset)); 00345 00346 00347 /**@brief Initiate a GATT Read Multiple Characteristic Values procedure. 00348 * 00349 * @details This function initiates a GATT Read Multiple Characteristic Values procedure. 00350 * 00351 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00352 * @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read. 00353 * @param[in] handle_count The number of handles in p_handles. 00354 * 00355 * @return @ref NRF_SUCCESS Successfully started the Read Multiple Characteristic Values procedure. 00356 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00357 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00358 * @return @ref NRF_ERROR_BUSY Client procedure already in progress. 00359 */ 00360 SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const * const p_handles, uint16_t handle_count)); 00361 00362 00363 /**@brief Perform a Write (Characteristic Value or Descriptor, with or without response, signed or not, long or reliable) procedure. 00364 * 00365 * @details This function can perform all write procedures described in GATT. 00366 * 00367 * @note It is important to note that a write without response will <b>consume an application buffer</b>, and will therefore 00368 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. A write on the other hand will use the 00369 * standard client internal buffer and thus will only generate a @ref BLE_GATTC_EVT_WRITE_RSP event as soon as the write response 00370 * has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details. 00371 * 00372 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00373 * @param[in] p_write_params A pointer to a write parameters structure. 00374 * 00375 * @return @ref NRF_SUCCESS Successfully started the Write procedure. 00376 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00377 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied. 00378 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied. 00379 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied. 00380 * @return @ref NRF_ERROR_BUSY Procedure already in progress. 00381 * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left. 00382 */ 00383 SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const * const p_write_params)); 00384 00385 00386 /**@brief Send a Handle Value Confirmation to the GATT Server. 00387 * 00388 * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on. 00389 * @param[in] handle The handle of the attribute in the indication. 00390 * 00391 * @return @ref NRF_SUCCESS Successfully queued the Handle Value Confirmation for transmission. 00392 * @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. 00393 * @return @ref NRF_ERROR_INVALID_STATE No Indication pending to be confirmed. 00394 * @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle. 00395 * @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers left. 00396 */ 00397 SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle)); 00398 00399 /** @} */ 00400 00401 #endif /* BLE_GATTC_H__ */ 00402 00403 /** 00404 @} 00405 @} 00406 */
Generated on Tue Jul 12 2022 20:35:45 by 1.7.2