Developer World
Spresense SDK Library v3.3.0-375c679
bt_common.h
Go to the documentation of this file.
1/****************************************************************************
2 * modules/include/bluetooth/bt_common.h
3 *
4 * Copyright 2018, 2024 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
43#ifndef __MODULES_INCLUDE_BLUETOOTH_BT_COMMON_H
44#define __MODULES_INCLUDE_BLUETOOTH_BT_COMMON_H
45
46/****************************************************************************
47 * Included Files
48 ****************************************************************************/
49
50#include <stdint.h>
51#include <bluetooth/bluetooth.h>
52
53/****************************************************************************
54 * Pre-processor Definitions
55 ****************************************************************************/
56
57#define BT_ADV_DATA_MAX_LEN (255)
58#define BT_ADV_DATA_LEN_LEN (1)
59#define BT_ADV_DATA_TYPE_LEN (1)
60#define BT_EIR_LEN (BT_ADV_DATA_MAX_LEN \
61 - BT_ADV_DATA_LEN_LEN \
62 - BT_ADV_DATA_TYPE_LEN)
63
64#define BLE_IRK_LEN (16)
65#define BLE_CSRK_LEN (16)
66#define BLE_LTK_LEN (16)
67#define BLE_RAND_LEN (8)
68
69/* Macro to convert time in msec for scan parameter */
70
71#define BLE_SCAN_PARAM_INTERVAL_MSEC(t) ((t) * 1000 / 625)
72#define BLE_SCAN_PARAM_WINDOW_MSEC(t) ((t) * 1000 / 625)
73#define BLE_SCAN_PARAM_TIMEOUT_MSEC(t) ((t) * 1000 / 10000)
74
75/* Macro to convert time in msec for connection parameter */
76
77#define BLE_CONN_PARAM_INTERVAL_MSEC(t) ((t) * 1000 / 1250)
78#define BLE_CONN_PARAM_TIMEOUT_MSEC(t) ((t) * 1000 / 10000)
79
84#define BLESTAT_SUCCESS 0x00
85
88#define BLESTAT_MEMCAP_EXCD 0x07
89
92#define BLESTAT_CONNECT_TIMEOUT 0x08
93
96#define BLESTAT_PEER_TERMINATED 0x13
97
100#define BLESTAT_PEER_TERM_LOWRES 0x14
101
104#define BLESTAT_PEER_TERM_POFF 0x15
105
108#define BLESTAT_TERMINATED 0x16
109
112#define BLESTAT_UNSPEC_ERR 0x1F
113
116#define BLESTAT_DEVICE_BUSY 0x3A
117
120#define BLESTAT_PARAM_REJECTED 0x3B
121
124#define BLESTAT_CONNECT_FAILED 0x3E
125
126/****************************************************************************
127 * Public Types
128 ****************************************************************************/
129
134typedef enum
135{
139 BT_CONNECTED = 3
141
147{
155 char bt_name[BT_NAME_LEN + 1];
156 char ble_name[BT_NAME_LEN + 1];
157};
158
164{
168 char bt_target_name[BT_NAME_LEN];
169};
170
176{
182 char bt_target_name[BT_NAME_LEN];
183};
184
191{
192 uint8_t type;
193 uint8_t addr[BT_ADDR_LEN];
194};
195
202{
203 uint8_t irk[BLE_IRK_LEN];
204 uint8_t csrk[BLE_CSRK_LEN];
205 uint8_t ltk[BLE_LTK_LEN];
206 uint8_t rand[BLE_RAND_LEN];
207 uint16_t ediv;
208};
209
211{
212 uint16_t handle;
213 uint16_t value;
214};
215
222{
223 struct ble_addr_s peer_addr;
224 struct ble_idkey_s peer;
225 struct ble_idkey_s own;
226 uint8_t cccd_num;
227 struct ble_cccd_s *cccd;
228};
229
231{
232 uint8_t active;
233 uint16_t interval;
234 uint16_t window;
235 uint16_t timeout;
236};
237
239{
240 uint16_t min_interval;
241 uint16_t max_interval;
242 uint16_t slave_latency;
243 uint16_t sup_timeout;
244};
245
251{
254 void (*inquiry_result)(BT_ADDR addr, char *name);
255 void (*inquiry_complete)(void);
256 void (*connect_status_changed)(struct bt_acl_state_s *bt_acl_state, bool connected, int status);
257 void (*connected_device_name)(const char *name);
258 void (*bond_info)(BT_ADDR addr);
259};
260
266{
269 void (*connect_status_changed)(struct ble_state_s *ble_state,
270 bool connected,
271 uint8_t status);
272
275 void (*connected_device_name_resp)(const char *name);
276
279 void (*scan_result)(BT_ADDR addr, uint8_t *data, uint8_t len);
280
283 void (*mtusize)(uint16_t handle, uint16_t sz);
284
287 void (*save_bondinfo)(int num, struct ble_bondinfo_s *bond);
288
291 int (*load_bondinfo)(int num, struct ble_bondinfo_s *bond);
292
295 void (*encryption_result)(uint16_t conn_handle, bool result);
296
297};
298
305{
306 uint8_t len;
307 uint8_t type;
308 uint8_t data[BT_EIR_LEN];
309};
310
311#ifdef __cplusplus
312#define EXTERN extern "C"
313extern "C"
314{
315#else
316#define EXTERN extern
317#endif
318
319/****************************************************************************
320 * Public Function Prototypes
321 ****************************************************************************/
322
330int bt_init(void);
331
338int bt_finalize(void);
339
350
360
370int bt_set_name(char *name);
371
380int bt_get_name(char *name);
381
389int bt_enable(void);
390
398int bt_disable(void);
399
408
417
428int bt_get_bond_list(BT_ADDR *addr, int *num);
429
440
451
460
469
479int bt_register_common_cb(struct bt_common_ops_s *bt_common_ops);
480
491
501
512
520
530int ble_set_name(char *name);
531
540int ble_get_name(char *name);
541
551
558int ble_enable(void);
559
566int ble_disable(void);
567
576int ble_connect(struct ble_state_s *ble_state);
577
586int ble_disconnect(struct ble_state_s *ble_state);
587
596
605
615int ble_start_scan(bool duplicate_filter);
616
625
635int ble_register_common_cb(struct ble_common_ops_s *ble_common_ops);
636
645uint16_t ble_set_request_mtusize(uint16_t sz);
646
654
664int ble_get_negotiated_mtusize(uint16_t handle);
665
677int ble_set_tx_power(int8_t tx_power);
678
688
698
707int ble_pairing(uint16_t handle);
708
719 uint8_t *adv_data,
720 uint8_t adv_len,
721 struct bt_eir_s *eir);
722
723#undef EXTERN
724#ifdef __cplusplus
725}
726#endif
727
728#endif /* __MODULES_INCLUDE_BLUETOOTH_BT_COMMON_H */
Bluetooth common header for SDK on Spresense.
BT_VISIBILITY
BT visibility ID.
Definition: bluetooth.h:250
BT_PAIR_STATUS
BT pairing result.
Definition: bluetooth.h:210
BT_CMD_STATUS
BT hci command status.
Definition: bluetooth.h:189
BLE_APPEARANCE
BLE appearance ID.
Definition: bluetooth.h:262
BLE_AD_TYPE
BLE data type of advertising data.
Definition: bluetooth.h:322
int bt_get_address(BT_ADDR *addr)
Get Bluetooth module address.
int bt_disable(void)
Bluetooth module disable Bluetooth set power off.
int bt_start_inquiry(void)
Bluetooth inquiry start Start to inquiry for connect peer device.
int bt_get_bond_list(BT_ADDR *addr, int *num)
Bluetooth get bond device list Get bond devices list with BD_ADDR.
int bt_set_visibility(BT_VISIBILITY visibility)
Bluetooth set visible Visible this device from others.
int ble_cancel_advertise(void)
Bluetooth LE cancel advertise Cancel BLE advertise mode.
int bt_finalize(void)
Bluetooth module finalize.
int ble_pairing(uint16_t handle)
Execute pairing.
int ble_start_advertise(void)
Bluetooth LE start advertise Start BLE advertise mode.
int ble_set_tx_power(int8_t tx_power)
Set Tx power.
int ble_parse_advertising_data(BLE_AD_TYPE target, uint8_t *adv_data, uint8_t adv_len, struct bt_eir_s *eir)
Parse advertise data.
int bt_pairing_enable(void)
Bluetooth pairing enable Entering bluetooth pairing mode.
int ble_get_name(char *name)
Get Bluetooth LE module name.
uint8_t ble_get_address_type(void)
Get Bluetooth LE module address type.
int ble_get_address(BT_ADDR *addr)
Get Bluetooth LE module address.
int ble_set_scan_param(struct ble_scan_param_s *param)
Set scan parameter.
int ble_get_negotiated_mtusize(uint16_t handle)
Get negotiated MTU size.
int ble_register_common_cb(struct ble_common_ops_s *ble_common_ops)
Bluetooth LE register common callbacks Register Connect/Advertise/Scan callback.
int ble_disconnect(struct ble_state_s *ble_state)
Bluetooth LE dicsonnect for Central.
int bt_cancel_inquiry(void)
Bluetooth inquiry cancel Cancel to inquiry.
int bt_enable(void)
Bluetooth module enable Bluetooth set power on(and download firmware, etc).
int ble_cancel_scan(void)
Bluetooth LE cancel scan Cancel BLE scan mode.
int ble_set_conn_param(struct ble_conn_param_s *param)
Set connection parameter.
int ble_disable(void)
Bluetooth LE disable.
int bt_set_address(BT_ADDR *addr)
Set Bluetooth module address This is Spresense side address and should be called before bt_enable.
int ble_start_scan(bool duplicate_filter)
Bluetooth LE start scan Start BLE scan mode.
int bt_register_common_cb(struct bt_common_ops_s *bt_common_ops)
Bluetooth register common callbacks Register Connect/Pairing/Inquiry callback.
int ble_connect(struct ble_state_s *ble_state)
Bluetooth LE connect for Central.
int ble_set_public_address(BT_ADDR *addr)
Set Bluetooth LE module address of the public address type. This is Spresense side address and should...
int bt_paring_disable(void)
Bluetooth pairing disable Escaping bluetooth pairing mode.
int ble_set_appearance(BLE_APPEARANCE appearance)
Set Bluetooth LE module appearance.
int bt_init(void)
Bluetooth module initialize For initialize a pin config, NV storage, UART, etc.
int ble_set_address(BT_ADDR *addr)
Set Bluetooth LE module address of the random static address type. This is Spresense side address and...
int ble_set_name(char *name)
Set Bluetooth LE module name This name visible for other devices and should be called before bt_enabl...
uint16_t ble_set_request_mtusize(uint16_t sz)
Set MTU size that application requests.
int ble_enable(void)
Bluetooth LE enable.
int bt_set_name(char *name)
Set Bluetooth module name This name visible for other devices and should be called before bt_enable.
uint16_t ble_get_request_mtusize(void)
Get MTU size that application requests.
int bt_unbond(BT_ADDR *addr)
Bluetooth unbond by BD_ADDR Unbond device by BD_ADDR.
int bt_get_name(char *name)
Get Bluetooth module name.
BT_CONNECT_STATUS
BT profile connection status.
Definition: bt_common.h:135
@ BT_DISCONNECTING
Definition: bt_common.h:137
@ BT_CONNECTED
Definition: bt_common.h:139
@ BT_CONNECTING
Definition: bt_common.h:138
@ BT_DISCONNECTED
Definition: bt_common.h:136
BT address types.
Definition: bluetooth.h:171
BLE address.
Definition: bt_common.h:191
Bluetooth LE bonding information.
Definition: bt_common.h:222
Definition: bt_common.h:211
Bluetooth LE Common application callbacks.
Definition: bt_common.h:266
void(* save_bondinfo)(int num, struct ble_bondinfo_s *bond)
Definition: bt_common.h:287
void(* connect_status_changed)(struct ble_state_s *ble_state, bool connected, uint8_t status)
Definition: bt_common.h:269
void(* connected_device_name_resp)(const char *name)
Definition: bt_common.h:275
int(* load_bondinfo)(int num, struct ble_bondinfo_s *bond)
Definition: bt_common.h:291
void(* encryption_result)(uint16_t conn_handle, bool result)
Definition: bt_common.h:295
void(* mtusize)(uint16_t handle, uint16_t sz)
Definition: bt_common.h:283
Definition: bt_common.h:239
uint16_t slave_latency
Definition: bt_common.h:242
uint16_t max_interval
Definition: bt_common.h:241
uint16_t min_interval
Definition: bt_common.h:240
uint16_t sup_timeout
Definition: bt_common.h:243
Bluetooth LE common HAL callbacks.
Definition: bt_if.h:139
Definition: bt_common.h:202
Definition: bt_common.h:231
uint8_t active
Definition: bt_common.h:232
uint16_t window
Definition: bt_common.h:234
uint16_t interval
Definition: bt_common.h:233
uint16_t timeout
Definition: bt_common.h:235
Bluetooth LE context.
Definition: bt_common.h:176
struct bt_common_state_s * bt_common_state
Definition: bt_common.h:179
BT_CONNECT_STATUS ble_connection
Definition: bt_common.h:177
uint8_t bt_target_addr_type
Definition: bt_common.h:180
BT_ADDR bt_target_addr
Definition: bt_common.h:181
uint16_t ble_connect_handle
Definition: bt_common.h:178
char bt_target_name[BT_NAME_LEN]
Definition: bt_common.h:182
Bluetooth ACL context.
Definition: bt_common.h:164
struct bt_common_state_s * bt_common_state
Definition: bt_common.h:166
BT_ADDR bt_target_addr
Definition: bt_common.h:167
BT_CONNECT_STATUS bt_acl_connection
Definition: bt_common.h:165
char bt_target_name[BT_NAME_LEN]
Definition: bt_common.h:168
Bluetooth Common application callbacks.
Definition: bt_common.h:251
void(* connected_device_name)(const char *name)
Definition: bt_common.h:257
void(* connect_status_changed)(struct bt_acl_state_s *bt_acl_state, bool connected, int status)
Definition: bt_common.h:256
void(* command_status)(BT_CMD_STATUS status)
Definition: bt_common.h:252
void(* bond_info)(BT_ADDR addr)
Definition: bt_common.h:258
void(* inquiry_complete)(void)
Definition: bt_common.h:255
void(* pairing_complete)(BT_ADDR addr, BT_PAIR_STATUS status)
Definition: bt_common.h:253
void(* inquiry_result)(BT_ADDR addr, char *name)
Definition: bt_common.h:254
Bluetooth base context.
Definition: bt_common.h:147
struct bt_hal_common_ops_s * bt_hal_common_ops
Definition: bt_common.h:148
struct bt_common_ops_s * bt_common_ops
Definition: bt_common.h:150
BT_ADDR bt_addr
Definition: bt_common.h:152
char bt_name[BT_NAME_LEN+1]
Definition: bt_common.h:155
char ble_name[BT_NAME_LEN+1]
Definition: bt_common.h:156
struct ble_common_ops_s * ble_common_ops
Definition: bt_common.h:151
uint8_t ble_addr_type
Definition: bt_common.h:154
BT_ADDR ble_addr
Definition: bt_common.h:153
struct ble_hal_common_ops_s * ble_hal_common_ops
Definition: bt_common.h:149
The format of one data in advertising data.
Definition: bt_common.h:305
Bluetooth Common HAL callbacks.
Definition: bt_if.h:70