bms.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file bms.h
5  *
6  * @brief Bond Management Service API.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************************
36  */
37 
38 /**
39  * @addtogroup BLE_SRV BLE Services
40  * @{
41  * @brief Definitions and prototypes for the BLE Service interface.
42  */
43 
44 /**
45  * @defgroup BLE_SDK_BMS Bond Management Service (BMS)
46  * @{
47  * @brief Bond Management Service module.
48  *
49  * @details The Bond Management Service exposes glucose and other data related to
50  * a personal Continuous Glucose Monitoring (BMS) sensor for use in consumer healthcare applications.
51  * This module implements the Bond Management Service with BMS Measurement, BMS Feature,
52  * BMS Status, BMS Session Start Time, BMS Session Run Time, Record Access Control Point and BMS Specific
53  * Ops Control Point characteristics.
54  */
55 
56 #ifndef __BMS_H__
57 #define __BMS_H__
58 
59 /*
60  * INCLUDE FILES
61  ****************************************************************************************
62  */
63 #include "gr_includes.h"
64 
65 /**
66  * @defgroup BMS_MACRO Defines
67  * @{
68  */
69 #define BMS_CONNECTION_MAX 10 /**< Maximum number of BMS connections.The value is configurable. */
70 
71 #define BMS_ERROR_OP_CODE_NOT_SUPPORTED 0x80 /**< Error code: Response if unsupported Op Code is received. */
72 #define BMS_ERROR_OPERATION_FAILED 0x81 /**< Error code: Response if unable to complete a procedure for any reason. */
73 
74 #define BMS_AUTH_CODE_LEN_MAX 12
75 
76 /**
77  * @defgroup BMS_FEAT BMS Feature
78  * @{
79  * @brief BMS feature.
80  */
81 #define BMS_FEAT_DEL_BONDS_REQ_DEV_BR_LE (0x01 << 0) /**< Delete bond of the requesting device (BR/EDR and LE). */
82 #define BMS_FEAT_DEL_BONDS_REQ_DEV_BR_LE_AUTH_CODE (0x01 << 1) /**< Delete bond of the requesting device (BR/EDR and LE) with an authorization code. */
83 #define BMS_FEAT_DEL_BONDS_REQ_DEV_BR (0x01 << 2) /**< Delete bond of the requesting device (BR/EDR transport only). */
84 #define BMS_FEAT_DEL_BONDS_REQ_DEV_BR_AUTH_CODE (0x01 << 3) /**< Delete bond of the requesting device (BR/EDR transport only) with an authorization code. */
85 #define BMS_FEAT_DEL_BONDS_REQ_DEV_LE (0x01 << 4) /**< Delete bond of the requesting device (LE transport only). */
86 #define BMS_FEAT_DEL_BONDS_REQ_DEV_LE_AUTH_CODE (0x01 << 5) /**< Delete bond of the requesting device (LE transport only) with an authorization code. */
87 #define BMS_FEAT_DEL_ALL_BONDS_BR_LE (0x01 << 6) /**< Delete all bonds on the device (BR/EDR and LE). */
88 #define BMS_FEAT_DEL_ALL_BONDS_BR_LE_AUTH_CODE (0x01 << 7) /**< Delete all bonds on the device (BR/EDR and LE) with an authorization code. */
89 #define BMS_FEAT_DEL_ALL_BONDS_BR (0x01 << 8) /**< Delete all bonds on the device (BR/EDR transport only). */
90 #define BMS_FEAT_DEL_ALL_BONDS_BR_AUTH_CODE (0x01 << 9) /**< Delete all bonds on the device (BR/EDR transport only) with an authorization code. */
91 #define BMS_FEAT_DEL_ALL_BONDS_LE (0x01 << 10) /**< Delete all bonds on the device (LE transport only). */
92 #define BMS_FEAT_DEL_ALL_BONDS_LE_AUTH_CODE (0x01 << 11) /**< Delete all bonds on the device (LE transport only) with an authorization code. */
93 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_BR_LE (0x01 << 12) /**< Delete all bonds on the device except for the bond of the requesting device (BR/EDR and LE). */
94 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_BR_LE_AUTH_CODE (0x01 << 13) /**< Delete all bonds on the device except for the bond of the requesting device (BR/EDR and LE) with an authorization code. */
95 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_BR (0x01 << 14) /**< Delete all bonds on the device except for the bond of the requesting device (BR/EDR transport only). */
96 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_BR_AUTH_CODE (0x01 << 15) /**< Delete all bonds on the device except for the bond of the requesting device (BR/EDR transport only) with an authorization code. */
97 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_LE (0x01 << 16) /**< Delete all bonds on the device except for the bond of the requesting device (LE transport only). */
98 #define BMS_FEAT_DEL_ALL_BUT_REQ_DEV_LE_AUTH_CODE (0x01 << 17) /**< Delete all bonds on the device except for the bond of the requesting device (LE transport only) with an authorization code. */
99 #define BMS_FEAT_FULL (0x3ffff) /**< All feature Supported. */
100 /** @} */
101 
102 /** @} */
103 
104 /**
105  * @defgroup BMS_ENUM Enumerations
106  * @{
107  */
108 /**@brief BMS Service CCCD status. */
109 typedef enum
110 {
111  BMS_CCCD_STATUS_FEATURE_ENABLED, /**< BMS Feature indication enabled. */
112  BMS_CCCD_STATUS_FEATURE_DISABLED, /**< BMS Feature indication disabled. */
114 
115 /**@brief Bond Management Control Point opcodes. */
116 typedef enum
117 {
118  BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_LE = 0x01, /**< Initiates the procedure to delete the bond of the requesting device on BR/EDR and LE transports. */
119  BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_ONLY = 0x02, /**< Initiates the procedure to delete the bond of the requesting device on BR/EDR transport. */
120  BMS_OP_CODE_DEL_BOND_REQ_DEVICE_LE_ONLY = 0x03, /**< Initiates the procedure to delete the bond of the requesting device on LE transport. */
121  BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_LE = 0x04, /**< Initiates the procedure to delete all bonds on the device on BR/EDR and LE transports. */
122  BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_ONLY = 0x05, /**< Initiates the procedure to delete all bonds on the device on BR/EDR transport. */
123  BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_LE_ONLY = 0x06, /**< Initiates the procedure to delete all bonds on the device on LE transport. */
124  BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_LE = 0x07, /**< Initiates the procedure to delete all bonds except for the one of the requesting device on BR/EDR and LE transports. */
125  BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_ONLY = 0x08, /**< Initiates the procedure to delete all bonds except for the one of the requesting device on BR/EDR transport. */
126  BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_LE_ONLY = 0x09, /**< Initiates the procedure to delete all bonds except for the one of the requesting device on LE transport. */
127  BMS_OP_CODE_NONE = 0xFF /**< Indicates an invalid opcode or no pending opcode. */
129 /** @} */
130 
131 /**
132  * @defgroup BMS_TYPEDEF Typedefs
133  * @{
134  */
135 /**@brief BMS Service CCCD change handler type.*/
136 typedef void (*bms_cccd_change_handler_t)(uint8_t conn_idx, bms_cccd_status_t cccd_status);
137 /** @} */
138 
139 
140 /**
141  * @defgroup BMS_STRUCT Structures
142  * @{
143  */
144 /**@brief BMS Service init stucture. This contains all option and data needed for initialization of the service. */
145 typedef struct
146 {
147 
149  uint32_t feature;
150  uint8_t auth_code_val[BMS_AUTH_CODE_LEN_MAX];
151  uint8_t auth_code_len;
152 } bms_init_t;
153 /** @} */
154 
155 /**
156  * @defgroup BMS_FUNCTION Functions
157  * @{
158  */
159 /**
160  *****************************************************************************************
161  * @brief Initialize a Bond Management Service instance and add in the DB.
162  *
163  * @param[in] p_bms_init: Pointer to Service initialization variable
164  *
165  * @return Result of service initialization.
166  *****************************************************************************************
167  */
169 
170 /**
171  *****************************************************************************************
172  * @brief Bond Management Service feature update.
173  *
174  * @param[in] feature: Feature Value
175  *
176  * @return Result of feature update.
177  *****************************************************************************************
178  */
179 sdk_err_t bms_feature_update(uint32_t feature);
180 
181 /** @} */
182 
183 #endif
184 /** @} */
185 /** @} */
186 
BMS_OP_CODE_DEL_BOND_REQ_DEVICE_LE_ONLY
@ BMS_OP_CODE_DEL_BOND_REQ_DEVICE_LE_ONLY
Definition: bms.h:120
BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_ONLY
@ BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_ONLY
Definition: bms.h:119
bms_cccd_status_t
bms_cccd_status_t
BMS Service CCCD status.
Definition: bms.h:110
BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_ONLY
@ BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_ONLY
Definition: bms.h:122
gr_includes.h
Include Files API.
bms_feature_update
sdk_err_t bms_feature_update(uint32_t feature)
Bond Management Service feature update.
bms_cccd_change_handler_t
void(* bms_cccd_change_handler_t)(uint8_t conn_idx, bms_cccd_status_t cccd_status)
BMS Service CCCD change handler type.
Definition: bms.h:136
BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_LE
@ BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_BR_LE
Definition: bms.h:121
BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_LE
@ BMS_OP_CODE_DEL_BOND_REQ_DEVICE_BR_LE
Definition: bms.h:118
bms_init_t::auth_code_len
uint8_t auth_code_len
Definition: bms.h:151
bms_service_init
sdk_err_t bms_service_init(bms_init_t *p_bms_init)
Initialize a Bond Management Service instance and add in the DB.
BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_ONLY
@ BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_ONLY
Definition: bms.h:125
BMS_CCCD_STATUS_FEATURE_ENABLED
@ BMS_CCCD_STATUS_FEATURE_ENABLED
Definition: bms.h:111
BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_LE
@ BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_BR_LE
Definition: bms.h:124
BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_LE_ONLY
@ BMS_OP_CODE_DEL_ALL_BONDS_ON_SERVER_LE_ONLY
Definition: bms.h:123
BMS_OP_CODE_NONE
@ BMS_OP_CODE_NONE
Definition: bms.h:127
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:290
bms_op_code_t
bms_op_code_t
Bond Management Control Point opcodes.
Definition: bms.h:117
bms_init_t
BMS Service init stucture. This contains all option and data needed for initialization of the service...
Definition: bms.h:146
bms_init_t::feature
uint32_t feature
Definition: bms.h:149
BMS_AUTH_CODE_LEN_MAX
#define BMS_AUTH_CODE_LEN_MAX
Definition: bms.h:74
BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_LE_ONLY
@ BMS_OP_CODE_DEL_ALL_BUT_ACTIVE_BOND_LE_ONLY
Definition: bms.h:126
bms_init_t::cccd_change_handler
bms_cccd_change_handler_t cccd_change_handler
Definition: bms.h:148
BMS_CCCD_STATUS_FEATURE_DISABLED
@ BMS_CCCD_STATUS_FEATURE_DISABLED
Definition: bms.h:112