Developer World
Spresense SDK Library v3.2.0-ebc0364
ble_util.h
1/****************************************************************************
2 * sdk/modules/include/bluetooth/ble_util.h
3 *
4 * Copyright 2023 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef __SDK_MODULES_INCLUDE_BLUETOOTH_BLE_UTIL_H
37#define __SDK_MODULES_INCLUDE_BLUETOOTH_BLE_UTIL_H
38
39/****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43#include <stdint.h>
44#include <bluetooth/bt_common.h>
45#include <bluetooth/ble_gatt.h>
46#include <bluetooth/hal/bt_if.h>
47
48/****************************************************************************
49 * Public Functions Prototypes
50 ****************************************************************************/
51
52/* name: bleutil_convert_uuid2str
53 * Convert BLE_UUID to string.
54 *
55 * uuid [in] : UUID
56 * str [out] : UUID string
57 * In uuid->type = BLE_UUID_TYPE_UUID128 case,
58 * VVVVVVVV-WWWW-XXXX-YYYY-ZZZZZZZZZZZZ.
59 * otherwise XXXX
60 * len [in] : str buffer length.
61 * In uuid->type = BLE_UUID_TYPE_UUID128 case,
62 * len needs to be greater than BLE_UUID_128BIT_STRING_LENGTH.
63 * othewise, len needs to be greater than BLE_UUID_16BIT_STRING_LENGTH.
64 *
65 * Return : Positive integer String length of str.
66 * -ENOMEM len is too short.
67 */
68
69int bleutil_convert_uuid2str(BLE_UUID *uuid, char *str, int len);
70
71/* name: bleutil_convert_str2uuid
72 * Convert UUID string to BLE_UUID structure.
73 *
74 * str [in] : UUID string
75 * uuid [out] : BLE_UUID structure
76 *
77 * Return : OK convert success, ERROR invalid input string
78 */
79
80int bleutil_convert_str2uuid(char *str, BLE_UUID *uuid);
81
82/* name: bleutil_uuidcmp
83 * Compare two UUIDs that are input.
84 *
85 * uuid1 [in] : UUID1
86 * uuid2 [in] : UUID2
87 *
88 * Return : 0 Two UUIDs are same. 0 Not
89 */
90
91int bleutil_uuidcmp(BLE_UUID *uuid1, BLE_UUID *uuid2);
92
93/* name: bleutil_add_btaddr
94 * Add a BLE address in the ble_status.
95 *
96 * status [in/out] : Status instance.
97 * addr [in] : BLE address
98 * addr_type [in] : BLE address type
99 */
100
101void bleutil_add_btaddr(struct ble_state_s *state, BT_ADDR *addr,
102 uint8_t addr_type);
103
104/* name: bleutil_find_srvc_uuid
105 * Find specific UUID from advertising data.
106 *
107 * uuid [in] : Target UUID to find.
108 * data [in] : Advertising data
109 * len [in] : Advertising data length in bytes
110 *
111 * Return : 1 Found the UUID. 0 Not
112 */
113
114int bleutil_find_srvc_uuid(BLE_UUID *uuid, uint8_t *data, uint8_t len);
115
116/* name: bleutil_get_devicename
117 * Get device name from advertising data
118 *
119 * data [in] : Advertising data
120 * len [in] : Advertising data length in bytes
121 * devname [out] : Device name
122 *
123 * Return : 1 Device name is contained. 0 Not
124 */
125
126int bleutil_get_devicename(uint8_t *data, uint8_t len, char *devname);
127
128/* name: bleutil_get_addrtype
129 * Get BLE address type from advertising data
130 *
131 * data [in] : Advertising data
132 * len [in] : Advertising data length in bytes
133 *
134 * Return : BLE address type. One of below
135 * BLE_ADDRTYPE_PUBLIC
136 * BLE_ADDRTYPE_RAND_STATIC
137 * BLE_ADDRTYPE_RAND_PRIV_RESOLVABLE
138 * BLE_ADDRTYPE_RAND_PRIV_NONRESOLVABLE
139 */
140
141BLE_ADDRESS_TYPE bleutil_get_addrtype(uint8_t *data, uint8_t len);
142
143/* name: bleutil_get_advertising_flags
144 * Get advertising flags from advertising data
145 * This flags setting is defined in P.15 of
146 * https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=556598
147 *
148 * data [in] : Advertising data
149 * len [in] : Advertising data length in bytes
150 * flags [out] : Advertising flags, which has the bit structure.
151 * Each bits are defined as follows
152 * BLE_ADV_FLAGS_LIMITED_DISC_MODE
153 * BLE_ADV_FLAGS_GENERAL_DISC_MODE
154 * BLE_ADV_FLAGS_BR_EDR_NOT_SUPPORTED
155 * BLE_ADV_FLAGS_LE_BR_EDR_CONTROLLER
156 * BLE_ADV_FLAGS_LE_BR_EDR_HOST
157 *
158 * Return : 1 Advertising flags is contained. 0 Not
159 */
160
161int bleutil_get_advertising_flags(uint8_t *data, uint8_t len, uint8_t *flags);
162
163/* name: bleutil_get_txpower
164 * Get advertise flags from advertising data
165 *
166 * data [in] : Advertising data
167 * len [in] : Advertising data length in bytes
168 * txpower [out] : TX power(-127dBm to +127dBm)
169 *
170 * Return : 1 TX power is contained. 0 Not
171 */
172
173int bleutil_get_txpower(uint8_t *data, uint8_t len, int8_t *txpower);
174
175/* name: bleutil_get_connection_interval
176 * Get connection interval range from advertising data.
177 *
178 * data [in] : Advertising data
179 * len [in] : Advertising data length in bytes
180 * min [out] : The minimum value for the connection interval
181 * The actual minimum value = min * 1.25msec
182 * max [out] : The maximum value for the connection interval
183 * The actual maximum value = max * 1.25msec
184 *
185 * Return : 1 Connection interval is contained. 0 Not
186 */
187
188int bleutil_get_connection_interval(uint8_t *data,
189 uint8_t len,
190 uint16_t *min,
191 uint16_t *max);
192
193/* name: bleutil_judge_srvc_uuid_requested
194 * Judge if specific UUID is requested from advertising data.
195 *
196 * uuid [in] : Target UUID, that own device provides
197 * data [in] : Advertising data
198 * len [in] : Advertising data length in bytes
199 *
200 * Return : 1 UUID is requested. 0 Not
201 */
202
203int bleutil_judge_srvc_uuid_requested(BLE_UUID *uuid,
204 uint8_t *data,
205 uint8_t len);
206
207/* name: bleutil_get_appearance
208 * Get appearance from advertising data.
209 * Appearances are defined in P.27 - P.40
210 * of https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned_Numbers.pdf
211 *
212 * data [in] : Advertising data
213 * len [in] : Advertising data length in bytes
214 * appearance [out] : Apperance. One of below
215 * BLE_APPEARANCE_GENERIC_PHONE
216 * BLE_APPEARANCE_GENERIC_COMPUTER
217 * BLE_APPEARANCE_GENERIC_WATCH
218 * BLE_APPEARANCE_WATCH_SPORTS
219 * BLE_APPEARANCE_GENERIC_CLOCK
220 * BLE_APPEARANCE_GENERIC_DISPLAY
221 * BLE_APPEARANCE_GENERIC_REMOTE_CONTROL
222 * BLE_APPEARANCE_GENERIC_EYE_GLASSES
223 * BLE_APPEARANCE_GENERIC_TAG
224 * BLE_APPEARANCE_GENERIC_KEYRING
225 * BLE_APPEARANCE_GENERIC_MEDIA_PLAYER
226 * BLE_APPEARANCE_GENERIC_BARCODE_SCANNER
227 * BLE_APPEARANCE_GENERIC_THERMOMETER
228 * BLE_APPEARANCE_THERMOMETER_EAR
229 * BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR
230 * BLE_APPEARANCE_HEART_RATE_BELT
231 * BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE
232 * BLE_APPEARANCE_BLOOD_PRESSURE_ARM
233 * BLE_APPEARANCE_BLOOD_PRESSURE_WRIST
234 * BLE_APPEARANCE_GENERIC_HID_DEVICE
235 * BLE_APPEARANCE_HID_KEYBOARD
236 * BLE_APPEARANCE_HID_MOUSE
237 * BLE_APPEARANCE_HID_JOYSTICK
238 * BLE_APPEARANCE_HID_GAMEPAD
239 * BLE_APPEARANCE_HID_DIGITIZER_TABLET
240 * BLE_APPEARANCE_HID_CARD_READER
241 * BLE_APPEARANCE_HID_DIGITAL_PEN
242 * BLE_APPEARANCE_HID_BARCODE_SCANNER
243 * BLE_APPEARANCE_GENERIC_GLUCOSE_METER
244 * BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR
245 * BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE
246 * BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE
247 * BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP
248 * BLE_APPEARANCE_GENERIC_CYCLING
249 * BLE_APPEARANCE_CYCLING_COMPUTER
250 * BLE_APPEARANCE_CYCLING_SPEED_SENSOR
251 * BLE_APPEARANCE_CYCLING_CADENCE_SENSOR
252 * BLE_APPEARANCE_CYCLING_POWER_SENSOR
253 * BLE_APPEARANCE_CYCLING_SPEED_AND_CADENCE_SENSOR
254 *
255 * Return : 1 Apperance is contained. 0 Not
256 */
257
258int bleutil_get_appearance(uint8_t *data, uint8_t len, uint16_t *appearance);
259
260/* name: bleutil_get_advertise_interval
261 * Get advertising interval range from advertising data.
262 *
263 * data [in] : Advertising data
264 * len [in] : Advertising data length in bytes
265 * interval [out] : The advertising interval
266 * The actual value = interval * 0.625msec
267 *
268 * Return : 1 Advertising interval is contained. 0 Not
269 */
270
271int bleutil_get_advertising_interval(uint8_t *data, uint8_t len, uint16_t *interval);
272
273/* name: bleutil_get_manufacturer_specific_data
274 * Get manufacturer specific data from advertising data.
275 * The manufacturer specific data consists of company ID and arbitrary data.
276 * Company IDs are defined in P.216 - P.402
277 * of https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned_Numbers.pdf
278 *
279 * data [in] : Advertising data
280 * len [in] : Advertising data length in bytes
281 * company [out] : company ID
282 * specific_data [out] : Manufacturer specific data
283 * specific_datalen [out] : Manufacturer specific data length
284 *
285 * Return : 1 Manufacturer specific data is contained. 0 Not
286 */
287
288int bleutil_get_manufacturer_specific_data(uint8_t *data,
289 uint8_t len,
290 uint8_t *company,
291 uint8_t **specific_data,
292 uint8_t *specific_datalen);
293
294#endif /* __SDK_MODULES_INCLUDE_BLUETOOTH_BLE_UTIL_H */
Bluetooth Low Energy GATT Server/Client API.
BLE_ADDRESS_TYPE
BLE address type.
Definition: bluetooth.h:474
Bluetooth generic API.
Bluetooth HAL I/F.
BLE UUID structure.
Definition: ble_gatt.h:177
BT address types.
Definition: bluetooth.h:171
Bluetooth LE context.
Definition: bt_common.h:164