Developer World
Spresense SDK Library v3.2.0-ebc0364
bt_common.h
Go to the documentation of this file.
1/****************************************************************************
2 * modules/include/bluetooth/bt_common.h
3 *
4 * Copyright 2018 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
73#define BLESTAT_SUCCESS 0x00
74
77#define BLESTAT_MEMCAP_EXCD 0x07
78
81#define BLESTAT_CONNECT_TIMEOUT 0x08
82
85#define BLESTAT_PEER_TERMINATED 0x13
86
89#define BLESTAT_PEER_TERM_LOWRES 0x14
90
93#define BLESTAT_PEER_TERM_POFF 0x15
94
97#define BLESTAT_TERMINATED 0x16
98
101#define BLESTAT_UNSPEC_ERR 0x1F
102
105#define BLESTAT_DEVICE_BUSY 0x3A
106
109#define BLESTAT_PARAM_REJECTED 0x3B
110
113#define BLESTAT_CONNECT_FAILED 0x3E
114
115/****************************************************************************
116 * Public Types
117 ****************************************************************************/
118
123typedef enum
124{
128 BT_CONNECTED = 3
130
136{
143 char bt_name[BT_NAME_LEN + 1];
144 char ble_name[BT_NAME_LEN + 1];
145};
146
152{
156 char bt_target_name[BT_NAME_LEN];
157};
158
164{
170 char bt_target_name[BT_NAME_LEN];
171};
172
179{
180 uint8_t type;
181 uint8_t addr[BT_ADDR_LEN];
182};
183
190{
191 uint8_t irk[BLE_IRK_LEN];
192 uint8_t csrk[BLE_CSRK_LEN];
193 uint8_t ltk[BLE_LTK_LEN];
194 uint8_t rand[BLE_RAND_LEN];
195 uint16_t ediv;
196};
197
199{
200 uint16_t handle;
201 uint16_t value;
202};
203
210{
211 struct ble_addr_s peer_addr;
212 struct ble_idkey_s peer;
213 struct ble_idkey_s own;
214 uint8_t cccd_num;
215 struct ble_cccd_s *cccd;
216};
217
223{
226 void (*inquiry_result)(BT_ADDR addr, char *name);
227 void (*inquiry_complete)(void);
228 void (*connect_status_changed)(struct bt_acl_state_s *bt_acl_state, bool connected, int status);
229 void (*connected_device_name)(const char *name);
230 void (*bond_info)(BT_ADDR addr);
231};
232
238{
241 void (*connect_status_changed)(struct ble_state_s *ble_state,
242 bool connected,
243 uint8_t status);
244
247 void (*connected_device_name_resp)(const char *name);
248
251 void (*scan_result)(BT_ADDR addr, uint8_t *data, uint8_t len);
252
255 void (*mtusize)(uint16_t handle, uint16_t sz);
256
259 void (*save_bondinfo)(int num, struct ble_bondinfo_s *bond);
260
263 int (*load_bondinfo)(int num, struct ble_bondinfo_s *bond);
264
267 void (*encryption_result)(uint16_t conn_handle, bool result);
268
269};
270
277{
278 uint8_t len;
279 uint8_t type;
280 uint8_t data[BT_EIR_LEN];
281};
282
283#ifdef __cplusplus
284#define EXTERN extern "C"
285extern "C"
286{
287#else
288#define EXTERN extern
289#endif
290
291/****************************************************************************
292 * Public Function Prototypes
293 ****************************************************************************/
294
302int bt_init(void);
303
310int bt_finalize(void);
311
322
332
342int bt_set_name(char *name);
343
352int bt_get_name(char *name);
353
361int bt_enable(void);
362
370int bt_disable(void);
371
380
389
400int bt_get_bond_list(BT_ADDR *addr, int *num);
401
412
423
432
441
451int bt_register_common_cb(struct bt_common_ops_s *bt_common_ops);
452
463
473
483int ble_set_name(char *name);
484
493int ble_get_name(char *name);
494
501int ble_enable(void);
502
509int ble_disable(void);
510
519int ble_connect(struct ble_state_s *ble_state);
520
529int ble_disconnect(struct ble_state_s *ble_state);
530
539
548
558int ble_start_scan(bool duplicate_filter);
559
568
578int ble_register_common_cb(struct ble_common_ops_s *ble_common_ops);
579
588uint16_t ble_set_request_mtusize(uint16_t sz);
589
597
607int ble_get_negotiated_mtusize(uint16_t handle);
608
617int ble_pairing(uint16_t handle);
618
629 uint8_t *adv_data,
630 uint8_t adv_len,
631 struct bt_eir_s *eir);
632
633#undef EXTERN
634#ifdef __cplusplus
635}
636#endif
637
638#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_AD_TYPE
BLE data type of advertising data.
Definition: bluetooth.h:326
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_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.
int ble_get_address(BT_ADDR *addr)
Get Bluetooth LE module address.
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_disable(void)
Bluetooth LE disable.
int bt_set_address(BT_ADDR *addr)
Set Bluetooth module address This is Spresense side address and should be call 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 bt_paring_disable(void)
Bluetooth pairing disable Escaping bluetooth pairing mode.
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 This is Spresense side address and should be call before bt_enable.
int ble_set_name(char *name)
Set Bluetooth LE module name This name visible for other devices and should be call before bt_enable.
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 call 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:124
@ BT_DISCONNECTING
Definition: bt_common.h:126
@ BT_CONNECTED
Definition: bt_common.h:128
@ BT_CONNECTING
Definition: bt_common.h:127
@ BT_DISCONNECTED
Definition: bt_common.h:125
BT address types.
Definition: bluetooth.h:171
BLE address.
Definition: bt_common.h:179
Bluetooth LE bonding information.
Definition: bt_common.h:210
Definition: bt_common.h:199
Bluetooth LE Common application callbacks.
Definition: bt_common.h:238
void(* save_bondinfo)(int num, struct ble_bondinfo_s *bond)
Definition: bt_common.h:259
void(* connect_status_changed)(struct ble_state_s *ble_state, bool connected, uint8_t status)
Definition: bt_common.h:241
void(* connected_device_name_resp)(const char *name)
Definition: bt_common.h:247
int(* load_bondinfo)(int num, struct ble_bondinfo_s *bond)
Definition: bt_common.h:263
void(* encryption_result)(uint16_t conn_handle, bool result)
Definition: bt_common.h:267
void(* mtusize)(uint16_t handle, uint16_t sz)
Definition: bt_common.h:255
Bluetooth LE common HAL callbacks.
Definition: bt_if.h:139
Definition: bt_common.h:190
Bluetooth LE context.
Definition: bt_common.h:164
struct bt_common_state_s * bt_common_state
Definition: bt_common.h:167
BT_CONNECT_STATUS ble_connection
Definition: bt_common.h:165
uint8_t bt_target_addr_type
Definition: bt_common.h:168
BT_ADDR bt_target_addr
Definition: bt_common.h:169
uint16_t ble_connect_handle
Definition: bt_common.h:166
char bt_target_name[BT_NAME_LEN]
Definition: bt_common.h:170
Bluetooth ACL context.
Definition: bt_common.h:152
struct bt_common_state_s * bt_common_state
Definition: bt_common.h:154
BT_ADDR bt_target_addr
Definition: bt_common.h:155
BT_CONNECT_STATUS bt_acl_connection
Definition: bt_common.h:153
char bt_target_name[BT_NAME_LEN]
Definition: bt_common.h:156
Bluetooth Common application callbacks.
Definition: bt_common.h:223
void(* connected_device_name)(const char *name)
Definition: bt_common.h:229
void(* connect_status_changed)(struct bt_acl_state_s *bt_acl_state, bool connected, int status)
Definition: bt_common.h:228
void(* command_status)(BT_CMD_STATUS status)
Definition: bt_common.h:224
void(* bond_info)(BT_ADDR addr)
Definition: bt_common.h:230
void(* inquiry_complete)(void)
Definition: bt_common.h:227
void(* pairing_complete)(BT_ADDR addr, BT_PAIR_STATUS status)
Definition: bt_common.h:225
void(* inquiry_result)(BT_ADDR addr, char *name)
Definition: bt_common.h:226
Bluetooth base context.
Definition: bt_common.h:136
struct bt_hal_common_ops_s * bt_hal_common_ops
Definition: bt_common.h:137
struct bt_common_ops_s * bt_common_ops
Definition: bt_common.h:139
BT_ADDR bt_addr
Definition: bt_common.h:141
char bt_name[BT_NAME_LEN+1]
Definition: bt_common.h:143
char ble_name[BT_NAME_LEN+1]
Definition: bt_common.h:144
struct ble_common_ops_s * ble_common_ops
Definition: bt_common.h:140
BT_ADDR ble_addr
Definition: bt_common.h:142
struct ble_hal_common_ops_s * ble_hal_common_ops
Definition: bt_common.h:138
The format of one data in advertising data.
Definition: bt_common.h:277
Bluetooth Common HAL callbacks.
Definition: bt_if.h:70