BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

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