Wallbot_CaaS
Dependencies: MPU6050 mbed PID
Fork of BLE_MPU6050_test6_challenge_sb 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 /** 00235 * @brief Device Handle used for unique identification of each peer. 00236 * 00237 * @details This data type is used to uniquely identify each peer device. A peer device could be 00238 * active and/or bonded. Therefore an instance for active and bonded is provided. 00239 * However, the application is expected to treat this is an opaque structure and use this for 00240 * all API interactions once stored on appropriate events. 00241 * See \ref dm_events. 00242 */ 00243 typedef struct device_handle 00244 { 00245 dm_application_instance_t appl_id; /**< Identifies the application instances for the device that is being managed. */ 00246 dm_connection_instance_t connection_id; /**< Identifies the active connection instance. */ 00247 dm_device_instance_t device_id; /**< Identifies peer instance in the data base. */ 00248 dm_service_instance_t service_id; /**< Service instance identifier. */ 00249 } dm_handle_t; 00250 00251 /** 00252 * @brief Definition of Data Context. 00253 * 00254 * @details Defines contextual data format, it consists of context data length and pointer to data. 00255 */ 00256 typedef struct 00257 { 00258 uint32_t len; /**< Length of data . */ 00259 uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */ 00260 } dm_context_t; 00261 00262 00263 /** 00264 * @brief Device Context. 00265 * 00266 * @details Defines "device context" type for a device managed by device manager. 00267 */ 00268 typedef dm_context_t dm_device_context_t; 00269 00270 /** 00271 * @brief Service Context. 00272 * 00273 * @details Service context data for a service identified by the 'service_type' field. 00274 */ 00275 typedef struct 00276 { 00277 service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */ 00278 dm_context_t context_data; /**< Contains length and pointer to context data */ 00279 } dm_service_context_t; 00280 00281 /** 00282 * @brief Application context. 00283 * 00284 * @details The application context can be used by the application to map any application level 00285 * information that is to be mapped with a particular peer. 00286 * For bonded peers, this information will be stored by the bond manager persistently. 00287 * Note that the device manager treats this information as an 00288 * opaque block of bytes. 00289 * Necessary APIs to get and set this context for a peer have been provided. 00290 */ 00291 typedef dm_context_t dm_application_context_t; 00292 00293 /** 00294 * @brief Event parameters. 00295 * 00296 * @details Defines event parameters for each of the events notified by the module. 00297 */ 00298 typedef union 00299 { 00300 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. */ 00301 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. */ 00302 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. */ 00303 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. */ 00304 } dm_event_param_t; 00305 00306 /** 00307 * @brief Asynchronous events details notified to the application by the module. 00308 * 00309 * @details Defines event type along with event parameters notified to the application by the 00310 * module. 00311 */ 00312 typedef struct 00313 { 00314 uint8_t event_id; /**< Identifies the event. See \ref dm_events for details on event types and their significance. */ 00315 dm_event_param_t event_param; /**< Event parameters. Can be NULL if the event does not have any parameters. */ 00316 uint16_t event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */ 00317 } dm_event_t; 00318 00319 /** 00320 * @brief Event notification callback registered by application with the module. 00321 * 00322 * @details Event notification callback registered by application with the module when registering 00323 * the module using \ref dm_register API. 00324 * 00325 * @param[in] p_handle Identifies the peer for which the event is being notified. 00326 * @param[in] p_event Identifies the event, any associated parameters and parameter length. 00327 * See \ref dm_events for details on event types and their significance. 00328 * @param[in,out] event_result Provide additional information on the event. 00329 * In addition to SDK error codes there is also a return value 00330 * indicating if maximum number of connections has been reached when connecting or bonding. 00331 * 00332 * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event 00333 * successfully. There is no action taken in case application returns a failure. 00334 */ 00335 typedef api_result_t (*dm_event_cb_t)(dm_handle_t const * p_handle, 00336 dm_event_t const * p_event, 00337 api_result_t event_result); 00338 00339 /** 00340 * @brief Initialization Parameters. 00341 * 00342 * @details Indicates the application parameters. Currently this only encompasses clearing 00343 * all persistent data. 00344 */ 00345 typedef struct 00346 { 00347 bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */ 00348 } dm_init_param_t; 00349 00350 /** 00351 * @brief Application Registration Parameters. 00352 * 00353 * @details Parameters needed by the module when registering with it. 00354 */ 00355 typedef struct 00356 { 00357 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. */ 00358 uint8_t service_type; /**< Bit mask identifying services that the application intends to support for all peers. */ 00359 ble_gap_sec_params_t sec_param; /**< Security parameters to be used for the application. */ 00360 } dm_application_param_t; 00361 00362 /** 00363 * @brief Defines possible security status/states. 00364 * 00365 * @details Defines possible security status/states of a link when requested by application using 00366 * the \ref dm_security_status_req. 00367 */ 00368 typedef enum 00369 { 00370 NOT_ENCRYPTED, /**< The link does not security. */ 00371 ENCRYPTION_IN_PROGRESS, /**< Security is in progress of being established.*/ 00372 ENCRYPTED /**< The link is secure.*/ 00373 } dm_security_status_t; 00374 /** @} */ 00375 00376 /** 00377 * @defgroup dm_api Device Module APIs 00378 * 00379 * @brief This section describes APIs exposed by the module. 00380 * 00381 * @details This section describes APIs exposed by the module. The APIs have been categorized to provide 00382 * better and specific look up for developers. Categories are: 00383 * a. Set up APIs. 00384 * b. Context Management APIs. 00385 * c. Utility APIs. 00386 * 00387 * MSCs describe usage of these APIs. See @mscfile dm_api.dox 00388 * @{ 00389 */ 00390 /** 00391 * @defgroup dm_setup_api Device Module Set-up APIs 00392 * 00393 * @brief Initialization & registration APIs that are pre-requisite for all other module procedures. 00394 * @details This section describes the Module Initialization and Registration APIs needed to be set up by 00395 * the application before device manager can start managing devices and device contexts 00396 * for the application. 00397 * 00398 * @{ 00399 */ 00400 00401 /** 00402 * @brief Module Initialization Routine. 00403 * 00404 * @details Function for initializing the module. Must called before any other APIs of the module are used. 00405 * 00406 * @param[in] p_init_param Initialization parameters. 00407 * 00408 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00409 * 00410 * @note It is mandatory that pstorage is initialized before initializing this module. 00411 */ 00412 api_result_t dm_init(dm_init_param_t const * p_init_param); 00413 00414 /** 00415 * @brief Function for registering the application. 00416 * 00417 * @details This routine is used by the application to register for asynchronous events with the 00418 * device manager. During registration the application also indicates the services that it 00419 * intends to support on this instance. It is possible to register multiple times with the 00420 * device manager. At least one instance shall be registered with the device manager after 00421 * the module has been initialized. 00422 * Maximum number of application instances device manager can support is determined 00423 * by DM_MAX_APPLICATIONS. 00424 * 00425 * All applications must be registered before initiating or accepting connections from the peer. 00426 * 00427 * @param[in] p_appl_param Application parameters. 00428 * @param[out] p_appl_instance Application Instance Identifier in case registration is successful. 00429 * 00430 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00431 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization. 00432 * @retval NRF_ERROR_NO_MEM If module cannot support more applications. 00433 * 00434 * @note Currently only one application instance is supported by the module. 00435 */ 00436 api_result_t dm_register(dm_application_instance_t * p_appl_instance, 00437 dm_application_param_t const * p_appl_param); 00438 00439 /** 00440 * @brief Function for handling BLE events. 00441 * 00442 * @details BLE Event Handler for the module. This routine should be called from BLE stack event 00443 * dispatcher for the module to work as expected. 00444 * 00445 * @param[in] p_ble_evt BLE stack event being dispatched to the function. 00446 * 00447 */ 00448 void dm_ble_evt_handler(ble_evt_t * p_ble_evt); 00449 00450 /** @} */ 00451 00452 00453 /** 00454 * @defgroup dm_security_api APIs to set up or read status of security on a link. 00455 * 00456 * @brief This section describes APIs to set up Security. These APIs require that the peer is 00457 * connected before the procedures can be requested. 00458 * 00459 * @details This group allows application to request security procedures 00460 * or get the status of the security on a link. 00461 * @{ 00462 */ 00463 /** 00464 * @brief Function for requesting setting up security on a link. 00465 * 00466 * @details This API initiates security procedures with a peer device. 00467 * @note For the GAP Central role, in case peer is not bonded, request to bond/pair is 00468 * initiated. If it is bonded, the link is re-encrypted using the existing bond information. 00469 * For the GAP peripheral role, a Slave security request is sent. 00470 * @details If a pairing procedure is initiated successfully, application is notified of 00471 * @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event. 00472 * In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is 00473 * notified to the application. 00474 * 00475 * @param[in] p_handle Identifies the link on which security is desired. 00476 * 00477 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00478 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00479 * application registration. 00480 * @retval NRF_ERROR_NULL If p_handle is NULL. 00481 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application 00482 * or if the peer is not connected when this procedure is requested. 00483 */ 00484 api_result_t dm_security_setup_req(dm_handle_t * p_handle); 00485 00486 /** 00487 * @brief Function for reading the status of the security on a link. 00488 * 00489 * @details This API allows application to query status of security on a link. 00490 * 00491 * @param[in] p_handle Identifies the link on which security is desired. 00492 * @param[out] p_status Pointer where security status is provided to the application. 00493 * See \ref dm_security_status_t for possible statuses that can be expected. 00494 * 00495 * @retval NRF_SUCCESS Or appropriate error code indicating reason for failure. 00496 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00497 * application registration. 00498 * @retval NRF_ERROR_NULL If p_handle or p_status is NULL. 00499 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application 00500 * or if peer is not connected when this procedure is requested. 00501 */ 00502 api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status); 00503 00504 /** 00505 * @brief Function for creating the whitelist. 00506 * 00507 * @details This API allows application to create whitelist based on bonded peer devices in module 00508 * data base. 00509 * 00510 * @param[in] p_handle Identifies the application requesting whitelist creation. 00511 * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application. 00512 * 00513 * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum 00514 * number of devices that the application wishes to request in the whitelist. 00515 * If the number of bonded devices is less than requested, the fields are updated with that number of devices. 00516 * If the number of devices are more than requested, the module will populate the list 00517 * with devices in the order the bond was established with the peer devices. Also, if this routine is 00518 * called when a connection exists with one or more peer devices, 00519 * those connected devices are not added to the whitelist. 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 or p_whitelist is NULL. 00525 */ 00526 api_result_t dm_whitelist_create(dm_application_instance_t const * p_handle, 00527 ble_gap_whitelist_t * p_whitelist); 00528 00529 /** @} */ 00530 00531 00532 /** 00533 * @defgroup dm_cntxt_mgmt_api Context Management APIs 00534 * 00535 * @brief Utility APIs offered by the device manager to get information about the peer if and 00536 * when needed. 00537 * 00538 * @details This group of API allow the application to access information that is not required to be 00539 * maintained by the application but may be needed. Hence it is possible to get the 00540 * information from the module instead of mapping all the information with a device 00541 * context. 00542 * @{ 00543 */ 00544 00545 api_result_t dm_device_add(dm_handle_t * p_handle, 00546 dm_device_context_t const * p_context); 00547 00548 /** 00549 * @brief Function for deleting a peer device context and all related information from the database. 00550 * 00551 * @details Delete peer device context and all related information from database. If 00552 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the 00553 * application. Event result notified along with the event indicates success or failure 00554 * of this procedure. 00555 * 00556 * @param[in] p_handle Identifies the peer device to be deleted. 00557 * 00558 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00559 * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or 00560 * application registration. 00561 * @retval NRF_ERROR_NULL If p_handle is NULL. 00562 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00563 * 00564 * @note Deleting device context results in deleting service and application context for the 00565 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and 00566 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. 00567 */ 00568 api_result_t dm_device_delete(dm_handle_t const * p_handle); 00569 00570 /** 00571 * @brief Function for deleting all peer device context and all related information from the database. 00572 * 00573 * @details Delete peer device context and all related information from database. If 00574 * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the 00575 * application for each device that is deleted from the data base. Event result 00576 * notified along with the event indicates success or failure of this procedure. 00577 * 00578 * @param[in] p_handle Identifies application instance that is requesting 00579 * the deletion of all bonded devices. 00580 * 00581 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00582 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00583 * application registration. 00584 * @retval NRF_ERROR_NULL If p_handle is NULL. 00585 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00586 * 00587 * @note Deleting device context results in deleting both service and application context for the 00588 * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and 00589 * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. 00590 */ 00591 api_result_t dm_device_delete_all(dm_application_instance_t const * p_handle); 00592 00593 /** 00594 * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter. 00595 * 00596 * @details This API allows application to Set Service Context for a peer device identified by the 00597 * 'p_handle' parameter. This API is useful when the Service Context cannot be requested 00598 * from the SoftDevice, but needs to be assembled by the application or an another module. 00599 * (or when service context is exchanged in an out of band way.) 00600 * This API could also be used to trigger a storing of service context into persistent 00601 * memory. If this is desired, a NULL pointer could be passed to the p_context. 00602 * 00603 * @param[in] p_handle Identifies peer device for which the procedure is requested. 00604 * @param[in] p_context Service context being set. The context information includes length of 00605 * data and pointer to the contextual data being set. The memory pointed to by 00606 * the pointer to data is assumed to be resident when API is being called and 00607 * can be freed or reused once the set procedure is complete. Set procedure 00608 * completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED. 00609 * The Event result is notified along with the event and indicates success or failure of 00610 * this procedure. 00611 * 00612 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00613 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00614 * application registration. 00615 * @retval NRF_ERROR_NULL If p_handle is NULL. 00616 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00617 */ 00618 api_result_t dm_service_context_set(dm_handle_t const * p_handle, 00619 dm_service_context_t const * p_context); 00620 00621 /** 00622 * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter. 00623 * 00624 * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If 00625 * this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the 00626 * application. The event result is notified along with the event indicates success or failure 00627 * of this procedure. 00628 * 00629 * @param[in] p_handle Identifies peer device for which procedure is requested. 00630 * @param[in] p_context Application context being requested. The context information includes length 00631 * of the data and a pointer to the data. Note that requesting a 'get' 00632 * of application does not need to provide memory, the pointer to data will be 00633 * pointing to service data and hence no data movement is involved. 00634 * 00635 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00636 * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or 00637 * application registration. 00638 * @retval NRF_ERROR_NULL If p_handle is NULL. 00639 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00640 */ 00641 api_result_t dm_service_context_get(dm_handle_t const * p_handle, 00642 dm_service_context_t * p_context); 00643 00644 /** 00645 * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter. 00646 * 00647 * @details This API allows application to delete a Service Context identified for a peer device 00648 * identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS, 00649 * DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application. 00650 * Event result is notified along with the event and indicates success or failure of this 00651 * procedure. 00652 * 00653 * @param[in] p_handle Identifies peer device for which procedure is requested. 00654 * 00655 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00656 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00657 * application registration. 00658 * @retval NRF_ERROR_NULL If p_handle is NULL. 00659 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00660 */ 00661 api_result_t dm_service_context_delete(dm_handle_t const * p_handle); 00662 00663 /** 00664 * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter. 00665 * 00666 * @details This application allows the setting of the application context for the peer device identified by 00667 * the 'p_handle'. Application context is stored persistently by the module and can be 00668 * requested by the application at any time using the \ref dm_application_context_get 00669 * API. Note that this procedure is permitted only for bonded devices. If the 00670 * device is not bonded, application context cannot be set. However, it is not mandatory 00671 * that the bonded device is connected when requesting this procedure. 00672 * 00673 * @param[in] p_handle Identifies peer device for which procedure is requested. 00674 * 00675 * @param[in] p_context Application context being set. The context information includes length of the 00676 * data and pointer to the contextual data being set. The memory pointed to by 00677 * the data pointer is assumed to be resident when API is being called and 00678 * can be freed or reused once the set procedure is complete. Set procedure 00679 * completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED. 00680 * The event result is notified along with the event and indicates success or 00681 * failure of this procedure. 00682 * 00683 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00684 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00685 * application registration. 00686 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. 00687 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00688 * 00689 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. 00690 */ 00691 api_result_t dm_application_context_set(dm_handle_t const * p_handle, 00692 dm_application_context_t const * p_context); 00693 00694 /** 00695 * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter. 00696 * 00697 * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If 00698 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the 00699 * application. Event result notified along with the event indicates success or failure 00700 * of this procedure. 00701 * 00702 * @param[in] p_handle Identifies peer device for which procedure is requested. 00703 * @param[in] p_context Application context being requested. The context information includes 00704 * length of data and pointer to the contextual data is provided. 00705 * 00706 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00707 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00708 * application registration. 00709 * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. 00710 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00711 * @retval DM_NO_APP_CONTEXT If no application context was set that can be fetched. 00712 * 00713 * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to 00714 * zero. 00715 */ 00716 api_result_t dm_application_context_get(dm_handle_t const * p_handle, 00717 dm_application_context_t * p_context); 00718 00719 /** 00720 * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter. 00721 * 00722 * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If 00723 * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the 00724 * application. The event result notified along with the event and indicates success or failure 00725 * of this procedure. 00726 * 00727 * @param[in] p_handle Identifies peer device for which procedure is requested. 00728 * 00729 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00730 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00731 * application registration. 00732 * @retval NRF_ERROR_NULL If the p_handle is NULL. 00733 * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. 00734 * @retval DM_NO_APP_CONTEXT If no application context was set that can be deleted. 00735 * 00736 * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. 00737 */ 00738 api_result_t dm_application_context_delete(dm_handle_t const * p_handle); 00739 00740 /** @} */ 00741 00742 00743 /** 00744 * @defgroup utility_api Utility APIs 00745 * @{ 00746 * @brief This section describes the utility APIs offered by the module. 00747 * 00748 * @details APIs defined in this section are utility or assisting/helper APIs. 00749 */ 00750 /** 00751 * @brief Function for Setting/Copying Application instance to Device Manager handle. 00752 * 00753 * @param[in] p_appl_instance Application instance to be set. 00754 * @param[out] p_handle Device Manager handle for which the instance is to be copied. 00755 * 00756 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00757 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00758 * application registration. 00759 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00760 */ 00761 api_result_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, 00762 dm_handle_t * p_handle); 00763 00764 /** 00765 * @brief Function for getting a peer's device address. 00766 * 00767 * @param[in] p_handle Identifies the peer device whose address is requested. Can not be NULL. 00768 * @param[out] p_addr Pointer where address is to be copied. Can not be NULL. 00769 * 00770 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00771 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00772 * application registration. 00773 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00774 * @retval NRF_ERROR_NOT_FOUND If the peer could not be identified. 00775 */ 00776 api_result_t dm_peer_addr_get(dm_handle_t const * p_handle, 00777 ble_gap_addr_t * p_addr); 00778 00779 /** 00780 * @brief Function for setting/updating a peer's device address. 00781 * 00782 * @param[in] p_handle Identifies the peer device whose address is requested to be set/updated. 00783 * @param[out] p_addr Address to be set/updated. 00784 * 00785 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00786 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00787 * application registration. 00788 * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. 00789 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00790 * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address 00791 * type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. 00792 * 00793 * @note Setting or updating a peer's device address is permitted 00794 * only for a peer that is bonded and disconnected. 00795 * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the 00796 * application for this bonded device instance. In order to avoid abnormal behaviour, it is 00797 * recommended to not invite/initiate connections on the updated address unless this event 00798 * has been notified. 00799 */ 00800 api_result_t dm_peer_addr_set(dm_handle_t const * p_handle, 00801 ble_gap_addr_t const * p_addr); 00802 00803 /** 00804 * @brief Function for initializing Device Manager handle. 00805 * 00806 * @param[in] p_handle Device Manager handle to be initialized. 00807 * 00808 * @retval NRF_SUCCESS On success. 00809 * @retval NRF_ERROR_NULL If p_handle is NULL. 00810 * 00811 * @note This routine is permitted before initialization of the module. 00812 */ 00813 api_result_t dm_handle_initialize(dm_handle_t * p_handle); 00814 00815 #ifdef GAP_CENTRAL 00816 /** 00817 * @brief Function for getting distributed keys for a device. 00818 * 00819 * @details This routine is used to get distributed keys with a bonded device. This API is currently 00820 * only available on S120 (GAP Central role). 00821 * 00822 * @param[in] p_handle Device Manager handle identifying the peer. 00823 * 00824 * @param[out] p_key_dist Pointer to distributed keys. 00825 * 00826 * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. 00827 * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or 00828 * application registration. 00829 * @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL. 00830 * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. 00831 */ 00832 api_result_t dm_distributed_keys_get(dm_handle_t const * p_handle, 00833 ble_gap_sec_keyset_t * p_key_dist); 00834 #endif // GAP_CENTRAL 00835 /** @} */ 00836 /** @} */ 00837 /** @} */ 00838 #endif // DEVICE_MANAGER_H__ 00839
Generated on Tue Jul 12 2022 18:33:09 by 1.7.2