ble_prf_utils.h
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 *
4 * @file ble_prf_utils.h
5 *
6 * @brief Profile/Service Utilities 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_PRF_UTILS Profile/Service Utilities
46 * @{
47 * @brief Definitions and prototypes for the Profile/Service Utilities interface.
48 *
49 */
50
51 #ifndef __BLE_PRF_UTILS_H__
52 #define __BLE_PRF_UTILS_H__
53
54 #include "ble_prf_types.h"
55 #include <stdbool.h>
56
57 /**
58 * @defgroup BLE_PRF_UTILS_FUNCTION Functions
59 * @{
60 */
61 /**
62 *****************************************************************************************
63 * @brief Pack Characteristic Presentation Format descriptor value to a buffer.
64 *
65 * @param[out] p_packed_val: Pointer to the packed buffer.
66 * @param[in] p_char_pres_fmt: Pointer to the structure of Characteristic Presentation
67 * Format value. See @ref prf_char_pres_fmt_t.
68 *****************************************************************************************
69 */
70 void prf_pack_char_pres_fmt(uint8_t *p_packed_val, const prf_char_pres_fmt_t *p_char_pres_fmt);
71
72 /**
73 *****************************************************************************************
74 * @brief Unpack the data in a buffer to the structure of Characteristic Presentation
75 * Format descriptor value.
76 *
77 * @param[in] p_packed_val: Pointer to the packed buffer.
78 * @param[out] p_char_pres_fmt: Pointer to the structure of Characteristic Presentation
79 * Format value. See @ref prf_char_pres_fmt_t.
80 *****************************************************************************************
81 */
82 void prf_unpack_char_pres_fmt(const uint8_t *p_packed_val, prf_char_pres_fmt_t *p_char_pres_fmt);
83
84 /**
85 *****************************************************************************************
86 * @brief Pack the value in date-time structure to a buffer.
87 *
88 * @param[out] p_packed_val: Pointer to a packed buffer.
89 * @param[in] p_date_time: Pointer to the date-time structure, see @ref prf_date_time_t.
90 *
91 * @return The size of packed value.
92 *****************************************************************************************
93 */
94 uint8_t prf_pack_date_time(uint8_t *p_packed_val, const prf_date_time_t *p_date_time);
95
96 /**
97 *****************************************************************************************
98 * @brief Unpack the data in buffer to the date-time structure.
99 *
100 * @param[in] p_packed_val: Pointer to the packed buffer.
101 * @param[out] p_date_time: Pointer to date-time structure, see @ref prf_date_time_t.
102 *
103 * @return The size of packed value
104 *****************************************************************************************
105 */
106 uint8_t prf_unpack_date_time(const uint8_t *p_packed_val, prf_date_time_t *p_date_time);
107
108 /**
109 *****************************************************************************************
110 * @brief Find the attribute index by handle.
111 *
112 * @param[in] handle: The handle of a characteristic in BLE Stack database.
113 * @param[in] start_hdl: The start handle of a service in BLE Stack database.
114 * @param[in] char_nb: The number of the characteristics in a service's attribute table.
115 * @param[in] p_char_mask: Pointer to the mask of characteristics which are added
116 * into BLE Stack database from the service's attribute table.
117 *
118 * @return The handle's index in the service's attribute table.
119 *****************************************************************************************
120 */
121 uint8_t prf_find_idx_by_handle(uint16_t handle, uint16_t start_hdl,
122 uint8_t char_nb, uint8_t *p_char_mask);
123
124 /**
125 *****************************************************************************************
126 * @brief Find the attribute handle by index.
127 *
128 * @param[in] idx: The attribute index in the service's attribute table.
129 * @param[in] start_hdl: The start handle value in the database.
130 * @param[in] p_char_mask: Pointer to the mask of characteristics which are added
131 * into BLE Stack database from the service's attribute table.
132 *
133 * @return The handle of the attribute with the index in BLE Stack database.
134 *****************************************************************************************
135 */
136 uint16_t prf_find_handle_by_idx(uint8_t idx, uint16_t start_hdl, uint8_t *p_char_mask);
137
138 /**
139 *****************************************************************************************
140 * @brief Check if a CCCD value is valid.
141 *
142 * @param[in] cccd_value: The CCCD value to be checked.
143 *
144 * @return True if valid, otherwise false.
145 ****************************************************************************************
146 */
147 bool prf_is_cccd_value_valid(uint16_t cccd_value);
148
149 /**
150 *****************************************************************************************
151 * @brief Check if a CCCD value is notification enabled.
152 *
153 * @param[in] cccd_value: The CCCD value to be checked.
154 *
155 * @return true if enabled, otherwise false.
156 ****************************************************************************************
157 */
158 bool prf_is_notification_enabled(uint16_t cccd_value);
159
160 /**
161 *****************************************************************************************
162 * @brief Check if a CCCD value is indication enabled.
163 *
164 * @param[in] cccd_value: The CCCD value to be checked
165 *
166 * @return true if enabled, otherwise false.
167 *****************************************************************************************
168 */
169 bool prf_is_indication_enabled(uint16_t cccd_value);
170 /** @} */
171
172 #endif /* _BLE_PRF_UTILS_H_ */
173 /** @} */
174 /** @} */
175
prf_pack_char_pres_fmt
void prf_pack_char_pres_fmt(uint8_t *p_packed_val, const prf_char_pres_fmt_t *p_char_pres_fmt)
Pack Characteristic Presentation Format descriptor value to a buffer.
prf_is_notification_enabled
bool prf_is_notification_enabled(uint16_t cccd_value)
Check if a CCCD value is notification enabled.
prf_char_pres_fmt_t
Characteristic Presentation Format Descriptor structure.
Definition: ble_prf_types.h:91
prf_unpack_char_pres_fmt
void prf_unpack_char_pres_fmt(const uint8_t *p_packed_val, prf_char_pres_fmt_t *p_char_pres_fmt)
Unpack the data in a buffer to the structure of Characteristic Presentation Format descriptor value.
ble_prf_types.h
Profile/Service Common Types.
prf_pack_date_time
uint8_t prf_pack_date_time(uint8_t *p_packed_val, const prf_date_time_t *p_date_time)
Pack the value in date-time structure to a buffer.
prf_date_time_t
The date and time structure.
Definition: ble_prf_types.h:101
prf_unpack_date_time
uint8_t prf_unpack_date_time(const uint8_t *p_packed_val, prf_date_time_t *p_date_time)
Unpack the data in buffer to the date-time structure.
prf_is_indication_enabled
bool prf_is_indication_enabled(uint16_t cccd_value)
Check if a CCCD value is indication enabled.
prf_find_idx_by_handle
uint8_t prf_find_idx_by_handle(uint16_t handle, uint16_t start_hdl, uint8_t char_nb, uint8_t *p_char_mask)
Find the attribute index by handle.
prf_find_handle_by_idx
uint16_t prf_find_handle_by_idx(uint8_t idx, uint16_t start_hdl, uint8_t *p_char_mask)
Find the attribute handle by index.
prf_is_cccd_value_valid
bool prf_is_cccd_value_valid(uint16_t cccd_value)
Check if a CCCD value is valid.