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 <stdint.h> 61 #include <stdbool.h> 62 #include "ble_prf_types.h" 63 #include "gr55xx_sys.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 GLS_RACP_OP_RESERVED, /**< Reserved for future use. */ 80 GLS_RACP_OP_REP_STRD_RECS, /**< Report stored records (Operator: Value from Operator Table). */ 81 GLS_RACP_OP_DEL_STRD_RECS, /**< Delete stored records (Operator: Value from Operator Table). */ 82 GLS_RACP_OP_ABORT_OP, /**< Abort operation (Operator: Null 'value of 0x00 from Operator Table'). */ 83 GLS_RACP_OP_REP_NB_OF_STRD_RECS, /**< Report number of stored records (Operator: Value from Operator Table). */ 84 GLS_RACP_OP_NB_OF_STRD_RECS_RSP, /**< Number of stored records response \ 85 (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 GLS_RACP_OPERATOR_NULL, /**< NULL. */ 92 GLS_RACP_OPERATOR_ALL_RECS, /**< All records. */ 93 GLS_RACP_OPERATOR_LE_OR_EQ, /**< Less than or equal to. */ 94 GLS_RACP_OPERATOR_GT_OR_EQ, /**< Greater than or equal to. */ 95 GLS_RACP_OPERATOR_WITHIN_RANGE_OF, /**< Within rang of (inclusive). */ 96 GLS_RACP_OPERATOR_FIRST_REC, /**< First record(i.e. oldest record). */ 97 GLS_RACP_OPERATOR_LAST_REC, /**< Last record (i.e. most recent record). */ 98 } gls_racp_operator_t; 99 100 /**@brief Glucose Recoerd Access Control Point Response codes. */ 101 typedef enum { 102 GLS_RACP_RSP_RESERVED, /**< Reserved for future use. */ 103 GLS_RACP_RSP_SUCCESS, /**< Normal response for successful operation. */ 104 GLS_RACP_RSP_OP_CODE_NOT_SUP, /**< Normal response if unsupported Op Code is received. */ 105 GLS_RACP_RSP_INVALID_OPERATOR, /**< Normal response if Operator received does not meet \ 106 the requirements of the service (e.g. Null was expected). */ 107 GLS_RACP_RSP_OPERATOR_NOT_SUP, /**< Normal response if unsupported Operator is received. */ 108 GLS_RACP_RSP_INVALID_OPERAND, /**< Normal response if Operand received does not meet \ 109 the requirements of the service. */ 110 GLS_RACP_RSP_NO_RECS_FOUND, /**< Normal response if request to report stored records or request to \ 111 delete stored records resulted in no records meeting criteria. */ 112 GLS_RACP_RSP_ABORT_UNSUCCESSFUL, /**< Normal response if request for Abort cannot be completed. */ 113 GLS_RACP_RSP_PROCEDURE_NOT_COMPLETED, /**< Normal response if unable to complete a procedure for any reason. */ 114 GLS_RACP_RSP_OPERAND_NOT_SUP, /**< Normal response if unsupported Operand is received. */ 115 GLS_RACP_RSP_VALID_DECODE = 0xff /**< User-defined response if RACP request is valid for GLS. */ 116 } gls_racp_operand_t; 117 118 /**@brief Glucose Recoerd Access Control Point filter types. */ 119 typedef enum { 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 gls_racp_operator_t racp_operator; /**< Glucose Recoerd Access Control Point Operator. */ 133 gls_racp_filter_type_t racp_filter_type; /**< Glucose Recoerd Access Control Point filter types. */ 134 union { 135 struct { 136 uint16_t min; /**< Min sequence number. */ 137 uint16_t max; /**< Max sequence number. */ 138 } seq_num; /**< Sequence number filtering \ 139 (racp_filter_type = GLS_RACP_FILTER_SEQ_NUMBER). */ 140 struct { 141 prf_date_time_t min; /**< Min base time. */ 142 prf_date_time_t max; /**< Max base time. */ 143 } time; /**< User facing time filtering \ 144 (filter_type = GLS_RACP_FILTER_USER_FACING_TIME). */ 145 } val; /**< Filter union. */ 146 } gls_racp_filter_t; 147 148 /**@brief Glucose Recoerd Access Control Point request value. */ 149 typedef struct { 150 gls_racp_op_code_t op_code; /**< Glucose Recoerd Access Control Point Operation Code. */ 151 gls_racp_filter_t filter; /**< Glucose Recoerd Access Control Point Operation Code. */ 152 } gls_racp_req_t; 153 154 /**@brief Glucose Recoerd Access Control Point response value. */ 155 typedef struct { 156 gls_racp_op_code_t op_code; /**< Glucose Recoerd Access Control Point Operation Code. */ 157 gls_racp_operator_t racp_operator; /**< Glucose Recoerd Access Control Point Operator. */ 158 union { 159 uint16_t num_of_record; /**< Number of record (if op_code = GLS_RACP_OP_REP_NB_OF_STRD_RECS). */ 160 struct { 161 gls_racp_op_code_t op_code_req; /**< Request Op Code. */ 162 gls_racp_operand_t status; /**< Command Status (if op_code = GLS_RACP_OP_RSP_CODE). */ 163 } rsp; /**< Response. */ 164 } operand; /**< Response operand. */ 165 } gls_racp_rsp_t; 166 /** @} */ 167 168 /** 169 * @defgroup GLS_RACP_FUNCTION Functions 170 * @{ 171 */ 172 /** 173 ***************************************************************************************** 174 * @brief Decode record access control point request. 175 * 176 * @param[in] p_data: Pointer to data. 177 * @param[in] length: Length of data. 178 * @param[out] p_racp_req: Potnter to buffer saved decode result. 179 * 180 * @return Record access control point request decode result. 181 ***************************************************************************************** 182 */ 183 gls_racp_operand_t gls_racp_req_decode(const uint8_t *p_data, uint16_t length, gls_racp_req_t *p_racp_req); 184 185 /** 186 ***************************************************************************************** 187 * @brief Encode record access control point response. 188 * 189 * @param[in] p_racp_rsp: Pointer to buffer saved response. 190 * @param[out] p_encoded_buffer: Pointer to buffer where the encoded data will be written. 191 * 192 * @return Length of encode data. 193 ***************************************************************************************** 194 */ 195 uint16_t gls_racp_rsp_encode(gls_racp_rsp_t *p_racp_rsp, uint8_t *p_encoded_buffer); 196 197 /** 198 ***************************************************************************************** 199 * @brief Compared two date time. 200 * 201 * @param[in] p_compared_date_time: Pointer to compared date time. 202 * @param[out] p_base_date_time: Pointer to base date time. 203 * 204 * @return Result of compared. 205 * 1: compared_date_time > base_date_time. 206 * -1: compared_date_time < base_date_time 207 * 0: compared_date_time = base_date_time 208 ***************************************************************************************** 209 */ 210 int8_t gls_racp_user_time_compare(prf_date_time_t *p_compared_date_time, prf_date_time_t *p_base_date_time); 211 /** @} */ 212 213 #endif 214 /** @} */ 215 /** @} */ 216 217