The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_VBLUNO51/TOOLCHAIN_GCC_ARM/ble_db_discovery.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_TY51822R3/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/ble/ble_db_discovery/ble_db_discovery.h@169:a7c7b631e539
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2013 Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 3 | * All rights reserved. |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 143:86740a56073b | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 143:86740a56073b | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 15 | * |
AnnaBridge | 143:86740a56073b | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 143:86740a56073b | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 143:86740a56073b | 18 | * written permission. |
AnnaBridge | 143:86740a56073b | 19 | * |
AnnaBridge | 143:86740a56073b | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 143:86740a56073b | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 143:86740a56073b | 22 | * |
AnnaBridge | 143:86740a56073b | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 143:86740a56073b | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 143:86740a56073b | 25 | * |
AnnaBridge | 143:86740a56073b | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 36 | * |
AnnaBridge | 143:86740a56073b | 37 | */ |
AnnaBridge | 143:86740a56073b | 38 | |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | |
AnnaBridge | 143:86740a56073b | 41 | /**@file |
AnnaBridge | 143:86740a56073b | 42 | * |
AnnaBridge | 143:86740a56073b | 43 | * @defgroup ble_sdk_lib_db_discovery Database Discovery |
AnnaBridge | 143:86740a56073b | 44 | * @{ |
AnnaBridge | 143:86740a56073b | 45 | * @ingroup ble_sdk_lib |
AnnaBridge | 143:86740a56073b | 46 | * @brief Database discovery module. |
AnnaBridge | 143:86740a56073b | 47 | * |
AnnaBridge | 143:86740a56073b | 48 | * @details This module contains the APIs and types exposed by the DB Discovery module. These APIs |
AnnaBridge | 143:86740a56073b | 49 | * and types can be used by the application to perform discovery of a service and its |
AnnaBridge | 143:86740a56073b | 50 | * characteristics at the peer server. This module can also be used to discover the |
AnnaBridge | 143:86740a56073b | 51 | * desired services in multiple remote devices. |
AnnaBridge | 143:86740a56073b | 52 | * |
AnnaBridge | 143:86740a56073b | 53 | * @warning The maximum number of characteristics per service that can be discovered by this module |
AnnaBridge | 143:86740a56073b | 54 | * is determined by the number of characteristics in the service structure defined in |
AnnaBridge | 143:86740a56073b | 55 | * db_disc_config.h. If the peer has more than the supported number of characteristics, then |
AnnaBridge | 143:86740a56073b | 56 | * the first found will be discovered and any further characteristics will be ignored. No |
AnnaBridge | 143:86740a56073b | 57 | * descriptors other than Client Characteristic Configuration Descriptors will be searched |
AnnaBridge | 143:86740a56073b | 58 | * for at the peer. |
AnnaBridge | 143:86740a56073b | 59 | * |
AnnaBridge | 143:86740a56073b | 60 | * @note Presently only one instance of a Primary Service can be discovered by this module. If |
AnnaBridge | 143:86740a56073b | 61 | * there are multiple instances of the service at the peer, only the first instance |
AnnaBridge | 143:86740a56073b | 62 | * of it at the peer is fetched and returned to the application. |
AnnaBridge | 143:86740a56073b | 63 | * |
AnnaBridge | 143:86740a56073b | 64 | * @note The application must propagate BLE stack events to this module by calling |
AnnaBridge | 143:86740a56073b | 65 | * ble_db_discovery_on_ble_evt(). |
AnnaBridge | 143:86740a56073b | 66 | * |
AnnaBridge | 143:86740a56073b | 67 | */ |
AnnaBridge | 143:86740a56073b | 68 | |
AnnaBridge | 143:86740a56073b | 69 | #ifndef BLE_DB_DISCOVERY_H__ |
AnnaBridge | 143:86740a56073b | 70 | #define BLE_DB_DISCOVERY_H__ |
AnnaBridge | 143:86740a56073b | 71 | |
AnnaBridge | 143:86740a56073b | 72 | #include <stdint.h> |
AnnaBridge | 143:86740a56073b | 73 | #include "nrf_ble_gattc.h" |
AnnaBridge | 143:86740a56073b | 74 | #include "nrf_ble.h" |
AnnaBridge | 143:86740a56073b | 75 | #include "nrf_error.h" |
AnnaBridge | 143:86740a56073b | 76 | #include "ble_srv_common.h" |
AnnaBridge | 143:86740a56073b | 77 | #include "ble_gatt_db.h" |
AnnaBridge | 143:86740a56073b | 78 | |
AnnaBridge | 143:86740a56073b | 79 | |
AnnaBridge | 143:86740a56073b | 80 | #define BLE_DB_DISCOVERY_MAX_SRV 6 /**< Maximum number of services supported by this module. This also indicates the maximum number of users allowed to be registered to this module. (one user per service). */ |
AnnaBridge | 143:86740a56073b | 81 | |
AnnaBridge | 143:86740a56073b | 82 | |
AnnaBridge | 143:86740a56073b | 83 | /**@brief Type of the DB Discovery event. |
AnnaBridge | 143:86740a56073b | 84 | */ |
AnnaBridge | 143:86740a56073b | 85 | typedef enum |
AnnaBridge | 143:86740a56073b | 86 | { |
AnnaBridge | 143:86740a56073b | 87 | BLE_DB_DISCOVERY_COMPLETE, /**< Event indicating that the GATT Database discovery is complete. */ |
AnnaBridge | 143:86740a56073b | 88 | BLE_DB_DISCOVERY_ERROR, /**< Event indicating that an internal error has occurred in the DB Discovery module. This could typically be because of the SoftDevice API returning an error code during the DB discover.*/ |
AnnaBridge | 143:86740a56073b | 89 | BLE_DB_DISCOVERY_SRV_NOT_FOUND, /**< Event indicating that the service was not found at the peer.*/ |
AnnaBridge | 143:86740a56073b | 90 | BLE_DB_DISCOVERY_AVAILABLE /**< Event indicating that the DB discovery module is available.*/ |
AnnaBridge | 143:86740a56073b | 91 | } ble_db_discovery_evt_type_t; |
AnnaBridge | 143:86740a56073b | 92 | |
AnnaBridge | 143:86740a56073b | 93 | |
AnnaBridge | 143:86740a56073b | 94 | |
AnnaBridge | 143:86740a56073b | 95 | /**@brief Structure for holding the information related to the GATT database at the server. |
AnnaBridge | 143:86740a56073b | 96 | * |
AnnaBridge | 143:86740a56073b | 97 | * @details This module identifies a remote database. Use one instance of this structure per |
AnnaBridge | 143:86740a56073b | 98 | * connection. |
AnnaBridge | 143:86740a56073b | 99 | * |
AnnaBridge | 143:86740a56073b | 100 | * @warning This structure must be zero-initialized. |
AnnaBridge | 143:86740a56073b | 101 | */ |
AnnaBridge | 143:86740a56073b | 102 | typedef struct |
AnnaBridge | 143:86740a56073b | 103 | { |
AnnaBridge | 143:86740a56073b | 104 | ble_gatt_db_srv_t services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered. This is intended for internal use during service discovery.*/ |
AnnaBridge | 143:86740a56073b | 105 | uint8_t srv_count; /**< Number of services at the peers GATT database.*/ |
AnnaBridge | 143:86740a56073b | 106 | uint8_t curr_char_ind; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/ |
AnnaBridge | 143:86740a56073b | 107 | uint8_t curr_srv_ind; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/ |
AnnaBridge | 143:86740a56073b | 108 | bool discovery_in_progress; /**< Variable to indicate if there is a service discovery in progress. */ |
AnnaBridge | 143:86740a56073b | 109 | uint8_t discoveries_count; /**< Number of service discoveries made, both successful and unsuccessful. */ |
AnnaBridge | 143:86740a56073b | 110 | uint16_t conn_handle; /**< Connection handle on which the discovery is started*/ |
AnnaBridge | 143:86740a56073b | 111 | } ble_db_discovery_t; |
AnnaBridge | 143:86740a56073b | 112 | |
AnnaBridge | 143:86740a56073b | 113 | |
AnnaBridge | 143:86740a56073b | 114 | /**@brief Structure containing the event from the DB discovery module to the application. |
AnnaBridge | 143:86740a56073b | 115 | */ |
AnnaBridge | 143:86740a56073b | 116 | typedef struct |
AnnaBridge | 143:86740a56073b | 117 | { |
AnnaBridge | 143:86740a56073b | 118 | ble_db_discovery_evt_type_t evt_type; /**< Type of event. */ |
AnnaBridge | 143:86740a56073b | 119 | uint16_t conn_handle; /**< Handle of the connection for which this event has occurred. */ |
AnnaBridge | 143:86740a56073b | 120 | union |
AnnaBridge | 143:86740a56073b | 121 | { |
AnnaBridge | 143:86740a56073b | 122 | ble_gatt_db_srv_t discovered_db; /**< Structure containing the information about the GATT Database at the server. This will be filled when the event type is @ref BLE_DB_DISCOVERY_COMPLETE.*/ |
AnnaBridge | 143:86740a56073b | 123 | uint32_t err_code; /**< nRF Error code indicating the type of error which occurred in the DB Discovery module. This will be filled when the event type is @ref BLE_DB_DISCOVERY_ERROR. */ |
AnnaBridge | 143:86740a56073b | 124 | } params; |
AnnaBridge | 143:86740a56073b | 125 | } ble_db_discovery_evt_t; |
AnnaBridge | 143:86740a56073b | 126 | |
AnnaBridge | 143:86740a56073b | 127 | |
AnnaBridge | 143:86740a56073b | 128 | /**@brief DB Discovery event handler type. */ |
AnnaBridge | 143:86740a56073b | 129 | typedef void (* ble_db_discovery_evt_handler_t)(ble_db_discovery_evt_t * p_evt); |
AnnaBridge | 143:86740a56073b | 130 | |
AnnaBridge | 143:86740a56073b | 131 | |
AnnaBridge | 143:86740a56073b | 132 | /**@brief Function for initializing the DB Discovery module. |
AnnaBridge | 143:86740a56073b | 133 | * |
AnnaBridge | 143:86740a56073b | 134 | * @param[in] evt_handler Event handler to be called by the DB discovery module when any event |
AnnaBridge | 143:86740a56073b | 135 | * related to discovery of the registered service occurs. |
AnnaBridge | 143:86740a56073b | 136 | * |
AnnaBridge | 143:86740a56073b | 137 | * @retval NRF_SUCCESS On successful initialization. |
AnnaBridge | 143:86740a56073b | 138 | * @retval NRF_ERROR_NULL If the handler was NULL. |
AnnaBridge | 143:86740a56073b | 139 | */ |
AnnaBridge | 143:86740a56073b | 140 | uint32_t ble_db_discovery_init(ble_db_discovery_evt_handler_t evt_handler); |
AnnaBridge | 143:86740a56073b | 141 | |
AnnaBridge | 143:86740a56073b | 142 | |
AnnaBridge | 143:86740a56073b | 143 | /**@brief Function for closing the DB Discovery module. |
AnnaBridge | 143:86740a56073b | 144 | * |
AnnaBridge | 143:86740a56073b | 145 | * @details This function will clear up any internal variables and states maintained by the |
AnnaBridge | 143:86740a56073b | 146 | * module. To re-use the module after calling this function, the function @ref |
AnnaBridge | 143:86740a56073b | 147 | * ble_db_discovery_init must be called again. |
AnnaBridge | 143:86740a56073b | 148 | * |
AnnaBridge | 143:86740a56073b | 149 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 150 | */ |
AnnaBridge | 143:86740a56073b | 151 | uint32_t ble_db_discovery_close(void); |
AnnaBridge | 143:86740a56073b | 152 | |
AnnaBridge | 143:86740a56073b | 153 | |
AnnaBridge | 143:86740a56073b | 154 | /**@brief Function for registering with the DB Discovery module. |
AnnaBridge | 143:86740a56073b | 155 | * |
AnnaBridge | 143:86740a56073b | 156 | * @details The application can use this function to inform which service it is interested in |
AnnaBridge | 143:86740a56073b | 157 | * discovering at the server. |
AnnaBridge | 143:86740a56073b | 158 | * |
AnnaBridge | 143:86740a56073b | 159 | * @param[in] p_uuid Pointer to the UUID of the service to be discovered at the server. |
AnnaBridge | 143:86740a56073b | 160 | * |
AnnaBridge | 143:86740a56073b | 161 | * @note The total number of services that can be discovered by this module is @ref |
AnnaBridge | 143:86740a56073b | 162 | * BLE_DB_DISCOVERY_MAX_SRV. This effectively means that the maximum number of |
AnnaBridge | 143:86740a56073b | 163 | * registrations possible is equal to the @ref BLE_DB_DISCOVERY_MAX_SRV. |
AnnaBridge | 143:86740a56073b | 164 | * |
AnnaBridge | 143:86740a56073b | 165 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 166 | * @retval NRF_ERROR_NULL When a NULL pointer is passed as input. |
AnnaBridge | 143:86740a56073b | 167 | * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the |
AnnaBridge | 143:86740a56073b | 168 | * @ref ble_db_discovery_init. |
AnnaBridge | 143:86740a56073b | 169 | * @retval NRF_ERROR_NO_MEM The maximum number of registrations allowed by this module |
AnnaBridge | 143:86740a56073b | 170 | * has been reached. |
AnnaBridge | 143:86740a56073b | 171 | */ |
AnnaBridge | 143:86740a56073b | 172 | uint32_t ble_db_discovery_evt_register(const ble_uuid_t * const p_uuid); |
AnnaBridge | 143:86740a56073b | 173 | |
AnnaBridge | 143:86740a56073b | 174 | |
AnnaBridge | 143:86740a56073b | 175 | /**@brief Function for starting the discovery of the GATT database at the server. |
AnnaBridge | 143:86740a56073b | 176 | * |
AnnaBridge | 143:86740a56073b | 177 | * @warning p_db_discovery structure must be zero-initialized. |
AnnaBridge | 143:86740a56073b | 178 | * |
AnnaBridge | 143:86740a56073b | 179 | * @param[out] p_db_discovery Pointer to the DB Discovery structure. |
AnnaBridge | 143:86740a56073b | 180 | * @param[in] conn_handle The handle of the connection for which the discovery should be |
AnnaBridge | 143:86740a56073b | 181 | * started. |
AnnaBridge | 143:86740a56073b | 182 | * |
AnnaBridge | 143:86740a56073b | 183 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 184 | * @retval NRF_ERROR_NULL When a NULL pointer is passed as input. |
AnnaBridge | 143:86740a56073b | 185 | * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the |
AnnaBridge | 143:86740a56073b | 186 | * @ref ble_db_discovery_init, or without calling |
AnnaBridge | 143:86740a56073b | 187 | * @ref ble_db_discovery_evt_register. |
AnnaBridge | 143:86740a56073b | 188 | * @retval NRF_ERROR_BUSY If a discovery is already in progress for the current |
AnnaBridge | 143:86740a56073b | 189 | * connection. |
AnnaBridge | 143:86740a56073b | 190 | * |
AnnaBridge | 143:86740a56073b | 191 | * @return This API propagates the error code returned by the |
AnnaBridge | 143:86740a56073b | 192 | * SoftDevice API @ref sd_ble_gattc_primary_services_discover. |
AnnaBridge | 143:86740a56073b | 193 | */ |
AnnaBridge | 143:86740a56073b | 194 | uint32_t ble_db_discovery_start(ble_db_discovery_t * const p_db_discovery, |
AnnaBridge | 143:86740a56073b | 195 | uint16_t conn_handle); |
AnnaBridge | 143:86740a56073b | 196 | |
AnnaBridge | 143:86740a56073b | 197 | |
AnnaBridge | 143:86740a56073b | 198 | /**@brief Function for handling the Application's BLE Stack events. |
AnnaBridge | 143:86740a56073b | 199 | * |
AnnaBridge | 143:86740a56073b | 200 | * @param[in,out] p_db_discovery Pointer to the DB Discovery structure. |
AnnaBridge | 143:86740a56073b | 201 | * @param[in] p_ble_evt Pointer to the BLE event received. |
AnnaBridge | 143:86740a56073b | 202 | */ |
AnnaBridge | 143:86740a56073b | 203 | void ble_db_discovery_on_ble_evt(ble_db_discovery_t * const p_db_discovery, |
AnnaBridge | 143:86740a56073b | 204 | const ble_evt_t * const p_ble_evt); |
AnnaBridge | 143:86740a56073b | 205 | |
AnnaBridge | 143:86740a56073b | 206 | #endif // BLE_DB_DISCOVERY_H__ |
AnnaBridge | 143:86740a56073b | 207 | |
AnnaBridge | 143:86740a56073b | 208 | /** @} */ |