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