gls_racp.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gls_racp.h
5 *
6 * @brief Glucose Service Record Access Control Point 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_GLS_RACP Glucose Service Record Access Control Point (GLS_RACP)
46 * @{
47 * @brief Glucose Service Record Access Control Point module.
48 *
49 * @details This module implements Glucose Service Record Access Control Point (RACP), includeding
50 * parsing, executing and responsing RACP from Client.
51 */
52
53 #ifndef __GLS_RACP_H__
54 #define __GLS_RACP_H__
55
56 /*
57 * INCLUDE FILES
58 ****************************************************************************************
59 */
60 #include "ble_prf_types.h"
61 #include "gr_includes.h"
62 #include <stdint.h>
63 #include <stdbool.h>
64
65 /**
66 * @defgroup GLS_RACP_MACRO Defines
67 * @{
68 */
69 #define GLS_RACP_FILTER_SEQ_NUM_LEN 2 /**< Length of filter sequence number. */
70 #define GLS_RACP_FILTER_USER_TIME_LEN 7 /**< Length of filter user facing time. */
71 /** @} */
72
73 /**
74 * @defgroup GLS_RACP_ENUM Enumerations
75 * @{
76 */
77 /**@brief Glucose Recoerd Access Control Point Operation Codes. */
78 typedef enum
79 {
80 GLS_RACP_OP_RESERVED, /**< Reserved for future use. */
81 GLS_RACP_OP_REP_STRD_RECS, /**< Report stored records (Operator: Value from Operator Table). */
82 GLS_RACP_OP_DEL_STRD_RECS, /**< Delete stored records (Operator: Value from Operator Table). */
83 GLS_RACP_OP_ABORT_OP, /**< Abort operation (Operator: Null 'value of 0x00 from Operator Table'). */
84 GLS_RACP_OP_REP_NB_OF_STRD_RECS, /**< Report number of stored records (Operator: Value from Operator Table). */
85 GLS_RACP_OP_NB_OF_STRD_RECS_RSP, /**< Number of stored records response (Operator: Null 'value of 0x00 from Operator Table'). */
86 GLS_RACP_OP_RSP_CODE, /**< Response Code (Operator: Null 'value of 0x00 from Operator Table'). */
87 } gls_racp_op_code_t;
88
89 /**@brief Glucose Recoerd Access Control Point Operator. */
90 typedef enum
91 {
92 GLS_RACP_OPERATOR_NULL, /**< NULL. */
93 GLS_RACP_OPERATOR_ALL_RECS, /**< All records. */
94 GLS_RACP_OPERATOR_LE_OR_EQ, /**< Less than or equal to. */
95 GLS_RACP_OPERATOR_GT_OR_EQ, /**< Greater than or equal to. */
96 GLS_RACP_OPERATOR_WITHIN_RANGE_OF, /**< Within rang of (inclusive). */
97 GLS_RACP_OPERATOR_FIRST_REC, /**< First record(i.e. oldest record). */
98 GLS_RACP_OPERATOR_LAST_REC, /**< Last record (i.e. most recent record). */
99 } gls_racp_operator_t;
100
101 /**@brief Glucose Recoerd Access Control Point Response codes. */
102 typedef enum
103 {
104 GLS_RACP_RSP_RESERVED, /**< Reserved for future use. */
105 GLS_RACP_RSP_SUCCESS, /**< Normal response for successful operation. */
106 GLS_RACP_RSP_OP_CODE_NOT_SUP, /**< Normal response if unsupported Op Code is received. */
107 GLS_RACP_RSP_INVALID_OPERATOR, /**< Normal response if Operator received does not meet the requirements of the service (e.g. Null was expected). */
108 GLS_RACP_RSP_OPERATOR_NOT_SUP, /**< Normal response if unsupported Operator is received. */
109 GLS_RACP_RSP_INVALID_OPERAND, /**< Normal response if Operand received does not meet the requirements of the service. */
110 GLS_RACP_RSP_NO_RECS_FOUND, /**< Normal response if request to report stored records or request to delete stored records resulted in no records meeting criteria. */
111 GLS_RACP_RSP_ABORT_UNSUCCESSFUL, /**< Normal response if request for Abort cannot be completed. */
112 GLS_RACP_RSP_PROCEDURE_NOT_COMPLETED, /**< Normal response if unable to complete a procedure for any reason. */
113 GLS_RACP_RSP_OPERAND_NOT_SUP, /**< Normal response if unsupported Operand is received. */
114 GLS_RACP_RSP_VALID_DECODE = 0xff /**< User-defined response if RACP request is valid for GLS. */
115 } gls_racp_operand_t;
116
117 /**@brief Glucose Recoerd Access Control Point filter types. */
118 typedef enum
119 {
120 GLS_RACP_FILTER_RESERVED, /**< Reserved for future use. */
121 GLS_RACP_FILTER_SEQ_NUMBER, /**< Filter data using Sequence Number criteria. */
122 GLS_RACP_FILTER_USER_FACING_TIME, /**< Filter data using User Facing Time criteria. */
123 } gls_racp_filter_type_t;
124 /** @} */
125
126 /**
127 * @defgroup GLS_RACP_STRUCT Structures
128 * @{
129 */
130 /**@brief Glucose Recoerd Access Control Point filter value. */
131 typedef struct
132 {
133 gls_racp_operator_t racp_operator; /**< Glucose Recoerd Access Control Point Operator. */
134 gls_racp_filter_type_t racp_filter_type; /**< Glucose Recoerd Access Control Point filter types. */
135 union
136 {
137 struct
138 {
139 uint16_t min; /**< Min sequence number. */
140 uint16_t max; /**< Max sequence number. */
141 } seq_num; /**< Sequence number filtering (racp_filter_type = GLS_RACP_FILTER_SEQ_NUMBER). */
142 struct
143 {
144 prf_date_time_t min; /**< Min base time. */
145 prf_date_time_t max; /**< Max base time. */
146 } time; /**< User facing time filtering (filter_type = GLS_RACP_FILTER_USER_FACING_TIME). */
147 } val; /**< Filter union. */
148 } gls_racp_filter_t;
149
150 /**@brief Glucose Recoerd Access Control Point request value. */
151 typedef struct
152 {
153 gls_racp_op_code_t op_code; /**< Glucose Recoerd Access Control Point Operation Code. */
154 gls_racp_filter_t filter; /**< Glucose Recoerd Access Control Point Operation Code. */
155 } gls_racp_req_t;
156
157 /**@brief Glucose Recoerd Access Control Point response value. */
158 typedef struct
159 {
160 gls_racp_op_code_t op_code; /**< Glucose Recoerd Access Control Point Operation Code. */
161 gls_racp_operator_t racp_operator; /**< Glucose Recoerd Access Control Point Operator. */
162 union
163 {
164 uint16_t num_of_record; /**< Number of record (if op_code = GLS_RACP_OP_REP_NB_OF_STRD_RECS). */
165 struct
166 {
167 gls_racp_op_code_t op_code_req; /**< Request Op Code. */
168 gls_racp_operand_t status; /**< Command Status (if op_code = GLS_RACP_OP_RSP_CODE). */
169 } rsp; /**< Response. */
170 } operand; /**< Response operand. */
171 } gls_racp_rsp_t;
172 /** @} */
173
174 /**
175 * @defgroup GLS_RACP_FUNCTION Functions
176 * @{
177 */
178 /**
179 *****************************************************************************************
180 * @brief Decode record access control point request.
181 *
182 * @param[in] p_data: Pointer to data.
183 * @param[in] length: Length of data.
184 * @param[out] p_racp_req: Potnter to buffer saved decode result.
185 *
186 * @return Record access control point request decode result.
187 *****************************************************************************************
188 */
189 gls_racp_operand_t gls_racp_req_decode(const uint8_t *p_data, uint16_t length, gls_racp_req_t *p_racp_req);
190
191 /**
192 *****************************************************************************************
193 * @brief Encode record access control point response.
194 *
195 * @param[in] p_racp_rsp: Pointer to buffer saved response.
196 * @param[out] p_encoded_buffer: Pointer to buffer where the encoded data will be written.
197 *
198 * @return Length of encode data.
199 *****************************************************************************************
200 */
201 uint16_t gls_racp_rsp_encode(gls_racp_rsp_t *p_racp_rsp, uint8_t *p_encoded_buffer);
202
203 /**
204 *****************************************************************************************
205 * @brief Compared two date time.
206 *
207 * @param[in] p_compared_date_time: Pointer to compared date time.
208 * @param[out] p_base_date_time: Pointer to base date time.
209 *
210 * @return Result of compared.
211 * 1: compared_date_time > base_date_time.
212 * -1: compared_date_time < base_date_time
213 * 0: compared_date_time = base_date_time
214 *****************************************************************************************
215 */
216 int8_t gls_racp_user_time_compare(prf_date_time_t *p_compared_date_time, prf_date_time_t *p_base_date_time);
217 /** @} */
218
219 #endif
220 /** @} */
221 /** @} */
222
gls_racp_req_t::filter
gls_racp_filter_t filter
Glucose Recoerd Access Control Point Operation Code.
Definition: gls_racp.h:154
GLS_RACP_FILTER_RESERVED
@ GLS_RACP_FILTER_RESERVED
Reserved for future use.
Definition: gls_racp.h:120
GLS_RACP_RSP_NO_RECS_FOUND
@ GLS_RACP_RSP_NO_RECS_FOUND
Normal response if request to report stored records or request to delete stored records resulted in n...
Definition: gls_racp.h:110
GLS_RACP_RSP_RESERVED
@ GLS_RACP_RSP_RESERVED
Reserved for future use.
Definition: gls_racp.h:104
GLS_RACP_OP_NB_OF_STRD_RECS_RSP
@ GLS_RACP_OP_NB_OF_STRD_RECS_RSP
Number of stored records response (Operator: Null 'value of 0x00 from Operator Table').
Definition: gls_racp.h:85
GLS_RACP_OPERATOR_FIRST_REC
@ GLS_RACP_OPERATOR_FIRST_REC
First record(i.e.
Definition: gls_racp.h:97
gls_racp_rsp_t::op_code
gls_racp_op_code_t op_code
Glucose Recoerd Access Control Point Operation Code.
Definition: gls_racp.h:160
GLS_RACP_OPERATOR_NULL
@ GLS_RACP_OPERATOR_NULL
NULL.
Definition: gls_racp.h:92
GLS_RACP_OPERATOR_ALL_RECS
@ GLS_RACP_OPERATOR_ALL_RECS
All records.
Definition: gls_racp.h:93
GLS_RACP_OP_REP_NB_OF_STRD_RECS
@ GLS_RACP_OP_REP_NB_OF_STRD_RECS
Report number of stored records (Operator: Value from Operator Table).
Definition: gls_racp.h:84
gr_includes.h
Include Files API.
GLS_RACP_OP_RSP_CODE
@ GLS_RACP_OP_RSP_CODE
Response Code (Operator: Null 'value of 0x00 from Operator Table').
Definition: gls_racp.h:86
gls_racp_rsp_t::op_code_req
gls_racp_op_code_t op_code_req
Request Op Code.
Definition: gls_racp.h:167
gls_racp_rsp_t::racp_operator
gls_racp_operator_t racp_operator
Glucose Recoerd Access Control Point Operator.
Definition: gls_racp.h:161
GLS_RACP_FILTER_USER_FACING_TIME
@ GLS_RACP_FILTER_USER_FACING_TIME
Filter data using User Facing Time criteria.
Definition: gls_racp.h:122
GLS_RACP_OP_REP_STRD_RECS
@ GLS_RACP_OP_REP_STRD_RECS
Report stored records (Operator: Value from Operator Table).
Definition: gls_racp.h:81
gls_racp_user_time_compare
int8_t gls_racp_user_time_compare(prf_date_time_t *p_compared_date_time, prf_date_time_t *p_base_date_time)
Compared two date time.
GLS_RACP_FILTER_SEQ_NUMBER
@ GLS_RACP_FILTER_SEQ_NUMBER
Filter data using Sequence Number criteria.
Definition: gls_racp.h:121
gls_racp_filter_t::min
uint16_t min
Min sequence number.
Definition: gls_racp.h:139
gls_racp_filter_t::racp_operator
gls_racp_operator_t racp_operator
Glucose Recoerd Access Control Point Operator.
Definition: gls_racp.h:133
GLS_RACP_OPERATOR_WITHIN_RANGE_OF
@ GLS_RACP_OPERATOR_WITHIN_RANGE_OF
Within rang of (inclusive).
Definition: gls_racp.h:96
gls_racp_rsp_t::num_of_record
uint16_t num_of_record
Number of record (if op_code = GLS_RACP_OP_REP_NB_OF_STRD_RECS).
Definition: gls_racp.h:164
gls_racp_rsp_encode
uint16_t gls_racp_rsp_encode(gls_racp_rsp_t *p_racp_rsp, uint8_t *p_encoded_buffer)
Encode record access control point response.
GLS_RACP_OPERATOR_GT_OR_EQ
@ GLS_RACP_OPERATOR_GT_OR_EQ
Greater than or equal to.
Definition: gls_racp.h:95
gls_racp_operator_t
gls_racp_operator_t
Glucose Recoerd Access Control Point Operator.
Definition: gls_racp.h:91
gls_racp_req_t
Glucose Recoerd Access Control Point request value.
Definition: gls_racp.h:152
gls_racp_filter_t::max
prf_date_time_t max
Max base time.
Definition: gls_racp.h:145
GLS_RACP_OP_RESERVED
@ GLS_RACP_OP_RESERVED
Reserved for future use.
Definition: gls_racp.h:80
ble_prf_types.h
Profile/Service Common Types.
GLS_RACP_RSP_OPERATOR_NOT_SUP
@ GLS_RACP_RSP_OPERATOR_NOT_SUP
Normal response if unsupported Operator is received.
Definition: gls_racp.h:108
GLS_RACP_RSP_OP_CODE_NOT_SUP
@ GLS_RACP_RSP_OP_CODE_NOT_SUP
Normal response if unsupported Op Code is received.
Definition: gls_racp.h:106
GLS_RACP_OPERATOR_LAST_REC
@ GLS_RACP_OPERATOR_LAST_REC
Last record (i.e.
Definition: gls_racp.h:98
gls_racp_filter_t::max
uint16_t max
Max sequence number.
Definition: gls_racp.h:140
GLS_RACP_OPERATOR_LE_OR_EQ
@ GLS_RACP_OPERATOR_LE_OR_EQ
Less than or equal to.
Definition: gls_racp.h:94
prf_date_time_t
The date and time structure.
Definition: ble_prf_types.h:101
gls_racp_op_code_t
gls_racp_op_code_t
Glucose Recoerd Access Control Point Operation Codes.
Definition: gls_racp.h:79
gls_racp_operand_t
gls_racp_operand_t
Glucose Recoerd Access Control Point Response codes.
Definition: gls_racp.h:103
gls_racp_filter_t::min
prf_date_time_t min
Min base time.
Definition: gls_racp.h:144
GLS_RACP_RSP_VALID_DECODE
@ GLS_RACP_RSP_VALID_DECODE
User-defined response if RACP request is valid for GLS.
Definition: gls_racp.h:114
GLS_RACP_RSP_SUCCESS
@ GLS_RACP_RSP_SUCCESS
Normal response for successful operation.
Definition: gls_racp.h:105
GLS_RACP_OP_ABORT_OP
@ GLS_RACP_OP_ABORT_OP
Abort operation (Operator: Null 'value of 0x00 from Operator Table').
Definition: gls_racp.h:83
GLS_RACP_RSP_OPERAND_NOT_SUP
@ GLS_RACP_RSP_OPERAND_NOT_SUP
Normal response if unsupported Operand is received.
Definition: gls_racp.h:113
GLS_RACP_RSP_ABORT_UNSUCCESSFUL
@ GLS_RACP_RSP_ABORT_UNSUCCESSFUL
Normal response if request for Abort cannot be completed.
Definition: gls_racp.h:111
GLS_RACP_OP_DEL_STRD_RECS
@ GLS_RACP_OP_DEL_STRD_RECS
Delete stored records (Operator: Value from Operator Table).
Definition: gls_racp.h:82
GLS_RACP_RSP_PROCEDURE_NOT_COMPLETED
@ GLS_RACP_RSP_PROCEDURE_NOT_COMPLETED
Normal response if unable to complete a procedure for any reason.
Definition: gls_racp.h:112
gls_racp_rsp_t
Glucose Recoerd Access Control Point response value.
Definition: gls_racp.h:159
gls_racp_rsp_t::status
gls_racp_operand_t status
Command Status (if op_code = GLS_RACP_OP_RSP_CODE).
Definition: gls_racp.h:168
gls_racp_filter_t
Glucose Recoerd Access Control Point filter value.
Definition: gls_racp.h:132
gls_racp_req_t::op_code
gls_racp_op_code_t op_code
Glucose Recoerd Access Control Point Operation Code.
Definition: gls_racp.h:153
gls_racp_filter_type_t
gls_racp_filter_type_t
Glucose Recoerd Access Control Point filter types.
Definition: gls_racp.h:119
gls_racp_req_decode
gls_racp_operand_t gls_racp_req_decode(const uint8_t *p_data, uint16_t length, gls_racp_req_t *p_racp_req)
Decode record access control point request.
GLS_RACP_RSP_INVALID_OPERATOR
@ GLS_RACP_RSP_INVALID_OPERATOR
Normal response if Operator received does not meet the requirements of the service (e....
Definition: gls_racp.h:107
GLS_RACP_RSP_INVALID_OPERAND
@ GLS_RACP_RSP_INVALID_OPERAND
Normal response if Operand received does not meet the requirements of the service.
Definition: gls_racp.h:109
gls_racp_filter_t::racp_filter_type
gls_racp_filter_type_t racp_filter_type
Glucose Recoerd Access Control Point filter types.
Definition: gls_racp.h:134