Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
device_manager.h
00001 /* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00005 * 00006 * Licensees are granted free, non-transferable use of the information. NO 00007 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00008 * the file. 00009 * 00010 */ 00011 00012 /** 00013 * @file device_manager.h 00014 * 00015 * @defgroup device_manager Device Manager 00016 * @ingroup ble_sdk_lib 00017 * @{ 00018 * @brief Device Manager Application Interface Abstraction. 00019 * 00020 * @details The Device Manager module manages Active and Bonded Peers. Management of peer includes 00021 * book keeping of contextual information like the Security Keys, GATT 00022 * configuration and any application specific information. 00023 * 00024 * Active Peers are devices which are connected, and may or may not be bonded. 00025 * Bonded Peers are devices which are bonded, and may or may not be Active (Connected). 00026 * Active Bonded Peer refers to a device which is connected and bonded. 00027 * 00028 * Paired Devices refers to peer devices that are connected and have necessary context 00029 * establishment/exchange for the current connection session. On disconnect, 00030 * all contextual information is flushed. For example, SMP Information Exchanged during 00031 * pairing and GATT Configuration is not retained on disconnection. 00032 * 00033 * Note that this module allows management of contextual information but 00034 * does not provide an interface for connection management. Therefore, entering connectible 00035 * mode, connection establishment, or disconnection of a link with peer is not in scope 00036 * of this module. 00037 * 00038 * For bonded peers, the contextual information is required to be retained on disconnection 00039 * and power cycling. Persistent storage of contextual information is handled by the 00040 * module. This module categorizes the contextual information into 3 categories: 00041 * - <b>Bonding Information</b> 00042 * Bond information is the information exchanged between local and peer device to 00043 * establish a bond. It also includes peer identification information, 00044 * like the peer address or the IRK or both. From here on this category of information 00045 * is referred to as Device Context. 00046 * - <b>Service/Protocol Information</b> 00047 * Service/Protocol information is the information retained for the peer to save on one-time 00048 * procedures like the GATT Service Discovery procedures and Service Configurations. 00049 * It allows devices to resume data exchange on subsequent reconnection without having 00050 * to perform initial set-up procedures each time. From here on this category is 00051 * referred to as Service Context. 00052 * - <b>Application Information</b> 00053 * Application information is the context that the application would like to associate with 00054 * each of the bonded device. For example, if the application chooses to rank its peers 00055 * in order to manage them better, the rank information could be treated as 00056 * Application Information. This storage space is provided to save the application from 00057 * maintaining a mapping table with each Device Instance and Application Information. 00058 * However, if the application have no use for this, it is possible to not 00059 * use or employ this at compile time. From here on this category of information is 00060 * referred to as Application Context. 00061 */ 00062 00063 00064 #ifndef DEVICE_MANAGER_H__ 00065 #define DEVICE_MANAGER_H__ 00066 00067 #include <stdint.h> 00068 #include <stdbool.h> 00069 #include "sdk_common.h" 00070 #include "ble.h" 00071 #include "ble_gap.h" 00072 #include "device_manager_cnfg.h " 00073 00074 #ifdef __cplusplus 00075 extern "C" { 00076 #endif 00077 00078 /** 00079 * @defgroup dm_service_cntext_types Service/Protocol Types 00080 * 00081 * @brief Describes the possible types of Service/Protocol Contexts for a bonded/peer device. 00082 * 00083 * @details Possible Service/Protocol context per peer device. The Device Manager provides the 00084 * functionality of persistently storing the Service/Protocol context and can automatically 00085 * load them when needed. 00086 * For example system attributes for a GATT Server. Based on the nature of the application, 00087 * not all service types may be needed. The application can specify 00088 * only the service/protocol context it wants to use at the time of registration. 00089 * @{ 00090 */ 00091 #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 */ 00092 #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 */ 00093 #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 */ 00094 #define DM_PROTOCOL_CNTXT_ALL \ 00095 (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. */ 00096 /** @} */ 00097 00098 00099 /** 00100 * @defgroup dm_events Device Manager Events 00101 * 00102 * @brief This section describes the device manager events that are notified to the application. 00103 * 00104 * @details The Device Manager notifies the application of various asynchronous events using the 00105 * asynchronous event notification callback. All events has been categorized into: 00106 * a. General. 00107 * b. Link Status. 00108 * c. Context Management. 00109 * 00110 * In the callback, these events are notified along with handle that uniquely identifies: 00111 * application instance, active instance (if applicable), device instance 00112 * bonding instance, (if applicable) and service instance. 00113 * Not all events are pertaining to an active connection, for example a context deletion event could occur even if the peer 00114 * is not connected. Also, general category of events may not be pertaining to any specific peer. 00115 * See also \ref dm_event_cb_t and \ref dm_register. 00116 * @{ 00117 */ 00118 /** 00119 * @defgroup general_events General Events 00120 * 00121 * @brief General or miscellaneous events. 00122 * 00123 * @details This category of events are general events not pertaining to a peer or context. 00124 * 00125 * @{ 00126 */ 00127 #define DM_EVT_RFU 0x00 /**< Reserved for future use, is never notified. */ 00128 #define DM_EVT_ERROR 0x01 /**< Device Manager Event Error. */ 00129 /** @} */ 00130 00131 /** 00132 * @defgroup link_status_events Link Status Events 00133 * 00134 * @brief Link Status Events. 00135 * 00136 * @details This category of events notify the application of the link status. Event result associated 00137 * with the event is provided along with the event in the callback to provide more details of 00138 * whether a procedure succeeded or failed and assist the application in decision making of 00139 * how to proceed. For example if a DM_DEVICE_CONNECT_IND is indicated with NRF_SUCCESS 00140 * result, the application may want to proceed with discovering and association with 00141 * service of the peer. However, if indicated with a failure result, the application may 00142 * want to take an alternate action such as reattempting to connect or go into a 00143 * sleep mode. 00144 * 00145 * @{ 00146 */ 00147 #define DM_EVT_CONNECTION 0x11 /**< Indicates that link with the peer is established. */ 00148 #define DM_EVT_DISCONNECTION 0x12 /**< Indicates that link with peer is torn down. */ 00149 #define DM_EVT_SECURITY_SETUP 0x13 /**< Security procedure for link started indication */ 00150 #define DM_EVT_SECURITY_SETUP_COMPLETE 0x14 /**< Security procedure for link completion indication. */ 00151 #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. */ 00152 #define DM_EVT_SECURITY_SETUP_REFRESH 0x16 /**< Indicates that the security on the link was re-established. */ 00153 /** @} */ 00154 00155 /** 00156 * @defgroup context_mgmt_events Context Management Events 00157 * 00158 * @brief Context Management Events. 00159 * 00160 * @details These events notify the application of the status of context loading and storing. 00161 * 00162 * @{ 00163 */ 00164 #define DM_EVT_DEVICE_CONTEXT_LOADED 0x21 /**< Indicates that device context for a peer is loaded. */ 00165 #define DM_EVT_DEVICE_CONTEXT_STORED 0x22 /**< Indicates that device context is stored persistently. */ 00166 #define DM_EVT_DEVICE_CONTEXT_DELETED 0x23 /**< Indicates that device context is deleted. */ 00167 #define DM_EVT_SERVICE_CONTEXT_LOADED 0x31 /**< Indicates that service context for a peer is loaded. */ 00168 #define DM_EVT_SERVICE_CONTEXT_STORED 0x32 /**< Indicates that service context is stored persistently. */ 00169 #define DM_EVT_SERVICE_CONTEXT_DELETED 0x33 /**< Indicates that service context is deleted. */ 00170 #define DM_EVT_APPL_CONTEXT_LOADED 0x41 /**< Indicates that application context for a peer is loaded. */ 00171 #define DM_EVT_APPL_CONTEXT_STORED 0x42 /**< Indicates that application context is stored persistently. */ 00172 #define DM_EVT_APPL_CONTEXT_DELETED 0x43 /**< Indicates that application context is deleted. */ 00173 /** @} */ 00174 /** @} */ 00175 00176 #define DM_INVALID_ID 0xFF /**< Invalid instance idenitifer. */ 00177 00178 /** 00179 * @defgroup dm_data_structure Device Manager Data Types 00180 * 00181 * @brief This section describes all the data types exposed by the module to the application. 00182 * @{ 00183 */ 00184 00185 /** 00186 * @brief Application Instance. 00187 * 00188 * @details Application instance uniquely identifies an application. The identifier is allocated by 00189 * the device manager when application registers with the module. The application is 00190 * expected to identify itself with this instance identifier when initiating subsequent 00191 * requests. Application should use the utility API \ref dm_application_instance_set in 00192 * order to set its application instance in dm_handle_t needed for all subsequent APIs. 00193 * See also \ref dm_register. 00194 */ 00195 typedef uint8_t dm_application_instance_t; 00196 00197 /** 00198 * @brief Connection Instance. 00199 * 00200 * @details Identifies connection instance for an active device. This instance is allocated by the 00201 * device manager when a connection is established and is notified with DM_EVT_CONNECTION 00202 * with the event result NRF_SUCCESS. 00203 */ 00204 typedef uint8_t dm_connection_instance_t; 00205 00206 /** 00207 * @brief Device Instance. 00208 * 00209 * @details Uniquely identifies a bonded peer device. The peer device may or may not be connected. 00210 * 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. 00211 * In case of the peripheral: When the bonding procedure is successful, the DM_EVT_SECURITY_SETUP_COMPLETE event with success event result, is received. 00212 * 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. 00213 */ 00214 typedef uint8_t dm_device_instance_t; 00215 00216 /** 00217 * @brief Service Instance. 00218 * 00219 * @details Uniquely identifies a peer device. The peer device may or may not be connected. This 00220 * instance is allocated by the device manager when a device is bonded and is notified 00221 * when security procedures have been initiated. 00222 * Security Procedures initiation is notified with DM_SECURITY_SETUP_IND with 00223 * success event result. In case the event result indicates that the module cannot add more 00224 * bonded devices, no instance is allocated. Application can chose to disconnect the link. 00225 */ 00226 typedef uint8_t dm_service_instance_t; 00227 00228 /** 00229 * @brief Service/Protocol Type Identifier. 00230 * 00231 * @details Uniquely identifies a service or a protocol type. Service/Protocol Type identification 00232 * is needed as each service/protocol can have its own contextual data. 00233 * This allows the peer to access more than one service at a time. \ref dm_service_cntext_types describes the 00234 * list of services/protocols supported. 00235 */ 00236 typedef uint8_t service_type_t; 00237 00238 /**@brief Device Manager Master identification and encryption information. */ 00239 typedef struct dm_enc_key 00240 { 00241 ble_gap_enc_info_t enc_info; /**< GAP encryption information. */ 00242 ble_gap_master_id_t master_id; /**< Master identification. */ 00243 } dm_enc_key_t; 00244 00245 /** @brief Device Manager identity and address information. */ 00246 typedef struct dm_id_key 00247 { 00248 ble_gap_irk_t id_info; /**< Identity information. */ 00249 ble_gap_addr_t id_addr_info; /**< Identity address information. */ 00250 } dm_id_key_t; 00251 00252 /** @brief Device Manager signing information. */ 00253 typedef struct dm_sign_key 00254 { 00255 ble_gap_sign_info_t sign_key; /**< GAP signing information. */ 00256 } dm_sign_key_t; 00257 00258 /** @brief Security keys. */ 00259 typedef struct dm_sec_keyset 00260 { 00261 union 00262 { 00263 dm_enc_key_t * p_enc_key; /**< Pointer to Device Manager encryption information structure. */ 00264 } enc_key; 00265 dm_id_key_t * p_id_key; /**< Identity key, or NULL. */ 00266 dm_sign_key_t * p_sign_key; /**< Signing key, or NULL. */ 00267 } dm_sec_keys_t; 00268 00269 /** @brief Device Manager security key set. */ 00270 typedef struct 00271 { 00272 dm_sec_keys_t keys_periph; /**< Keys distributed by the device in the Peripheral role. */ 00273 dm_sec_keys_t keys_central; /**< Keys distributed by the device in the Central role. */ 00274 } dm_sec_keyset_t; 00275 00276 /** 00277 * @brief Device Handle used for unique identification of each peer. 00278 * 00279 * @details This data type is used to uniquely identify each peer device. A peer device could be 00280 * active and/or bonded. Therefore an instance for active and bonded is provided. 00281 * However, the application is expected to treat this is an opaque structure and use this for 00282 * all API interactions once stored on appropriate events. 00283 * See \ref dm_events. 00284 */ 00285 typedef struct device_handle 00286 { 00287 dm_application_instance_t appl_id; /**< Identifies the application instances for the device that is being managed. */ 00288 dm_connection_instance_t connection_id; /**< Identifies the active connection instance. */ 00289 dm_device_instance_t device_id; /**< Identifies peer instance in the data base. */ 00290 dm_service_instance_t service_id; /**< Service instance identifier. */ 00291 } dm_handle_t; 00292 00293 /** 00294 * @brief Definition of Data Context. 00295 * 00296 * @details Defines contextual data format, it consists of context data length and pointer to data. 00297 */ 00298 typedef struct 00299 { 00300 uint32_t flags; /**< Additional flags identifying data. */ 00301 uint32_t len; /**< Length of data. */ 00302 uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */ 00303 } dm_context_t; 00304 00305 00306 /** 00307 * @brief Device Context. 00308 * 00309 * @details Defines "device context" type for a device managed by device manager. 00310 */ 00311 typedef dm_context_t dm_device_context_t; 00312 00313 /** 00314 * @brief Service Context. 00315 * 00316 * @details Service context data for a service identified by the 'service_type' field. 00317 */ 00318 typedef struct 00319 { 00320 service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */ 00321 dm_context_t context_data; /**< Contains length and pointer to context data */ 00322 } dm_service_context_t; 00323 00324 /** 00325 * @brief Application context. 00326 * 00327 * @details The application context can be used by the application to map any application level 00328 * information that is to be mapped with a particular peer. 00329 * For bonded peers, this information will be stored by the bond manager persistently. 00330 * Note that the device manager treats this information as an 00331 * opaque block of bytes. 00332 * Necessary APIs to get and set this context for a peer have been provided. 00333 */ 00334 typedef dm_context_t dm_application_context_t; 00335 00336 /** 00337 * @brief Event parameters. 00338 * 00339 * @details Defines event parameters for each of the events notified by the module. 00340 */ 00341 typedef union 00342 { 00343 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. */ 00344 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. */ 00345 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. */ 00346 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. */ 00347 } dm_event_param_t; 00348 00349 /** 00350 * @brief Asynchronous events details notified to the application by the module. 00351 * 00352 * @details Defines event type along with event parameters notified to the application by the 00353 * module. 00354 */ 00355 typedef struct 00356 { 00357 uint8_t event_id; /**< Identifies the event. See \ref dm_events for details on event types and their significance. */ 00358 dm_event_param_t event_param; /**< Event parameters. Can be NULL if the event does not have any parameters. */ 00359 uint16_t event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */ 00360 } dm_event_t; 00361 00362 /** 00363 * @brief Event notification callback registered by application with the module. 00364 * 00365 * @details Event notification callback registered by application with the module when registering 00366 * the module using \ref dm_register API. 00367 * 00368 * @param[in] p_handle Identifies the peer for which the event is being notified. 00369 * @param[in] p_event Identifies the event, any associated parameters and parameter length. 00370 * See \ref dm_events for details on event types and their significance. 00371 * @param[in,out] event_result Provide additional information on the event. 00372 * In addition to SDK error codes there is also a return value 00373 * indicating if maximum number of connections has been reached when connecting or bonding. 00374 * 00375 * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event 00376 * successfully. There is no action taken in case application returns a failure. 00377 */ 00378 typedef ret_code_t (*dm_event_cb_t)(dm_handle_t const * p_handle, 00379 dm_event_t const * p_event, 00380 ret_code_t event_result); 00381 00382 /** 00383 * @brief Initialization Parameters. 00384 * 00385 * @details Indicates the application parameters. Currently this only encompasses clearing 00386 * all persistent data. 00387 */ 00388 typedef struct 00389 { 00390 bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */ 00391 } dm_init_param_t; 00392 00393 /** 00394 * @brief Application Registration Parameters. 00395 * 00396 * @details Parameters needed by the module when registering with it. 00397 */ 00398 typedef struct 00399 { 00400 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. */ 00401 uint8_t service_type; /**< Bit mask identifying services that the application intends to support for all peers. */ 00402 ble_gap_sec_params_t sec_param; /**< Security parameters to be used for the application. */ 00403 } dm_application_param_t; 00404 00405 /** 00406 * @brief Defines possible security status/states. 00407 * 00408 * @details Defines possible security status/states of a link when requested by application using 00409 * the \ref dm_security_status_req. 00410 */ 00411 typedef enum 00412 { 00413 NOT_ENCRYPTED, /**< The link is not secured. */ 00414 ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/ 00415 ENCRYPTED /**< The link is secure.*/ 00416 } dm_security_status_t; 00417 /** @} */ 00418 00419 /** 00420 * @defgroup dm_api Device Module APIs 00421 * 00422 * @brief This section describes APIs exposed by the module. 00423 * 00424 * @details This section describes APIs exposed by the module. The APIs have been categorized to provide 00425 * better and specific look up for developers. Categories are: 00426 * - Set up APIs. 00427 * - Context Management APIs. 00428 * - Utility APIs. 00429 * 00430 * MSCs describe usage of these APIs. 00431 * See @ref dm_msc. 00432 * @{ 00433 */ 00434 /** 00435 * @defgroup dm_setup_api Device Module Set-up APIs 00436 * 00437 * @brief Initialization & registration APIs that are pre-requisite for all other module procedures. 00438 * @details This section describes the Module Initialization and Registration APIs needed to be set up by 00439 * the application before device manager can start managing devices and device contexts 00440 * for the application. 00441 * 00442 * @{ 00443 */ 00444 00445 /** 00446 * @brief Module Initialization Routine. 00447 * 00448 * @details Function for initializing the module. Must called before any other APIs of the module are used. 00449 * 00450 * @param[in] p_init_param Initialization parameters. 00451 * 00452 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00453 * 00454 * @note It is mandatory that pstorage is initialized before initializing this module. 00455 */ 00456 ret_code_t dm_init(dm_init_param_t const * p_init_param); 00457 00458 /** 00459 * @brief Function for registering the application. 00460 * 00461 * @details This routine is used by the application to register for asynchronous events with the 00462 * device manager. During registration the application also indicates the services that it 00463 * intends to support on this instance. It is possible to register multiple times with the 00464 * device manager. At least one instance shall be registered with the device manager after 00465 * the module has been initialized. 00466 * Maximum number of application instances device manager can support is determined 00467 * by DM_MAX_APPLICATIONS. 00468 * 00469 * All applications must be registered before initiating or accepting connections from the peer. 00470 * 00471 * @param[in] p_appl_param Application parameters. 00472 * @param[out] p_appl_instance Application Instance Identifier in case registration is successful. 00473 * 00474 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00475 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization. 00476 * @retval NRF_ERROR_NO_MEM If module cannot support more applications. 00477 * 00478 * @note Currently only one application instance is supported by the module. 00479 */ 00480 ret_code_t dm_register(dm_application_instance_t * p_appl_instance, 00481 dm_application_param_t const * p_appl_param); 00482 00483 /** 00484 * @brief Function for handling BLE events. 00485 * 00486 * @details BLE Event Handler for the module. This routine should be called from BLE stack event 00487 * dispatcher for the module to work as expected. 00488 * 00489 * @param[in] p_ble_evt BLE stack event being dispatched to the function. 00490 * 00491 */ 00492 void dm_ble_evt_handler(ble_evt_t * p_ble_evt); 00493 00494 /** @} */ 00495 00496 00497 /** 00498 * @defgroup dm_security_api APIs to set up or read status of security on a link. 00499 * 00500 * @brief This section describes APIs to set up Security. These APIs require that the peer is 00501 * connected before the procedures can be requested. 00502 * 00503 * @details This group allows application to request security procedures 00504 * or get the status of the security on a link. 00505 * @{ 00506 */ 00507 /** 00508 * @brief Function for requesting setting up security on a link. 00509 * 00510 * @details This API initiates security procedures with a peer device. 00511 * @note For the GAP Central role, in case peer is not bonded, request to bond/pair is 00512 * initiated. If it is bonded, the link is re-encrypted using the existing bond information. 00513 * For the GAP peripheral role, a Slave security request is sent. 00514 * @details If a pairing procedure is initiated successfully, application is notified of 00515 * @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event. 00516 * In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is 00517 * notified to the application. 00518 * 00519 * @param[in] p_handle Identifies the link on which security is desired. 00520 * 00521 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00522 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00523 * application registration. 00524 * @retval NRF_ERROR_NULL If p_handle is NULL. 00525 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application 00526 * or if the peer is not connected when this procedure is requested. 00527 */ 00528 ret_code_t dm_security_setup_req(dm_handle_t * p_handle); 00529 00530 /** 00531 * @brief Function for reading the status of the security on a link. 00532 * 00533 * @details This API allows application to query status of security on a link. 00534 * 00535 * @param[in] p_handle Identifies the link on which security is desired. 00536 * @param[out] p_status Pointer where security status is provided to the application. 00537 * See \ref dm_security_status_t for possible statuses that can be expected. 00538 * 00539 * @retval NRF_SUCCESS Or appropriate error code indicating reason for failure. 00540 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00541 * application registration. 00542 * @retval NRF_ERROR_NULL If p_handle or p_status is NULL. 00543 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application 00544 * or if peer is not connected when this procedure is requested. 00545 */ 00546 ret_code_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status); 00547 00548 /** 00549 * @brief Function for creating the whitelist. 00550 * 00551 * @details This API allows application to create whitelist based on bonded peer devices in module 00552 * data base. 00553 * 00554 * @param[in] p_handle Identifies the application requesting whitelist creation. 00555 * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application. 00556 * 00557 * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum 00558 * number of devices that the application wishes to request in the whitelist. 00559 * If the number of bonded devices is less than requested, the fields are updated with that number of devices. 00560 * If the number of devices are more than requested, the module will populate the list 00561 * with devices in the order the bond was established with the peer devices. Also, if this routine is 00562 * called when a connection exists with one or more peer devices, 00563 * those connected devices are not added to the whitelist. 00564 * 00565 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00566 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00567 * application registration. 00568 * @retval NRF_ERROR_NULL If p_handle or p_whitelist is NULL. 00569 */ 00570 ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle, 00571 ble_gap_whitelist_t * p_whitelist); 00572 00573 /** @} */ 00574 00575 00576 /** 00577 * @defgroup dm_cntxt_mgmt_api Context Management APIs 00578 * 00579 * @brief Utility APIs offered by the device manager to get information about the peer if and 00580 * when needed. 00581 * 00582 * @details This group of API allow the application to access information that is not required to be 00583 * maintained by the application but may be needed. Hence it is possible to get the 00584 * information from the module instead of mapping all the information with a device 00585 * context. 00586 * @{ 00587 */ 00588 00589 ret_code_t dm_device_add(dm_handle_t * p_handle, 00590 dm_device_context_t const * p_context); 00591 00592 /** 00593 * @brief Function for deleting a peer device context and all related information from the database. 00594 * 00595 * @details Delete peer device context and all related information from database. If 00596 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the 00597 * application. Event result notified along with the event indicates success or failure 00598 * of this procedure. 00599 * 00600 * @param[in] p_handle Identifies the peer device to be deleted. 00601 * 00602 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00603 * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or 00604 * application registration. 00605 * @retval NRF_ERROR_NULL If p_handle is NULL. 00606 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00607 * 00608 * @note Deleting device context results in deleting service and application context for the 00609 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and 00610 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. 00611 */ 00612 ret_code_t dm_device_delete(dm_handle_t const * p_handle); 00613 00614 /** 00615 * @brief Function for deleting all peer device context and all related information from the database. 00616 * 00617 * @details Delete peer device context and all related information from database. If 00618 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the 00619 * application for each device that is deleted from the data base. Event result 00620 * notified along with the event indicates success or failure of this procedure. 00621 * 00622 * @param[in] p_handle Identifies application instance that is requesting 00623 * the deletion of all bonded devices. 00624 * 00625 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00626 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00627 * application registration. 00628 * @retval NRF_ERROR_NULL If p_handle is NULL. 00629 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00630 * 00631 * @note Deleting device context results in deleting both service and application context for the 00632 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and 00633 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. 00634 */ 00635 ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle); 00636 00637 /** 00638 * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter. 00639 * 00640 * @details This API allows application to Set Service Context for a peer device identified by the 00641 * 'p_handle' parameter. This API is useful when the Service Context cannot be requested 00642 * from the SoftDevice, but needs to be assembled by the application or an another module. 00643 * (or when service context is exchanged in an out of band way.) 00644 * This API could also be used to trigger a storing of service context into persistent 00645 * memory. If this is desired, a NULL pointer could be passed to the p_context. 00646 * 00647 * @param[in] p_handle Identifies peer device for which the procedure is requested. 00648 * @param[in] p_context Service context being set. The context information includes length of 00649 * data and pointer to the contextual data being set. The memory pointed to by 00650 * the pointer to data is assumed to be resident when API is being called and 00651 * can be freed or reused once the set procedure is complete. Set procedure 00652 * completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED. 00653 * The Event result is notified along with the event and indicates success or failure of 00654 * this procedure. 00655 * 00656 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00657 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00658 * application registration. 00659 * @retval NRF_ERROR_NULL If p_handle is NULL. 00660 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00661 */ 00662 ret_code_t dm_service_context_set(dm_handle_t const * p_handle, 00663 dm_service_context_t const * p_context); 00664 00665 /** 00666 * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter. 00667 * 00668 * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If 00669 * this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the 00670 * application. The event result is notified along with the event indicates success or failure 00671 * of this procedure. 00672 * 00673 * @param[in] p_handle Identifies peer device for which procedure is requested. 00674 * @param[in] p_context Application context being requested. The context information includes length 00675 * of the data and a pointer to the data. Note that requesting a 'get' 00676 * of application does not need to provide memory, the pointer to data will be 00677 * pointing to service data and hence no data movement is involved. 00678 * 00679 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00680 * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or 00681 * application registration. 00682 * @retval NRF_ERROR_NULL If p_handle is NULL. 00683 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00684 */ 00685 ret_code_t dm_service_context_get(dm_handle_t const * p_handle, 00686 dm_service_context_t * p_context); 00687 00688 /** 00689 * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter. 00690 * 00691 * @details This API allows application to delete a Service Context identified for a peer device 00692 * identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS, 00693 * DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application. 00694 * Event result is notified along with the event and indicates success or failure of this 00695 * procedure. 00696 * 00697 * @param[in] p_handle Identifies peer device for which procedure is requested. 00698 * 00699 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00700 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00701 * application registration. 00702 * @retval NRF_ERROR_NULL If p_handle is NULL. 00703 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00704 */ 00705 ret_code_t dm_service_context_delete(dm_handle_t const * p_handle); 00706 00707 /** 00708 * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter. 00709 * 00710 * @details This application allows the setting of the application context for the peer device identified by 00711 * the 'p_handle'. Application context is stored persistently by the module and can be 00712 * requested by the application at any time using the \ref dm_application_context_get 00713 * API. Note that this procedure is permitted only for bonded devices. If the 00714 * device is not bonded, application context cannot be set. However, it is not mandatory 00715 * that the bonded device is connected when requesting this procedure. 00716 * 00717 * @param[in] p_handle Identifies peer device for which procedure is requested. 00718 * 00719 * @param[in] p_context Application context being set. The context information includes length of the 00720 * data and pointer to the contextual data being set. The memory pointed to by 00721 * the data pointer is assumed to be resident when API is being called and 00722 * can be freed or reused once the set procedure is complete. Set procedure 00723 * completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED. 00724 * The event result is notified along with the event and indicates success or 00725 * failure of this procedure. 00726 * 00727 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00728 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00729 * application registration. 00730 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. 00731 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00732 * 00733 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. 00734 */ 00735 ret_code_t dm_application_context_set(dm_handle_t const * p_handle, 00736 dm_application_context_t const * p_context); 00737 00738 /** 00739 * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter. 00740 * 00741 * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If 00742 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the 00743 * application. Event result notified along with the event indicates success or failure 00744 * of this procedure. 00745 * 00746 * @param[in] p_handle Identifies peer device for which procedure is requested. 00747 * @param[in] p_context Application context being requested. The context information includes 00748 * length of data and pointer to the contextual data is provided. 00749 * 00750 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00751 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00752 * application registration. 00753 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. 00754 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00755 * @retval DM_NO_APP_CONTEXT If no application context was set that can be fetched. 00756 * 00757 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to 00758 * zero. 00759 */ 00760 ret_code_t dm_application_context_get(dm_handle_t const * p_handle, 00761 dm_application_context_t * p_context); 00762 00763 /** 00764 * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter. 00765 * 00766 * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If 00767 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the 00768 * application. The event result notified along with the event and indicates success or failure 00769 * of this procedure. 00770 * 00771 * @param[in] p_handle Identifies peer device for which procedure is requested. 00772 * 00773 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00774 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00775 * application registration. 00776 * @retval NRF_ERROR_NULL If the p_handle is NULL. 00777 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00778 * @retval DM_NO_APP_CONTEXT If no application context was set that can be deleted. 00779 * 00780 * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. 00781 */ 00782 ret_code_t dm_application_context_delete(dm_handle_t const * p_handle); 00783 00784 /** @} */ 00785 00786 00787 /** 00788 * @defgroup utility_api Utility APIs 00789 * @{ 00790 * @brief This section describes the utility APIs offered by the module. 00791 * 00792 * @details APIs defined in this section are utility or assisting/helper APIs. 00793 */ 00794 /** 00795 * @brief Function for Setting/Copying Application instance to Device Manager handle. 00796 * 00797 * @param[in] p_appl_instance Application instance to be set. 00798 * @param[out] p_handle Device Manager handle for which the instance is to be copied. 00799 * 00800 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00801 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00802 * application registration. 00803 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00804 */ 00805 ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, 00806 dm_handle_t * p_handle); 00807 00808 /** 00809 * @brief Function for getting a peer's device address. 00810 * 00811 * @param[in] p_handle Identifies the peer device whose address is requested. Can not be NULL. 00812 * @param[out] p_addr Pointer where address is to be copied. Can not be NULL. 00813 * 00814 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00815 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00816 * application registration. 00817 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00818 * @retval NRF_ERROR_NOT_FOUND If the peer could not be identified. 00819 */ 00820 ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle, 00821 ble_gap_addr_t * p_addr); 00822 00823 /** 00824 * @brief Function for setting/updating a peer's device address. 00825 * 00826 * @param[in] p_handle Identifies the peer device whose address is requested to be set/updated. 00827 * @param[out] p_addr Address to be set/updated. 00828 * 00829 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00830 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00831 * application registration. 00832 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00833 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00834 * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address 00835 * type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. 00836 * 00837 * @note Setting or updating a peer's device address is permitted 00838 * only for a peer that is bonded and disconnected. 00839 * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the 00840 * application for this bonded device instance. In order to avoid abnormal behaviour, it is 00841 * recommended to not invite/initiate connections on the updated address unless this event 00842 * has been notified. 00843 */ 00844 ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle, 00845 ble_gap_addr_t const * p_addr); 00846 00847 /** 00848 * @brief Function for initializing Device Manager handle. 00849 * 00850 * @param[in] p_handle Device Manager handle to be initialized. 00851 * 00852 * @retval NRF_SUCCESS On success. 00853 * @retval NRF_ERROR_NULL If p_handle is NULL. 00854 * 00855 * @note This routine is permitted before initialization of the module. 00856 */ 00857 ret_code_t dm_handle_initialize(dm_handle_t * p_handle); 00858 00859 /** 00860 * @brief Function for getting distributed keys for a device. 00861 * 00862 * @param[in] p_handle Device Manager handle identifying the peer. 00863 * @param[out] p_key_dist Pointer to distributed keys. 00864 * 00865 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00866 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00867 * application registration. 00868 * @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL. 00869 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00870 */ 00871 ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, 00872 dm_sec_keyset_t * p_key_dist); 00873 00874 /** 00875 * @brief Function for getting the corresponding dm_handle_t based on the connection handle. 00876 * 00877 * @param[in] conn_handle Connection handle as provided by the SoftDevice. 00878 * @param[in,out] p_handle Pointer to the p_handle containg the application instance for the 00879 * registered application. If the application instance is valid then 00880 * the p_handle will be filled with requested data. 00881 * 00882 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00883 * @retval NRF_ERROR_NULL If the p_handle pointer is NULL. 00884 * @retval NRF_ERROR_NOT_FOUND If no p_handle is found for the provided connection handle. 00885 */ 00886 ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle); 00887 00888 #ifdef __cplusplus 00889 } 00890 #endif 00891 00892 /** @} */ 00893 /** @} */ 00894 /** @} */ 00895 #endif // DEVICE_MANAGER_H__ 00896
Generated on Tue Jul 12 2022 19:22:46 by
1.7.2
