To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:fc2f9d636751 1 /* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved.
yihui 1:fc2f9d636751 2 *
yihui 1:fc2f9d636751 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:fc2f9d636751 4 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:fc2f9d636751 5 *
yihui 1:fc2f9d636751 6 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:fc2f9d636751 7 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:fc2f9d636751 8 * the file.
yihui 1:fc2f9d636751 9 *
yihui 1:fc2f9d636751 10 */
yihui 1:fc2f9d636751 11
yihui 1:fc2f9d636751 12 /**
yihui 1:fc2f9d636751 13 * @file device_manager.h
yihui 1:fc2f9d636751 14 *
yihui 1:fc2f9d636751 15 * @defgroup device_manager Device Manager
yihui 1:fc2f9d636751 16 * @ingroup ble_sdk_lib
yihui 1:fc2f9d636751 17 * @{
yihui 1:fc2f9d636751 18 * @brief Device Manager Application Interface Abstraction.
yihui 1:fc2f9d636751 19 *
yihui 1:fc2f9d636751 20 * @details The Device Manager module manages Active and Bonded Peers. Management of peer includes
yihui 1:fc2f9d636751 21 * book keeping of contextual information like the Security Keys, GATT
yihui 1:fc2f9d636751 22 * configuration and any application specific information.
yihui 1:fc2f9d636751 23 *
yihui 1:fc2f9d636751 24 * Active Peers are devices which are connected, and may or may not be bonded.
yihui 1:fc2f9d636751 25 * Bonded Peers are devices which are bonded, and may or may not be Active (Connected).
yihui 1:fc2f9d636751 26 * Active Bonded Peer refers to a device which is connected and bonded.
yihui 1:fc2f9d636751 27 *
yihui 1:fc2f9d636751 28 * Paired Devices refers to peer devices that are connected and have necessary context
yihui 1:fc2f9d636751 29 * establishment/exchange for the current connection session. On disconnect,
yihui 1:fc2f9d636751 30 * all contextual information is flushed. For example, SMP Information Exchanged during
yihui 1:fc2f9d636751 31 * pairing and GATT Configuration is not retained on disconnection.
yihui 1:fc2f9d636751 32 *
yihui 1:fc2f9d636751 33 * Note that this module allows management of contextual information but
yihui 1:fc2f9d636751 34 * does not provide an interface for connection management. Therefore, entering connectible
yihui 1:fc2f9d636751 35 * mode, connection establishment, or disconnection of a link with peer is not in scope
yihui 1:fc2f9d636751 36 * of this module.
yihui 1:fc2f9d636751 37 *
yihui 1:fc2f9d636751 38 * For bonded peers, the contextual information is required to be retained on disconnection
yihui 1:fc2f9d636751 39 * and power cycling. Persistent storage of contextual information is handled by the
yihui 1:fc2f9d636751 40 * module. This module categorizes the contextual information into 3 categories:
yihui 1:fc2f9d636751 41 * - <b>Bonding Information</b>
yihui 1:fc2f9d636751 42 * Bond information is the information exchanged between local and peer device to
yihui 1:fc2f9d636751 43 * establish a bond. It also includes peer identification information,
yihui 1:fc2f9d636751 44 * like the peer address or the IRK or both. From here on this category of information
yihui 1:fc2f9d636751 45 * is referred to as Device Context.
yihui 1:fc2f9d636751 46 * - <b>Service/Protocol Information</b>
yihui 1:fc2f9d636751 47 * Service/Protocol information is the information retained for the peer to save on one-time
yihui 1:fc2f9d636751 48 * procedures like the GATT Service Discovery procedures and Service Configurations.
yihui 1:fc2f9d636751 49 * It allows devices to resume data exchange on subsequent reconnection without having
yihui 1:fc2f9d636751 50 * to perform initial set-up procedures each time. From here on this category is
yihui 1:fc2f9d636751 51 * referred to as Service Context.
yihui 1:fc2f9d636751 52 * - <b>Application Information</b>
yihui 1:fc2f9d636751 53 * Application information is the context that the application would like to associate with
yihui 1:fc2f9d636751 54 * each of the bonded device. For example, if the application chooses to rank its peers
yihui 1:fc2f9d636751 55 * in order to manage them better, the rank information could be treated as
yihui 1:fc2f9d636751 56 * Application Information. This storage space is provided to save the application from
yihui 1:fc2f9d636751 57 * maintaining a mapping table with each Device Instance and Application Information.
yihui 1:fc2f9d636751 58 * However, if the application have no use for this, it is possible to not
yihui 1:fc2f9d636751 59 * use or employ this at compile time. From here on this category of information is
yihui 1:fc2f9d636751 60 * referred to as Application Context.
yihui 1:fc2f9d636751 61 */
yihui 1:fc2f9d636751 62
yihui 1:fc2f9d636751 63
yihui 1:fc2f9d636751 64 #ifndef DEVICE_MANAGER_H__
yihui 1:fc2f9d636751 65 #define DEVICE_MANAGER_H__
yihui 1:fc2f9d636751 66
yihui 1:fc2f9d636751 67 #include <stdint.h>
yihui 1:fc2f9d636751 68 #include <stdbool.h>
yihui 1:fc2f9d636751 69 #include "sdk_common.h"
yihui 1:fc2f9d636751 70 #include "ble.h"
yihui 1:fc2f9d636751 71 #include "ble_gap.h"
yihui 1:fc2f9d636751 72 #include "device_manager_cnfg.h"
yihui 1:fc2f9d636751 73
yihui 1:fc2f9d636751 74 /**
yihui 1:fc2f9d636751 75 * @defgroup dm_service_cntext_types Service/Protocol Types
yihui 1:fc2f9d636751 76 *
yihui 1:fc2f9d636751 77 * @brief Describes the possible types of Service/Protocol Contexts for a bonded/peer device.
yihui 1:fc2f9d636751 78 *
yihui 1:fc2f9d636751 79 * @details Possible Service/Protocol context per peer device. The Device Manager provides the
yihui 1:fc2f9d636751 80 * functionality of persistently storing the Service/Protocol context and can automatically
yihui 1:fc2f9d636751 81 * load them when needed.
yihui 1:fc2f9d636751 82 * For example system attributes for a GATT Server. Based on the nature of the application,
yihui 1:fc2f9d636751 83 * not all service types may be needed. The application can specify
yihui 1:fc2f9d636751 84 * only the service/protocol context it wants to use at the time of registration.
yihui 1:fc2f9d636751 85 * @{
yihui 1:fc2f9d636751 86 */
yihui 1:fc2f9d636751 87 #define DM_PROTOCOL_CNTXT_NONE 0x00 /**< No Service Context, this implies the application does not want to associate any service/protocol context with the peer device */
yihui 1:fc2f9d636751 88 #define DM_PROTOCOL_CNTXT_GATT_SRVR_ID 0x01 /**< GATT Server Service Context, this implies the application does associate GATT Server with the peer device and this information will be loaded when needed for a bonded device */
yihui 1:fc2f9d636751 89 #define DM_PROTOCOL_CNTXT_GATT_CLI_ID 0x02 /**< GATT Client Service Context, this implies the application does associate GATT Client with the peer device and this information will be loaded when needed for a bonded device */
yihui 1:fc2f9d636751 90 #define DM_PROTOCOL_CNTXT_ALL \
yihui 1:fc2f9d636751 91 (DM_PROTOCOL_CNTXT_GATT_SRVR_ID | DM_PROTOCOL_CNTXT_GATT_CLI_ID) /**< All Service/Protocol Context, this implies that the application wants to associate all Service/Protocol Information with the bonded device. This is configurable based on system requirements. If the application has only one type of service, this define could be altered to reflect the same. */
yihui 1:fc2f9d636751 92 /** @} */
yihui 1:fc2f9d636751 93
yihui 1:fc2f9d636751 94
yihui 1:fc2f9d636751 95 /**
yihui 1:fc2f9d636751 96 * @defgroup dm_events Device Manager Events
yihui 1:fc2f9d636751 97 *
yihui 1:fc2f9d636751 98 * @brief This section describes the device manager events that are notified to the application.
yihui 1:fc2f9d636751 99 *
yihui 1:fc2f9d636751 100 * @details The Device Manager notifies the application of various asynchronous events using the
yihui 1:fc2f9d636751 101 * asynchronous event notification callback. All events has been categorized into:
yihui 1:fc2f9d636751 102 * a. General.
yihui 1:fc2f9d636751 103 * b. Link Status.
yihui 1:fc2f9d636751 104 * c. Context Management.
yihui 1:fc2f9d636751 105 *
yihui 1:fc2f9d636751 106 * In the callback, these events are notified along with handle that uniquely identifies:
yihui 1:fc2f9d636751 107 * application instance, active instance (if applicable), device instance
yihui 1:fc2f9d636751 108 * bonding instance, (if applicable) and service instance.
yihui 1:fc2f9d636751 109 * Not all events are pertaining to an active connection, for example a context deletion event could occur even if the peer
yihui 1:fc2f9d636751 110 * is not connected. Also, general category of events may not be pertaining to any specific peer.
yihui 1:fc2f9d636751 111 * See also \ref dm_event_cb_t and \ref dm_register.
yihui 1:fc2f9d636751 112 * @{
yihui 1:fc2f9d636751 113 */
yihui 1:fc2f9d636751 114 /**
yihui 1:fc2f9d636751 115 * @defgroup general_events General Events
yihui 1:fc2f9d636751 116 *
yihui 1:fc2f9d636751 117 * @brief General or miscellaneous events.
yihui 1:fc2f9d636751 118 *
yihui 1:fc2f9d636751 119 * @details This category of events are general events not pertaining to a peer or context.
yihui 1:fc2f9d636751 120 *
yihui 1:fc2f9d636751 121 * @{
yihui 1:fc2f9d636751 122 */
yihui 1:fc2f9d636751 123 #define DM_EVT_RFU 0x00 /**< Reserved for future use, is never notified. */
yihui 1:fc2f9d636751 124 #define DM_EVT_ERROR 0x01 /**< Device Manager Event Error. */
yihui 1:fc2f9d636751 125 /** @} */
yihui 1:fc2f9d636751 126
yihui 1:fc2f9d636751 127 /**
yihui 1:fc2f9d636751 128 * @defgroup link_status_events Link Status Events
yihui 1:fc2f9d636751 129 *
yihui 1:fc2f9d636751 130 * @brief Link Status Events.
yihui 1:fc2f9d636751 131 *
yihui 1:fc2f9d636751 132 * @details This category of events notify the application of the link status. Event result associated
yihui 1:fc2f9d636751 133 * with the event is provided along with the event in the callback to provide more details of
yihui 1:fc2f9d636751 134 * whether a procedure succeeded or failed and assist the application in decision making of
yihui 1:fc2f9d636751 135 * how to proceed. For example if a DM_DEVICE_CONNECT_IND is indicated with NRF_SUCCESS
yihui 1:fc2f9d636751 136 * result, the application may want to proceed with discovering and association with
yihui 1:fc2f9d636751 137 * service of the peer. However, if indicated with a failure result, the application may
yihui 1:fc2f9d636751 138 * want to take an alternate action such as reattempting to connect or go into a
yihui 1:fc2f9d636751 139 * sleep mode.
yihui 1:fc2f9d636751 140 *
yihui 1:fc2f9d636751 141 * @{
yihui 1:fc2f9d636751 142 */
yihui 1:fc2f9d636751 143 #define DM_EVT_CONNECTION 0x11 /**< Indicates that link with the peer is established. */
yihui 1:fc2f9d636751 144 #define DM_EVT_DISCONNECTION 0x12 /**< Indicates that link with peer is torn down. */
yihui 1:fc2f9d636751 145 #define DM_EVT_SECURITY_SETUP 0x13 /**< Security procedure for link started indication */
yihui 1:fc2f9d636751 146 #define DM_EVT_SECURITY_SETUP_COMPLETE 0x14 /**< Security procedure for link completion indication. */
yihui 1:fc2f9d636751 147 #define DM_EVT_LINK_SECURED 0x15 /**< Indicates that link with the peer is secured. For bonded devices, subsequent reconnections with bonded peer will result only in this event when the link is secured and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides. */
yihui 1:fc2f9d636751 148 #define DM_EVT_SECURITY_SETUP_REFRESH 0x16 /**< Indicates that the security on the link was re-established. */
yihui 1:fc2f9d636751 149 /** @} */
yihui 1:fc2f9d636751 150
yihui 1:fc2f9d636751 151 /**
yihui 1:fc2f9d636751 152 * @defgroup context_mgmt_events Context Management Events
yihui 1:fc2f9d636751 153 *
yihui 1:fc2f9d636751 154 * @brief Context Management Events.
yihui 1:fc2f9d636751 155 *
yihui 1:fc2f9d636751 156 * @details These events notify the application of the status of context loading and storing.
yihui 1:fc2f9d636751 157 *
yihui 1:fc2f9d636751 158 * @{
yihui 1:fc2f9d636751 159 */
yihui 1:fc2f9d636751 160 #define DM_EVT_DEVICE_CONTEXT_LOADED 0x21 /**< Indicates that device context for a peer is loaded. */
yihui 1:fc2f9d636751 161 #define DM_EVT_DEVICE_CONTEXT_STORED 0x22 /**< Indicates that device context is stored persistently. */
yihui 1:fc2f9d636751 162 #define DM_EVT_DEVICE_CONTEXT_DELETED 0x23 /**< Indicates that device context is deleted. */
yihui 1:fc2f9d636751 163 #define DM_EVT_SERVICE_CONTEXT_LOADED 0x31 /**< Indicates that service context for a peer is loaded. */
yihui 1:fc2f9d636751 164 #define DM_EVT_SERVICE_CONTEXT_STORED 0x32 /**< Indicates that service context is stored persistently. */
yihui 1:fc2f9d636751 165 #define DM_EVT_SERVICE_CONTEXT_DELETED 0x33 /**< Indicates that service context is deleted. */
yihui 1:fc2f9d636751 166 #define DM_EVT_APPL_CONTEXT_LOADED 0x41 /**< Indicates that application context for a peer is loaded. */
yihui 1:fc2f9d636751 167 #define DM_EVT_APPL_CONTEXT_STORED 0x42 /**< Indicates that application context is stored persistently. */
yihui 1:fc2f9d636751 168 #define DM_EVT_APPL_CONTEXT_DELETED 0x43 /**< Indicates that application context is deleted. */
yihui 1:fc2f9d636751 169 /** @} */
yihui 1:fc2f9d636751 170 /** @} */
yihui 1:fc2f9d636751 171
yihui 1:fc2f9d636751 172 #define DM_INVALID_ID 0xFF /**< Invalid instance idenitifer. */
yihui 1:fc2f9d636751 173
yihui 1:fc2f9d636751 174 /**
yihui 1:fc2f9d636751 175 * @defgroup dm_data_structure Device Manager Data Types
yihui 1:fc2f9d636751 176 *
yihui 1:fc2f9d636751 177 * @brief This section describes all the data types exposed by the module to the application.
yihui 1:fc2f9d636751 178 * @{
yihui 1:fc2f9d636751 179 */
yihui 1:fc2f9d636751 180
yihui 1:fc2f9d636751 181 /**
yihui 1:fc2f9d636751 182 * @brief Application Instance.
yihui 1:fc2f9d636751 183 *
yihui 1:fc2f9d636751 184 * @details Application instance uniquely identifies an application. The identifier is allocated by
yihui 1:fc2f9d636751 185 * the device manager when application registers with the module. The application is
yihui 1:fc2f9d636751 186 * expected to identify itself with this instance identifier when initiating subsequent
yihui 1:fc2f9d636751 187 * requests. Application should use the utility API \ref dm_application_instance_set in
yihui 1:fc2f9d636751 188 * order to set its application instance in dm_handle_t needed for all subsequent APIs.
yihui 1:fc2f9d636751 189 * See also \ref dm_register.
yihui 1:fc2f9d636751 190 */
yihui 1:fc2f9d636751 191 typedef uint8_t dm_application_instance_t;
yihui 1:fc2f9d636751 192
yihui 1:fc2f9d636751 193 /**
yihui 1:fc2f9d636751 194 * @brief Connection Instance.
yihui 1:fc2f9d636751 195 *
yihui 1:fc2f9d636751 196 * @details Identifies connection instance for an active device. This instance is allocated by the
yihui 1:fc2f9d636751 197 * device manager when a connection is established and is notified with DM_EVT_CONNECTION
yihui 1:fc2f9d636751 198 * with the event result NRF_SUCCESS.
yihui 1:fc2f9d636751 199 */
yihui 1:fc2f9d636751 200 typedef uint8_t dm_connection_instance_t;
yihui 1:fc2f9d636751 201
yihui 1:fc2f9d636751 202 /**
yihui 1:fc2f9d636751 203 * @brief Device Instance.
yihui 1:fc2f9d636751 204 *
yihui 1:fc2f9d636751 205 * @details Uniquely identifies a bonded peer device. The peer device may or may not be connected.
yihui 1:fc2f9d636751 206 * In case of the central: The bonded device instance to identify the peer is allocated when bonding procedure is initiated by the central using dm_security_setup_req.
yihui 1:fc2f9d636751 207 * In case of the peripheral: When the bonding procedure is successful, the DM_EVT_SECURITY_SETUP_COMPLETE event with success event result, is received.
yihui 1:fc2f9d636751 208 * In case the module cannot add more bonded devices, no instance is allocated, this is indicated by an appropriate error code for the API/event as the case may be. Application can choose to disconnect the link.
yihui 1:fc2f9d636751 209 */
yihui 1:fc2f9d636751 210 typedef uint8_t dm_device_instance_t;
yihui 1:fc2f9d636751 211
yihui 1:fc2f9d636751 212 /**
yihui 1:fc2f9d636751 213 * @brief Service Instance.
yihui 1:fc2f9d636751 214 *
yihui 1:fc2f9d636751 215 * @details Uniquely identifies a peer device. The peer device may or may not be connected. This
yihui 1:fc2f9d636751 216 * instance is allocated by the device manager when a device is bonded and is notified
yihui 1:fc2f9d636751 217 * when security procedures have been initiated.
yihui 1:fc2f9d636751 218 * Security Procedures initiation is notified with DM_SECURITY_SETUP_IND with
yihui 1:fc2f9d636751 219 * success event result. In case the event result indicates that the module cannot add more
yihui 1:fc2f9d636751 220 * bonded devices, no instance is allocated. Application can chose to disconnect the link.
yihui 1:fc2f9d636751 221 */
yihui 1:fc2f9d636751 222 typedef uint8_t dm_service_instance_t;
yihui 1:fc2f9d636751 223
yihui 1:fc2f9d636751 224 /**
yihui 1:fc2f9d636751 225 * @brief Service/Protocol Type Identifier.
yihui 1:fc2f9d636751 226 *
yihui 1:fc2f9d636751 227 * @details Uniquely identifies a service or a protocol type. Service/Protocol Type identification
yihui 1:fc2f9d636751 228 * is needed as each service/protocol can have its own contextual data.
yihui 1:fc2f9d636751 229 * This allows the peer to access more than one service at a time. \ref dm_service_cntext_types describes the
yihui 1:fc2f9d636751 230 * list of services/protocols supported.
yihui 1:fc2f9d636751 231 */
yihui 1:fc2f9d636751 232 typedef uint8_t service_type_t;
yihui 1:fc2f9d636751 233
yihui 1:fc2f9d636751 234 /**@brief Device Manager Master identification and encryption information. */
yihui 1:fc2f9d636751 235 typedef struct dm_enc_key
yihui 1:fc2f9d636751 236 {
yihui 1:fc2f9d636751 237 ble_gap_enc_info_t enc_info; /**< GAP encryption information. */
yihui 1:fc2f9d636751 238 ble_gap_master_id_t master_id; /**< Master identification. */
yihui 1:fc2f9d636751 239 } dm_enc_key_t;
yihui 1:fc2f9d636751 240
yihui 1:fc2f9d636751 241 /** @brief Device Manager identity and address information. */
yihui 1:fc2f9d636751 242 typedef struct dm_id_key
yihui 1:fc2f9d636751 243 {
yihui 1:fc2f9d636751 244 ble_gap_irk_t id_info; /**< Identity information. */
yihui 1:fc2f9d636751 245 ble_gap_addr_t id_addr_info; /**< Identity address information. */
yihui 1:fc2f9d636751 246 } dm_id_key_t;
yihui 1:fc2f9d636751 247
yihui 1:fc2f9d636751 248 /** @brief Device Manager signing information. */
yihui 1:fc2f9d636751 249 typedef struct dm_sign_key
yihui 1:fc2f9d636751 250 {
yihui 1:fc2f9d636751 251 ble_gap_sign_info_t sign_key; /**< GAP signing information. */
yihui 1:fc2f9d636751 252 } dm_sign_key_t;
yihui 1:fc2f9d636751 253
yihui 1:fc2f9d636751 254 /** @brief Security keys. */
yihui 1:fc2f9d636751 255 typedef struct dm_sec_keyset
yihui 1:fc2f9d636751 256 {
yihui 1:fc2f9d636751 257 union
yihui 1:fc2f9d636751 258 {
yihui 1:fc2f9d636751 259 dm_enc_key_t * p_enc_key; /**< Pointer to Device Manager encryption information structure. */
yihui 1:fc2f9d636751 260 ble_gap_enc_info_t * p_enc_info; /**< Pointer to GAP encryption information. */
yihui 1:fc2f9d636751 261 } enc_key;
yihui 1:fc2f9d636751 262 dm_id_key_t * p_id_key; /**< Identity key, or NULL. */
yihui 1:fc2f9d636751 263 dm_sign_key_t * p_sign_key; /**< Signing key, or NULL. */
yihui 1:fc2f9d636751 264 } dm_sec_keys_t;
yihui 1:fc2f9d636751 265
yihui 1:fc2f9d636751 266 /** @brief Device Manager security key set. */
yihui 1:fc2f9d636751 267 typedef struct
yihui 1:fc2f9d636751 268 {
yihui 1:fc2f9d636751 269 dm_sec_keys_t keys_periph; /**< Keys distributed by the device in the Peripheral role. */
yihui 1:fc2f9d636751 270 dm_sec_keys_t keys_central; /**< Keys distributed by the device in the Central role. */
yihui 1:fc2f9d636751 271 } dm_sec_keyset_t;
yihui 1:fc2f9d636751 272
yihui 1:fc2f9d636751 273 /**
yihui 1:fc2f9d636751 274 * @brief Device Handle used for unique identification of each peer.
yihui 1:fc2f9d636751 275 *
yihui 1:fc2f9d636751 276 * @details This data type is used to uniquely identify each peer device. A peer device could be
yihui 1:fc2f9d636751 277 * active and/or bonded. Therefore an instance for active and bonded is provided.
yihui 1:fc2f9d636751 278 * However, the application is expected to treat this is an opaque structure and use this for
yihui 1:fc2f9d636751 279 * all API interactions once stored on appropriate events.
yihui 1:fc2f9d636751 280 * See \ref dm_events.
yihui 1:fc2f9d636751 281 */
yihui 1:fc2f9d636751 282 typedef struct device_handle
yihui 1:fc2f9d636751 283 {
yihui 1:fc2f9d636751 284 dm_application_instance_t appl_id; /**< Identifies the application instances for the device that is being managed. */
yihui 1:fc2f9d636751 285 dm_connection_instance_t connection_id; /**< Identifies the active connection instance. */
yihui 1:fc2f9d636751 286 dm_device_instance_t device_id; /**< Identifies peer instance in the data base. */
yihui 1:fc2f9d636751 287 dm_service_instance_t service_id; /**< Service instance identifier. */
yihui 1:fc2f9d636751 288 } dm_handle_t;
yihui 1:fc2f9d636751 289
yihui 1:fc2f9d636751 290 /**
yihui 1:fc2f9d636751 291 * @brief Definition of Data Context.
yihui 1:fc2f9d636751 292 *
yihui 1:fc2f9d636751 293 * @details Defines contextual data format, it consists of context data length and pointer to data.
yihui 1:fc2f9d636751 294 */
yihui 1:fc2f9d636751 295 typedef struct
yihui 1:fc2f9d636751 296 {
yihui 1:fc2f9d636751 297 uint32_t len; /**< Length of data . */
yihui 1:fc2f9d636751 298 uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */
yihui 1:fc2f9d636751 299 } dm_context_t;
yihui 1:fc2f9d636751 300
yihui 1:fc2f9d636751 301
yihui 1:fc2f9d636751 302 /**
yihui 1:fc2f9d636751 303 * @brief Device Context.
yihui 1:fc2f9d636751 304 *
yihui 1:fc2f9d636751 305 * @details Defines "device context" type for a device managed by device manager.
yihui 1:fc2f9d636751 306 */
yihui 1:fc2f9d636751 307 typedef dm_context_t dm_device_context_t;
yihui 1:fc2f9d636751 308
yihui 1:fc2f9d636751 309 /**
yihui 1:fc2f9d636751 310 * @brief Service Context.
yihui 1:fc2f9d636751 311 *
yihui 1:fc2f9d636751 312 * @details Service context data for a service identified by the 'service_type' field.
yihui 1:fc2f9d636751 313 */
yihui 1:fc2f9d636751 314 typedef struct
yihui 1:fc2f9d636751 315 {
yihui 1:fc2f9d636751 316 service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */
yihui 1:fc2f9d636751 317 dm_context_t context_data; /**< Contains length and pointer to context data */
yihui 1:fc2f9d636751 318 } dm_service_context_t;
yihui 1:fc2f9d636751 319
yihui 1:fc2f9d636751 320 /**
yihui 1:fc2f9d636751 321 * @brief Application context.
yihui 1:fc2f9d636751 322 *
yihui 1:fc2f9d636751 323 * @details The application context can be used by the application to map any application level
yihui 1:fc2f9d636751 324 * information that is to be mapped with a particular peer.
yihui 1:fc2f9d636751 325 * For bonded peers, this information will be stored by the bond manager persistently.
yihui 1:fc2f9d636751 326 * Note that the device manager treats this information as an
yihui 1:fc2f9d636751 327 * opaque block of bytes.
yihui 1:fc2f9d636751 328 * Necessary APIs to get and set this context for a peer have been provided.
yihui 1:fc2f9d636751 329 */
yihui 1:fc2f9d636751 330 typedef dm_context_t dm_application_context_t;
yihui 1:fc2f9d636751 331
yihui 1:fc2f9d636751 332 /**
yihui 1:fc2f9d636751 333 * @brief Event parameters.
yihui 1:fc2f9d636751 334 *
yihui 1:fc2f9d636751 335 * @details Defines event parameters for each of the events notified by the module.
yihui 1:fc2f9d636751 336 */
yihui 1:fc2f9d636751 337 typedef union
yihui 1:fc2f9d636751 338 {
yihui 1:fc2f9d636751 339 ble_gap_evt_t * p_gap_param; /**< All events that are triggered in device manager as a result of GAP events, like connection, disconnection and security procedures are accompanied with GAP parameters. */
yihui 1:fc2f9d636751 340 dm_application_context_t * p_app_context; /**< All events that are associated with application context procedures of store, load, and deletion have this as event parameter. */
yihui 1:fc2f9d636751 341 dm_service_context_t * p_service_context; /**< All events that are associated with service context procedures of store, load and deletion have this as event parameter. */
yihui 1:fc2f9d636751 342 dm_device_context_t * p_device_context; /**< All events that are associated with device context procedures of store, load and deletion have this as event parameter. */
yihui 1:fc2f9d636751 343 } dm_event_param_t;
yihui 1:fc2f9d636751 344
yihui 1:fc2f9d636751 345 /**
yihui 1:fc2f9d636751 346 * @brief Asynchronous events details notified to the application by the module.
yihui 1:fc2f9d636751 347 *
yihui 1:fc2f9d636751 348 * @details Defines event type along with event parameters notified to the application by the
yihui 1:fc2f9d636751 349 * module.
yihui 1:fc2f9d636751 350 */
yihui 1:fc2f9d636751 351 typedef struct
yihui 1:fc2f9d636751 352 {
yihui 1:fc2f9d636751 353 uint8_t event_id; /**< Identifies the event. See \ref dm_events for details on event types and their significance. */
yihui 1:fc2f9d636751 354 dm_event_param_t event_param; /**< Event parameters. Can be NULL if the event does not have any parameters. */
yihui 1:fc2f9d636751 355 uint16_t event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */
yihui 1:fc2f9d636751 356 } dm_event_t;
yihui 1:fc2f9d636751 357
yihui 1:fc2f9d636751 358 /**
yihui 1:fc2f9d636751 359 * @brief Event notification callback registered by application with the module.
yihui 1:fc2f9d636751 360 *
yihui 1:fc2f9d636751 361 * @details Event notification callback registered by application with the module when registering
yihui 1:fc2f9d636751 362 * the module using \ref dm_register API.
yihui 1:fc2f9d636751 363 *
yihui 1:fc2f9d636751 364 * @param[in] p_handle Identifies the peer for which the event is being notified.
yihui 1:fc2f9d636751 365 * @param[in] p_event Identifies the event, any associated parameters and parameter length.
yihui 1:fc2f9d636751 366 * See \ref dm_events for details on event types and their significance.
yihui 1:fc2f9d636751 367 * @param[in,out] event_result Provide additional information on the event.
yihui 1:fc2f9d636751 368 * In addition to SDK error codes there is also a return value
yihui 1:fc2f9d636751 369 * indicating if maximum number of connections has been reached when connecting or bonding.
yihui 1:fc2f9d636751 370 *
yihui 1:fc2f9d636751 371 * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event
yihui 1:fc2f9d636751 372 * successfully. There is no action taken in case application returns a failure.
yihui 1:fc2f9d636751 373 */
yihui 1:fc2f9d636751 374 typedef api_result_t (*dm_event_cb_t)(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 375 dm_event_t const * p_event,
yihui 1:fc2f9d636751 376 api_result_t event_result);
yihui 1:fc2f9d636751 377
yihui 1:fc2f9d636751 378 /**
yihui 1:fc2f9d636751 379 * @brief Initialization Parameters.
yihui 1:fc2f9d636751 380 *
yihui 1:fc2f9d636751 381 * @details Indicates the application parameters. Currently this only encompasses clearing
yihui 1:fc2f9d636751 382 * all persistent data.
yihui 1:fc2f9d636751 383 */
yihui 1:fc2f9d636751 384 typedef struct
yihui 1:fc2f9d636751 385 {
yihui 1:fc2f9d636751 386 bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */
yihui 1:fc2f9d636751 387 } dm_init_param_t;
yihui 1:fc2f9d636751 388
yihui 1:fc2f9d636751 389 /**
yihui 1:fc2f9d636751 390 * @brief Application Registration Parameters.
yihui 1:fc2f9d636751 391 *
yihui 1:fc2f9d636751 392 * @details Parameters needed by the module when registering with it.
yihui 1:fc2f9d636751 393 */
yihui 1:fc2f9d636751 394 typedef struct
yihui 1:fc2f9d636751 395 {
yihui 1:fc2f9d636751 396 dm_event_cb_t evt_handler; /**< Event Handler to be registered. It will receive asynchronous notification from the module, see \ref dm_events for asynchronous events. */
yihui 1:fc2f9d636751 397 uint8_t service_type; /**< Bit mask identifying services that the application intends to support for all peers. */
yihui 1:fc2f9d636751 398 ble_gap_sec_params_t sec_param; /**< Security parameters to be used for the application. */
yihui 1:fc2f9d636751 399 } dm_application_param_t;
yihui 1:fc2f9d636751 400
yihui 1:fc2f9d636751 401 /**
yihui 1:fc2f9d636751 402 * @brief Defines possible security status/states.
yihui 1:fc2f9d636751 403 *
yihui 1:fc2f9d636751 404 * @details Defines possible security status/states of a link when requested by application using
yihui 1:fc2f9d636751 405 * the \ref dm_security_status_req.
yihui 1:fc2f9d636751 406 */
yihui 1:fc2f9d636751 407 typedef enum
yihui 1:fc2f9d636751 408 {
yihui 1:fc2f9d636751 409 NOT_ENCRYPTED, /**< The link does not security. */
yihui 1:fc2f9d636751 410 ENCRYPTION_IN_PROGRESS, /**< Security is in progress of being established.*/
yihui 1:fc2f9d636751 411 ENCRYPTED /**< The link is secure.*/
yihui 1:fc2f9d636751 412 } dm_security_status_t;
yihui 1:fc2f9d636751 413 /** @} */
yihui 1:fc2f9d636751 414
yihui 1:fc2f9d636751 415 /**
yihui 1:fc2f9d636751 416 * @defgroup dm_api Device Module APIs
yihui 1:fc2f9d636751 417 *
yihui 1:fc2f9d636751 418 * @brief This section describes APIs exposed by the module.
yihui 1:fc2f9d636751 419 *
yihui 1:fc2f9d636751 420 * @details This section describes APIs exposed by the module. The APIs have been categorized to provide
yihui 1:fc2f9d636751 421 * better and specific look up for developers. Categories are:
yihui 1:fc2f9d636751 422 * - Set up APIs.
yihui 1:fc2f9d636751 423 * - Context Management APIs.
yihui 1:fc2f9d636751 424 * - Utility APIs.
yihui 1:fc2f9d636751 425 *
yihui 1:fc2f9d636751 426 * MSCs describe usage of these APIs.
yihui 1:fc2f9d636751 427 * See @ref dm_msc.
yihui 1:fc2f9d636751 428 * @{
yihui 1:fc2f9d636751 429 */
yihui 1:fc2f9d636751 430 /**
yihui 1:fc2f9d636751 431 * @defgroup dm_setup_api Device Module Set-up APIs
yihui 1:fc2f9d636751 432 *
yihui 1:fc2f9d636751 433 * @brief Initialization & registration APIs that are pre-requisite for all other module procedures.
yihui 1:fc2f9d636751 434 * @details This section describes the Module Initialization and Registration APIs needed to be set up by
yihui 1:fc2f9d636751 435 * the application before device manager can start managing devices and device contexts
yihui 1:fc2f9d636751 436 * for the application.
yihui 1:fc2f9d636751 437 *
yihui 1:fc2f9d636751 438 * @{
yihui 1:fc2f9d636751 439 */
yihui 1:fc2f9d636751 440
yihui 1:fc2f9d636751 441 /**
yihui 1:fc2f9d636751 442 * @brief Module Initialization Routine.
yihui 1:fc2f9d636751 443 *
yihui 1:fc2f9d636751 444 * @details Function for initializing the module. Must called before any other APIs of the module are used.
yihui 1:fc2f9d636751 445 *
yihui 1:fc2f9d636751 446 * @param[in] p_init_param Initialization parameters.
yihui 1:fc2f9d636751 447 *
yihui 1:fc2f9d636751 448 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 449 *
yihui 1:fc2f9d636751 450 * @note It is mandatory that pstorage is initialized before initializing this module.
yihui 1:fc2f9d636751 451 */
yihui 1:fc2f9d636751 452 api_result_t dm_init(dm_init_param_t const * p_init_param);
yihui 1:fc2f9d636751 453
yihui 1:fc2f9d636751 454 /**
yihui 1:fc2f9d636751 455 * @brief Function for registering the application.
yihui 1:fc2f9d636751 456 *
yihui 1:fc2f9d636751 457 * @details This routine is used by the application to register for asynchronous events with the
yihui 1:fc2f9d636751 458 * device manager. During registration the application also indicates the services that it
yihui 1:fc2f9d636751 459 * intends to support on this instance. It is possible to register multiple times with the
yihui 1:fc2f9d636751 460 * device manager. At least one instance shall be registered with the device manager after
yihui 1:fc2f9d636751 461 * the module has been initialized.
yihui 1:fc2f9d636751 462 * Maximum number of application instances device manager can support is determined
yihui 1:fc2f9d636751 463 * by DM_MAX_APPLICATIONS.
yihui 1:fc2f9d636751 464 *
yihui 1:fc2f9d636751 465 * All applications must be registered before initiating or accepting connections from the peer.
yihui 1:fc2f9d636751 466 *
yihui 1:fc2f9d636751 467 * @param[in] p_appl_param Application parameters.
yihui 1:fc2f9d636751 468 * @param[out] p_appl_instance Application Instance Identifier in case registration is successful.
yihui 1:fc2f9d636751 469 *
yihui 1:fc2f9d636751 470 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 471 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization.
yihui 1:fc2f9d636751 472 * @retval NRF_ERROR_NO_MEM If module cannot support more applications.
yihui 1:fc2f9d636751 473 *
yihui 1:fc2f9d636751 474 * @note Currently only one application instance is supported by the module.
yihui 1:fc2f9d636751 475 */
yihui 1:fc2f9d636751 476 api_result_t dm_register(dm_application_instance_t * p_appl_instance,
yihui 1:fc2f9d636751 477 dm_application_param_t const * p_appl_param);
yihui 1:fc2f9d636751 478
yihui 1:fc2f9d636751 479 /**
yihui 1:fc2f9d636751 480 * @brief Function for handling BLE events.
yihui 1:fc2f9d636751 481 *
yihui 1:fc2f9d636751 482 * @details BLE Event Handler for the module. This routine should be called from BLE stack event
yihui 1:fc2f9d636751 483 * dispatcher for the module to work as expected.
yihui 1:fc2f9d636751 484 *
yihui 1:fc2f9d636751 485 * @param[in] p_ble_evt BLE stack event being dispatched to the function.
yihui 1:fc2f9d636751 486 *
yihui 1:fc2f9d636751 487 */
yihui 1:fc2f9d636751 488 void dm_ble_evt_handler(ble_evt_t * p_ble_evt);
yihui 1:fc2f9d636751 489
yihui 1:fc2f9d636751 490 /** @} */
yihui 1:fc2f9d636751 491
yihui 1:fc2f9d636751 492
yihui 1:fc2f9d636751 493 /**
yihui 1:fc2f9d636751 494 * @defgroup dm_security_api APIs to set up or read status of security on a link.
yihui 1:fc2f9d636751 495 *
yihui 1:fc2f9d636751 496 * @brief This section describes APIs to set up Security. These APIs require that the peer is
yihui 1:fc2f9d636751 497 * connected before the procedures can be requested.
yihui 1:fc2f9d636751 498 *
yihui 1:fc2f9d636751 499 * @details This group allows application to request security procedures
yihui 1:fc2f9d636751 500 * or get the status of the security on a link.
yihui 1:fc2f9d636751 501 * @{
yihui 1:fc2f9d636751 502 */
yihui 1:fc2f9d636751 503 /**
yihui 1:fc2f9d636751 504 * @brief Function for requesting setting up security on a link.
yihui 1:fc2f9d636751 505 *
yihui 1:fc2f9d636751 506 * @details This API initiates security procedures with a peer device.
yihui 1:fc2f9d636751 507 * @note For the GAP Central role, in case peer is not bonded, request to bond/pair is
yihui 1:fc2f9d636751 508 * initiated. If it is bonded, the link is re-encrypted using the existing bond information.
yihui 1:fc2f9d636751 509 * For the GAP peripheral role, a Slave security request is sent.
yihui 1:fc2f9d636751 510 * @details If a pairing procedure is initiated successfully, application is notified of
yihui 1:fc2f9d636751 511 * @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event.
yihui 1:fc2f9d636751 512 * In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is
yihui 1:fc2f9d636751 513 * notified to the application.
yihui 1:fc2f9d636751 514 *
yihui 1:fc2f9d636751 515 * @param[in] p_handle Identifies the link on which security is desired.
yihui 1:fc2f9d636751 516 *
yihui 1:fc2f9d636751 517 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 518 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 519 * application registration.
yihui 1:fc2f9d636751 520 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 521 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application
yihui 1:fc2f9d636751 522 * or if the peer is not connected when this procedure is requested.
yihui 1:fc2f9d636751 523 */
yihui 1:fc2f9d636751 524 api_result_t dm_security_setup_req(dm_handle_t * p_handle);
yihui 1:fc2f9d636751 525
yihui 1:fc2f9d636751 526 /**
yihui 1:fc2f9d636751 527 * @brief Function for reading the status of the security on a link.
yihui 1:fc2f9d636751 528 *
yihui 1:fc2f9d636751 529 * @details This API allows application to query status of security on a link.
yihui 1:fc2f9d636751 530 *
yihui 1:fc2f9d636751 531 * @param[in] p_handle Identifies the link on which security is desired.
yihui 1:fc2f9d636751 532 * @param[out] p_status Pointer where security status is provided to the application.
yihui 1:fc2f9d636751 533 * See \ref dm_security_status_t for possible statuses that can be expected.
yihui 1:fc2f9d636751 534 *
yihui 1:fc2f9d636751 535 * @retval NRF_SUCCESS Or appropriate error code indicating reason for failure.
yihui 1:fc2f9d636751 536 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 537 * application registration.
yihui 1:fc2f9d636751 538 * @retval NRF_ERROR_NULL If p_handle or p_status is NULL.
yihui 1:fc2f9d636751 539 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application
yihui 1:fc2f9d636751 540 * or if peer is not connected when this procedure is requested.
yihui 1:fc2f9d636751 541 */
yihui 1:fc2f9d636751 542 api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status);
yihui 1:fc2f9d636751 543
yihui 1:fc2f9d636751 544 /**
yihui 1:fc2f9d636751 545 * @brief Function for creating the whitelist.
yihui 1:fc2f9d636751 546 *
yihui 1:fc2f9d636751 547 * @details This API allows application to create whitelist based on bonded peer devices in module
yihui 1:fc2f9d636751 548 * data base.
yihui 1:fc2f9d636751 549 *
yihui 1:fc2f9d636751 550 * @param[in] p_handle Identifies the application requesting whitelist creation.
yihui 1:fc2f9d636751 551 * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application.
yihui 1:fc2f9d636751 552 *
yihui 1:fc2f9d636751 553 * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum
yihui 1:fc2f9d636751 554 * number of devices that the application wishes to request in the whitelist.
yihui 1:fc2f9d636751 555 * If the number of bonded devices is less than requested, the fields are updated with that number of devices.
yihui 1:fc2f9d636751 556 * If the number of devices are more than requested, the module will populate the list
yihui 1:fc2f9d636751 557 * with devices in the order the bond was established with the peer devices. Also, if this routine is
yihui 1:fc2f9d636751 558 * called when a connection exists with one or more peer devices,
yihui 1:fc2f9d636751 559 * those connected devices are not added to the whitelist.
yihui 1:fc2f9d636751 560 *
yihui 1:fc2f9d636751 561 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 562 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 563 * application registration.
yihui 1:fc2f9d636751 564 * @retval NRF_ERROR_NULL If p_handle or p_whitelist is NULL.
yihui 1:fc2f9d636751 565 */
yihui 1:fc2f9d636751 566 api_result_t dm_whitelist_create(dm_application_instance_t const * p_handle,
yihui 1:fc2f9d636751 567 ble_gap_whitelist_t * p_whitelist);
yihui 1:fc2f9d636751 568
yihui 1:fc2f9d636751 569 /** @} */
yihui 1:fc2f9d636751 570
yihui 1:fc2f9d636751 571
yihui 1:fc2f9d636751 572 /**
yihui 1:fc2f9d636751 573 * @defgroup dm_cntxt_mgmt_api Context Management APIs
yihui 1:fc2f9d636751 574 *
yihui 1:fc2f9d636751 575 * @brief Utility APIs offered by the device manager to get information about the peer if and
yihui 1:fc2f9d636751 576 * when needed.
yihui 1:fc2f9d636751 577 *
yihui 1:fc2f9d636751 578 * @details This group of API allow the application to access information that is not required to be
yihui 1:fc2f9d636751 579 * maintained by the application but may be needed. Hence it is possible to get the
yihui 1:fc2f9d636751 580 * information from the module instead of mapping all the information with a device
yihui 1:fc2f9d636751 581 * context.
yihui 1:fc2f9d636751 582 * @{
yihui 1:fc2f9d636751 583 */
yihui 1:fc2f9d636751 584
yihui 1:fc2f9d636751 585 api_result_t dm_device_add(dm_handle_t * p_handle,
yihui 1:fc2f9d636751 586 dm_device_context_t const * p_context);
yihui 1:fc2f9d636751 587
yihui 1:fc2f9d636751 588 /**
yihui 1:fc2f9d636751 589 * @brief Function for deleting a peer device context and all related information from the database.
yihui 1:fc2f9d636751 590 *
yihui 1:fc2f9d636751 591 * @details Delete peer device context and all related information from database. If
yihui 1:fc2f9d636751 592 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the
yihui 1:fc2f9d636751 593 * application. Event result notified along with the event indicates success or failure
yihui 1:fc2f9d636751 594 * of this procedure.
yihui 1:fc2f9d636751 595 *
yihui 1:fc2f9d636751 596 * @param[in] p_handle Identifies the peer device to be deleted.
yihui 1:fc2f9d636751 597 *
yihui 1:fc2f9d636751 598 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 599 * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or
yihui 1:fc2f9d636751 600 * application registration.
yihui 1:fc2f9d636751 601 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 602 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application.
yihui 1:fc2f9d636751 603 *
yihui 1:fc2f9d636751 604 * @note Deleting device context results in deleting service and application context for the
yihui 1:fc2f9d636751 605 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
yihui 1:fc2f9d636751 606 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
yihui 1:fc2f9d636751 607 */
yihui 1:fc2f9d636751 608 api_result_t dm_device_delete(dm_handle_t const * p_handle);
yihui 1:fc2f9d636751 609
yihui 1:fc2f9d636751 610 /**
yihui 1:fc2f9d636751 611 * @brief Function for deleting all peer device context and all related information from the database.
yihui 1:fc2f9d636751 612 *
yihui 1:fc2f9d636751 613 * @details Delete peer device context and all related information from database. If
yihui 1:fc2f9d636751 614 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the
yihui 1:fc2f9d636751 615 * application for each device that is deleted from the data base. Event result
yihui 1:fc2f9d636751 616 * notified along with the event indicates success or failure of this procedure.
yihui 1:fc2f9d636751 617 *
yihui 1:fc2f9d636751 618 * @param[in] p_handle Identifies application instance that is requesting
yihui 1:fc2f9d636751 619 * the deletion of all bonded devices.
yihui 1:fc2f9d636751 620 *
yihui 1:fc2f9d636751 621 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 622 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 623 * application registration.
yihui 1:fc2f9d636751 624 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 625 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application.
yihui 1:fc2f9d636751 626 *
yihui 1:fc2f9d636751 627 * @note Deleting device context results in deleting both service and application context for the
yihui 1:fc2f9d636751 628 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
yihui 1:fc2f9d636751 629 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
yihui 1:fc2f9d636751 630 */
yihui 1:fc2f9d636751 631 api_result_t dm_device_delete_all(dm_application_instance_t const * p_handle);
yihui 1:fc2f9d636751 632
yihui 1:fc2f9d636751 633 /**
yihui 1:fc2f9d636751 634 * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter.
yihui 1:fc2f9d636751 635 *
yihui 1:fc2f9d636751 636 * @details This API allows application to Set Service Context for a peer device identified by the
yihui 1:fc2f9d636751 637 * 'p_handle' parameter. This API is useful when the Service Context cannot be requested
yihui 1:fc2f9d636751 638 * from the SoftDevice, but needs to be assembled by the application or an another module.
yihui 1:fc2f9d636751 639 * (or when service context is exchanged in an out of band way.)
yihui 1:fc2f9d636751 640 * This API could also be used to trigger a storing of service context into persistent
yihui 1:fc2f9d636751 641 * memory. If this is desired, a NULL pointer could be passed to the p_context.
yihui 1:fc2f9d636751 642 *
yihui 1:fc2f9d636751 643 * @param[in] p_handle Identifies peer device for which the procedure is requested.
yihui 1:fc2f9d636751 644 * @param[in] p_context Service context being set. The context information includes length of
yihui 1:fc2f9d636751 645 * data and pointer to the contextual data being set. The memory pointed to by
yihui 1:fc2f9d636751 646 * the pointer to data is assumed to be resident when API is being called and
yihui 1:fc2f9d636751 647 * can be freed or reused once the set procedure is complete. Set procedure
yihui 1:fc2f9d636751 648 * completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED.
yihui 1:fc2f9d636751 649 * The Event result is notified along with the event and indicates success or failure of
yihui 1:fc2f9d636751 650 * this procedure.
yihui 1:fc2f9d636751 651 *
yihui 1:fc2f9d636751 652 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 653 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 654 * application registration.
yihui 1:fc2f9d636751 655 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 656 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 657 */
yihui 1:fc2f9d636751 658 api_result_t dm_service_context_set(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 659 dm_service_context_t const * p_context);
yihui 1:fc2f9d636751 660
yihui 1:fc2f9d636751 661 /**
yihui 1:fc2f9d636751 662 * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter.
yihui 1:fc2f9d636751 663 *
yihui 1:fc2f9d636751 664 * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If
yihui 1:fc2f9d636751 665 * this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the
yihui 1:fc2f9d636751 666 * application. The event result is notified along with the event indicates success or failure
yihui 1:fc2f9d636751 667 * of this procedure.
yihui 1:fc2f9d636751 668 *
yihui 1:fc2f9d636751 669 * @param[in] p_handle Identifies peer device for which procedure is requested.
yihui 1:fc2f9d636751 670 * @param[in] p_context Application context being requested. The context information includes length
yihui 1:fc2f9d636751 671 * of the data and a pointer to the data. Note that requesting a 'get'
yihui 1:fc2f9d636751 672 * of application does not need to provide memory, the pointer to data will be
yihui 1:fc2f9d636751 673 * pointing to service data and hence no data movement is involved.
yihui 1:fc2f9d636751 674 *
yihui 1:fc2f9d636751 675 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 676 * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or
yihui 1:fc2f9d636751 677 * application registration.
yihui 1:fc2f9d636751 678 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 679 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 680 */
yihui 1:fc2f9d636751 681 api_result_t dm_service_context_get(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 682 dm_service_context_t * p_context);
yihui 1:fc2f9d636751 683
yihui 1:fc2f9d636751 684 /**
yihui 1:fc2f9d636751 685 * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter.
yihui 1:fc2f9d636751 686 *
yihui 1:fc2f9d636751 687 * @details This API allows application to delete a Service Context identified for a peer device
yihui 1:fc2f9d636751 688 * identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS,
yihui 1:fc2f9d636751 689 * DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application.
yihui 1:fc2f9d636751 690 * Event result is notified along with the event and indicates success or failure of this
yihui 1:fc2f9d636751 691 * procedure.
yihui 1:fc2f9d636751 692 *
yihui 1:fc2f9d636751 693 * @param[in] p_handle Identifies peer device for which procedure is requested.
yihui 1:fc2f9d636751 694 *
yihui 1:fc2f9d636751 695 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 696 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 697 * application registration.
yihui 1:fc2f9d636751 698 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 699 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 700 */
yihui 1:fc2f9d636751 701 api_result_t dm_service_context_delete(dm_handle_t const * p_handle);
yihui 1:fc2f9d636751 702
yihui 1:fc2f9d636751 703 /**
yihui 1:fc2f9d636751 704 * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter.
yihui 1:fc2f9d636751 705 *
yihui 1:fc2f9d636751 706 * @details This application allows the setting of the application context for the peer device identified by
yihui 1:fc2f9d636751 707 * the 'p_handle'. Application context is stored persistently by the module and can be
yihui 1:fc2f9d636751 708 * requested by the application at any time using the \ref dm_application_context_get
yihui 1:fc2f9d636751 709 * API. Note that this procedure is permitted only for bonded devices. If the
yihui 1:fc2f9d636751 710 * device is not bonded, application context cannot be set. However, it is not mandatory
yihui 1:fc2f9d636751 711 * that the bonded device is connected when requesting this procedure.
yihui 1:fc2f9d636751 712 *
yihui 1:fc2f9d636751 713 * @param[in] p_handle Identifies peer device for which procedure is requested.
yihui 1:fc2f9d636751 714 *
yihui 1:fc2f9d636751 715 * @param[in] p_context Application context being set. The context information includes length of the
yihui 1:fc2f9d636751 716 * data and pointer to the contextual data being set. The memory pointed to by
yihui 1:fc2f9d636751 717 * the data pointer is assumed to be resident when API is being called and
yihui 1:fc2f9d636751 718 * can be freed or reused once the set procedure is complete. Set procedure
yihui 1:fc2f9d636751 719 * completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED.
yihui 1:fc2f9d636751 720 * The event result is notified along with the event and indicates success or
yihui 1:fc2f9d636751 721 * failure of this procedure.
yihui 1:fc2f9d636751 722 *
yihui 1:fc2f9d636751 723 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 724 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 725 * application registration.
yihui 1:fc2f9d636751 726 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL.
yihui 1:fc2f9d636751 727 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application.
yihui 1:fc2f9d636751 728 *
yihui 1:fc2f9d636751 729 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
yihui 1:fc2f9d636751 730 */
yihui 1:fc2f9d636751 731 api_result_t dm_application_context_set(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 732 dm_application_context_t const * p_context);
yihui 1:fc2f9d636751 733
yihui 1:fc2f9d636751 734 /**
yihui 1:fc2f9d636751 735 * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter.
yihui 1:fc2f9d636751 736 *
yihui 1:fc2f9d636751 737 * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If
yihui 1:fc2f9d636751 738 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the
yihui 1:fc2f9d636751 739 * application. Event result notified along with the event indicates success or failure
yihui 1:fc2f9d636751 740 * of this procedure.
yihui 1:fc2f9d636751 741 *
yihui 1:fc2f9d636751 742 * @param[in] p_handle Identifies peer device for which procedure is requested.
yihui 1:fc2f9d636751 743 * @param[in] p_context Application context being requested. The context information includes
yihui 1:fc2f9d636751 744 * length of data and pointer to the contextual data is provided.
yihui 1:fc2f9d636751 745 *
yihui 1:fc2f9d636751 746 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 747 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 748 * application registration.
yihui 1:fc2f9d636751 749 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL.
yihui 1:fc2f9d636751 750 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 751 * @retval DM_NO_APP_CONTEXT If no application context was set that can be fetched.
yihui 1:fc2f9d636751 752 *
yihui 1:fc2f9d636751 753 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to
yihui 1:fc2f9d636751 754 * zero.
yihui 1:fc2f9d636751 755 */
yihui 1:fc2f9d636751 756 api_result_t dm_application_context_get(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 757 dm_application_context_t * p_context);
yihui 1:fc2f9d636751 758
yihui 1:fc2f9d636751 759 /**
yihui 1:fc2f9d636751 760 * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter.
yihui 1:fc2f9d636751 761 *
yihui 1:fc2f9d636751 762 * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If
yihui 1:fc2f9d636751 763 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the
yihui 1:fc2f9d636751 764 * application. The event result notified along with the event and indicates success or failure
yihui 1:fc2f9d636751 765 * of this procedure.
yihui 1:fc2f9d636751 766 *
yihui 1:fc2f9d636751 767 * @param[in] p_handle Identifies peer device for which procedure is requested.
yihui 1:fc2f9d636751 768 *
yihui 1:fc2f9d636751 769 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 770 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 771 * application registration.
yihui 1:fc2f9d636751 772 * @retval NRF_ERROR_NULL If the p_handle is NULL.
yihui 1:fc2f9d636751 773 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application.
yihui 1:fc2f9d636751 774 * @retval DM_NO_APP_CONTEXT If no application context was set that can be deleted.
yihui 1:fc2f9d636751 775 *
yihui 1:fc2f9d636751 776 * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
yihui 1:fc2f9d636751 777 */
yihui 1:fc2f9d636751 778 api_result_t dm_application_context_delete(dm_handle_t const * p_handle);
yihui 1:fc2f9d636751 779
yihui 1:fc2f9d636751 780 /** @} */
yihui 1:fc2f9d636751 781
yihui 1:fc2f9d636751 782
yihui 1:fc2f9d636751 783 /**
yihui 1:fc2f9d636751 784 * @defgroup utility_api Utility APIs
yihui 1:fc2f9d636751 785 * @{
yihui 1:fc2f9d636751 786 * @brief This section describes the utility APIs offered by the module.
yihui 1:fc2f9d636751 787 *
yihui 1:fc2f9d636751 788 * @details APIs defined in this section are utility or assisting/helper APIs.
yihui 1:fc2f9d636751 789 */
yihui 1:fc2f9d636751 790 /**
yihui 1:fc2f9d636751 791 * @brief Function for Setting/Copying Application instance to Device Manager handle.
yihui 1:fc2f9d636751 792 *
yihui 1:fc2f9d636751 793 * @param[in] p_appl_instance Application instance to be set.
yihui 1:fc2f9d636751 794 * @param[out] p_handle Device Manager handle for which the instance is to be copied.
yihui 1:fc2f9d636751 795 *
yihui 1:fc2f9d636751 796 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 797 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 798 * application registration.
yihui 1:fc2f9d636751 799 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL.
yihui 1:fc2f9d636751 800 */
yihui 1:fc2f9d636751 801 api_result_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
yihui 1:fc2f9d636751 802 dm_handle_t * p_handle);
yihui 1:fc2f9d636751 803
yihui 1:fc2f9d636751 804 /**
yihui 1:fc2f9d636751 805 * @brief Function for getting a peer's device address.
yihui 1:fc2f9d636751 806 *
yihui 1:fc2f9d636751 807 * @param[in] p_handle Identifies the peer device whose address is requested. Can not be NULL.
yihui 1:fc2f9d636751 808 * @param[out] p_addr Pointer where address is to be copied. Can not be NULL.
yihui 1:fc2f9d636751 809 *
yihui 1:fc2f9d636751 810 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 811 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 812 * application registration.
yihui 1:fc2f9d636751 813 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL.
yihui 1:fc2f9d636751 814 * @retval NRF_ERROR_NOT_FOUND If the peer could not be identified.
yihui 1:fc2f9d636751 815 */
yihui 1:fc2f9d636751 816 api_result_t dm_peer_addr_get(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 817 ble_gap_addr_t * p_addr);
yihui 1:fc2f9d636751 818
yihui 1:fc2f9d636751 819 /**
yihui 1:fc2f9d636751 820 * @brief Function for setting/updating a peer's device address.
yihui 1:fc2f9d636751 821 *
yihui 1:fc2f9d636751 822 * @param[in] p_handle Identifies the peer device whose address is requested to be set/updated.
yihui 1:fc2f9d636751 823 * @param[out] p_addr Address to be set/updated.
yihui 1:fc2f9d636751 824 *
yihui 1:fc2f9d636751 825 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 826 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 827 * application registration.
yihui 1:fc2f9d636751 828 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL.
yihui 1:fc2f9d636751 829 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 830 * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address
yihui 1:fc2f9d636751 831 * type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE.
yihui 1:fc2f9d636751 832 *
yihui 1:fc2f9d636751 833 * @note Setting or updating a peer's device address is permitted
yihui 1:fc2f9d636751 834 * only for a peer that is bonded and disconnected.
yihui 1:fc2f9d636751 835 * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the
yihui 1:fc2f9d636751 836 * application for this bonded device instance. In order to avoid abnormal behaviour, it is
yihui 1:fc2f9d636751 837 * recommended to not invite/initiate connections on the updated address unless this event
yihui 1:fc2f9d636751 838 * has been notified.
yihui 1:fc2f9d636751 839 */
yihui 1:fc2f9d636751 840 api_result_t dm_peer_addr_set(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 841 ble_gap_addr_t const * p_addr);
yihui 1:fc2f9d636751 842
yihui 1:fc2f9d636751 843 /**
yihui 1:fc2f9d636751 844 * @brief Function for initializing Device Manager handle.
yihui 1:fc2f9d636751 845 *
yihui 1:fc2f9d636751 846 * @param[in] p_handle Device Manager handle to be initialized.
yihui 1:fc2f9d636751 847 *
yihui 1:fc2f9d636751 848 * @retval NRF_SUCCESS On success.
yihui 1:fc2f9d636751 849 * @retval NRF_ERROR_NULL If p_handle is NULL.
yihui 1:fc2f9d636751 850 *
yihui 1:fc2f9d636751 851 * @note This routine is permitted before initialization of the module.
yihui 1:fc2f9d636751 852 */
yihui 1:fc2f9d636751 853 api_result_t dm_handle_initialize(dm_handle_t * p_handle);
yihui 1:fc2f9d636751 854
yihui 1:fc2f9d636751 855 /**
yihui 1:fc2f9d636751 856 * @brief Function for getting distributed keys for a device.
yihui 1:fc2f9d636751 857 *
yihui 1:fc2f9d636751 858 * @details This routine is used to get distributed keys with a bonded device. This API is currently
yihui 1:fc2f9d636751 859 * only available on S120 (GAP Central role).
yihui 1:fc2f9d636751 860 *
yihui 1:fc2f9d636751 861 * @param[in] p_handle Device Manager handle identifying the peer.
yihui 1:fc2f9d636751 862 *
yihui 1:fc2f9d636751 863 * @param[out] p_key_dist Pointer to distributed keys.
yihui 1:fc2f9d636751 864 *
yihui 1:fc2f9d636751 865 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 866 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or
yihui 1:fc2f9d636751 867 * application registration.
yihui 1:fc2f9d636751 868 * @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL.
yihui 1:fc2f9d636751 869 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
yihui 1:fc2f9d636751 870 */
yihui 1:fc2f9d636751 871 api_result_t dm_distributed_keys_get(dm_handle_t const * p_handle,
yihui 1:fc2f9d636751 872 dm_sec_keyset_t * p_key_dist);
yihui 1:fc2f9d636751 873
yihui 1:fc2f9d636751 874 /** @} */
yihui 1:fc2f9d636751 875 /** @} */
yihui 1:fc2f9d636751 876 /** @} */
yihui 1:fc2f9d636751 877 #endif // DEVICE_MANAGER_H__
yihui 1:fc2f9d636751 878