2015-07-06 12:22:48 +02:00
|
|
|
/** @file
|
2015-06-15 10:05:35 +02:00
|
|
|
* @brief Internal APIs for Bluetooth connection handling.
|
|
|
|
*/
|
2015-04-28 09:39:50 +02:00
|
|
|
|
|
|
|
/*
|
2016-05-23 15:17:20 +02:00
|
|
|
* Copyright (c) 2015 Intel Corporation
|
2015-04-28 09:39:50 +02:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-28 09:39:50 +02:00
|
|
|
*/
|
2016-01-14 09:18:00 +01:00
|
|
|
typedef enum __packed {
|
2015-04-28 09:39:50 +02:00
|
|
|
BT_CONN_DISCONNECTED,
|
2020-06-03 14:48:04 +02:00
|
|
|
BT_CONN_DISCONNECT_COMPLETE,
|
2015-07-02 11:16:55 +02:00
|
|
|
BT_CONN_CONNECT_SCAN,
|
2020-01-07 12:40:30 +01:00
|
|
|
BT_CONN_CONNECT_AUTO,
|
2020-01-07 14:16:49 +01:00
|
|
|
BT_CONN_CONNECT_ADV,
|
2018-08-20 14:44:42 +02:00
|
|
|
BT_CONN_CONNECT_DIR_ADV,
|
2015-06-19 11:18:34 +02:00
|
|
|
BT_CONN_CONNECT,
|
2015-04-28 09:39:50 +02:00
|
|
|
BT_CONN_CONNECTED,
|
2015-06-19 11:18:34 +02:00
|
|
|
BT_CONN_DISCONNECT,
|
2015-06-19 10:52:58 +02:00
|
|
|
} bt_conn_state_t;
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2015-07-13 12:43:02 +02:00
|
|
|
/* bt_conn flags: the flags defined here represent connection parameters */
|
|
|
|
enum {
|
|
|
|
BT_CONN_AUTO_CONNECT,
|
2016-01-20 13:00:58 +01:00
|
|
|
BT_CONN_BR_LEGACY_SECURE, /* 16 digits legacy PIN tracker */
|
2016-01-13 15:34:19 +01:00
|
|
|
BT_CONN_USER, /* user I/O when pairing */
|
2016-02-19 12:16:38 +01:00
|
|
|
BT_CONN_BR_PAIRING, /* BR connection in pairing context */
|
2016-03-04 14:50:29 +01:00
|
|
|
BT_CONN_BR_NOBOND, /* SSP no bond pairing tracker */
|
2016-03-18 14:13:23 +01:00
|
|
|
BT_CONN_BR_PAIRING_INITIATOR, /* local host starts authentication */
|
2017-02-10 07:49:19 +01:00
|
|
|
BT_CONN_CLEANUP, /* Disconnected, pending cleanup */
|
2017-05-19 05:01:43 +02:00
|
|
|
BT_CONN_AUTO_PHY_UPDATE, /* Auto-update PHY */
|
2018-09-24 08:18:57 +02:00
|
|
|
BT_CONN_SLAVE_PARAM_UPDATE, /* If slave param update timer fired */
|
2018-09-24 11:20:20 +02:00
|
|
|
BT_CONN_SLAVE_PARAM_SET, /* If slave param were set from app */
|
2018-11-06 13:48:07 +01:00
|
|
|
BT_CONN_SLAVE_PARAM_L2CAP, /* If should force L2CAP for CPUP */
|
2019-08-21 10:51:14 +02:00
|
|
|
BT_CONN_FORCE_PAIR, /* Pairing even with existing keys. */
|
2016-07-26 19:28:06 +02:00
|
|
|
|
2019-12-12 14:28:44 +01:00
|
|
|
BT_CONN_AUTO_PHY_COMPLETE, /* Auto-initiated PHY procedure done */
|
|
|
|
BT_CONN_AUTO_FEATURE_EXCH, /* Auto-initiated LE Feat done */
|
2019-09-27 14:53:40 +02:00
|
|
|
BT_CONN_AUTO_VERSION_INFO, /* Auto-initiated LE version done */
|
2020-04-22 20:28:48 +02:00
|
|
|
BT_CONN_AUTO_DATA_LEN_COMPLETE, /* Auto-initiated Data Length done */
|
2019-12-12 14:28:44 +01:00
|
|
|
|
2016-07-26 19:28:06 +02:00
|
|
|
/* Total number of flags - must be at the end of the enum */
|
|
|
|
BT_CONN_NUM_FLAGS,
|
2015-07-13 12:43:02 +02:00
|
|
|
};
|
|
|
|
|
2015-11-03 12:19:01 +01:00
|
|
|
struct bt_conn_le {
|
2015-05-25 08:13:33 +02:00
|
|
|
bt_addr_le_t dst;
|
2015-05-19 20:07:24 +02:00
|
|
|
|
2015-09-01 17:30:58 +02:00
|
|
|
bt_addr_le_t init_addr;
|
|
|
|
bt_addr_le_t resp_addr;
|
2015-12-05 14:32:58 +01:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t interval;
|
|
|
|
uint16_t interval_min;
|
|
|
|
uint16_t interval_max;
|
2015-12-05 14:32:58 +01:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t latency;
|
|
|
|
uint16_t timeout;
|
|
|
|
uint16_t pending_latency;
|
|
|
|
uint16_t pending_timeout;
|
2015-12-05 20:39:44 +01:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t features[8];
|
2016-05-23 15:17:20 +02:00
|
|
|
|
2016-08-08 16:40:30 +02:00
|
|
|
struct bt_keys *keys;
|
2020-04-22 20:37:55 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_BT_USER_PHY_UPDATE)
|
|
|
|
struct bt_conn_le_phy_info phy;
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 20:28:48 +02:00
|
|
|
#if defined(CONFIG_BT_USER_DATA_LEN_UPDATE)
|
|
|
|
struct bt_conn_le_data_len_info data_len;
|
|
|
|
#endif
|
2015-11-03 12:19:01 +01:00
|
|
|
};
|
|
|
|
|
2017-08-09 08:21:11 +02:00
|
|
|
#if defined(CONFIG_BT_BREDR)
|
2016-06-17 21:27:41 +02:00
|
|
|
/* For now reserve space for 2 pages of LMP remote features */
|
|
|
|
#define LMP_MAX_PAGES 2
|
|
|
|
|
2015-11-03 12:19:01 +01:00
|
|
|
struct bt_conn_br {
|
2015-11-25 11:51:25 +01:00
|
|
|
bt_addr_t dst;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t remote_io_capa;
|
|
|
|
uint8_t remote_auth;
|
|
|
|
uint8_t pairing_method;
|
2016-06-17 21:27:41 +02:00
|
|
|
/* remote LMP features pages per 8 bytes each */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t features[LMP_MAX_PAGES][8];
|
2016-08-08 16:40:30 +02:00
|
|
|
|
|
|
|
struct bt_keys_link_key *link_key;
|
2015-11-03 12:19:01 +01:00
|
|
|
};
|
Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask
> HCI Event: Connect Request (0x04) plen 10 [hci0] 126.198264
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Class: 0x7a020c
Major class: Phone (cellular, cordless, payphone, modem)
Minor class: Smart phone
Networking (LAN, Ad hoc)
Capturing (Scanner, Microphone)
Object Transfer (v-Inbox, v-Folder)
Audio (Speaker, Microphone, Headset)
Telephony (Cordless telephony, Modem, Headset)
Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 7
Setting: 0x0060
Input Coding: Linear
Input Data Format: 2's complement
Input Sample Size: 16-bit
# of bits padding at MSB: 0
Air Coding Format: CVSD
Retransmission effort: Optimize for power consumption (0x01)
Packet type: 0x0006
HV2 may be used
HV3 may be used
> HCI Event: Command Status (0x0f) plen 4 [hci0] 126.205171
Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
Status: Success (0x00)
Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-15 09:59:11 +01:00
|
|
|
|
|
|
|
struct bt_conn_sco {
|
|
|
|
/* Reference to ACL Connection */
|
2017-03-16 09:13:15 +01:00
|
|
|
struct bt_conn *acl;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t pkt_type;
|
Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask
> HCI Event: Connect Request (0x04) plen 10 [hci0] 126.198264
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Class: 0x7a020c
Major class: Phone (cellular, cordless, payphone, modem)
Minor class: Smart phone
Networking (LAN, Ad hoc)
Capturing (Scanner, Microphone)
Object Transfer (v-Inbox, v-Folder)
Audio (Speaker, Microphone, Headset)
Telephony (Cordless telephony, Modem, Headset)
Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 7
Setting: 0x0060
Input Coding: Linear
Input Data Format: 2's complement
Input Sample Size: 16-bit
# of bits padding at MSB: 0
Air Coding Format: CVSD
Retransmission effort: Optimize for power consumption (0x01)
Packet type: 0x0006
HV2 may be used
HV3 may be used
> HCI Event: Command Status (0x0f) plen 4 [hci0] 126.205171
Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
Status: Success (0x00)
Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-15 09:59:11 +01:00
|
|
|
};
|
2015-11-18 15:57:58 +01:00
|
|
|
#endif
|
2015-11-03 12:19:01 +01:00
|
|
|
|
2019-05-21 13:52:16 +02:00
|
|
|
typedef void (*bt_conn_tx_cb_t)(struct bt_conn *conn, void *user_data);
|
|
|
|
|
2017-03-17 07:02:57 +01:00
|
|
|
struct bt_conn_tx {
|
2019-11-28 13:11:57 +01:00
|
|
|
sys_snode_t node;
|
|
|
|
|
2019-11-22 23:08:46 +01:00
|
|
|
bt_conn_tx_cb_t cb;
|
|
|
|
void *user_data;
|
|
|
|
|
|
|
|
/* Number of pending packets without a callback after this one */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t pending_no_cb;
|
2017-03-17 07:02:57 +01:00
|
|
|
};
|
|
|
|
|
2015-11-03 12:19:01 +01:00
|
|
|
struct bt_conn {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t handle;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t role;
|
2016-07-26 19:28:06 +02:00
|
|
|
|
|
|
|
ATOMIC_DEFINE(flags, BT_CONN_NUM_FLAGS);
|
2015-09-01 17:30:58 +02:00
|
|
|
|
2018-07-04 11:58:10 +02:00
|
|
|
/* Which local identity address this connection uses */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t id;
|
2018-07-04 11:58:10 +02:00
|
|
|
|
2017-08-09 08:21:11 +02:00
|
|
|
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
2015-08-05 16:18:05 +02:00
|
|
|
bt_security_t sec_level;
|
|
|
|
bt_security_t required_sec_level;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t encrypt;
|
2017-08-09 08:21:11 +02:00
|
|
|
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
|
2015-05-21 20:00:50 +02:00
|
|
|
|
2017-07-04 21:03:58 +02:00
|
|
|
/* Connection error or reason for disconnect */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t err;
|
2017-07-04 21:03:58 +02:00
|
|
|
|
|
|
|
bt_conn_state_t state;
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t rx_len;
|
2015-10-28 09:39:02 +01:00
|
|
|
struct net_buf *rx;
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2019-11-22 23:08:46 +01:00
|
|
|
/* Sent but not acknowledged TX packets with a callback */
|
2017-03-17 07:02:57 +01:00
|
|
|
sys_slist_t tx_pending;
|
2019-11-22 23:08:46 +01:00
|
|
|
/* Sent but not acknowledged TX packets without a callback before
|
|
|
|
* the next packet (if any) in tx_pending.
|
|
|
|
*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t pending_no_cb;
|
2017-03-17 07:02:57 +01:00
|
|
|
|
2019-11-28 13:11:57 +01:00
|
|
|
/* Completed TX for which we need to call the callback */
|
|
|
|
sys_slist_t tx_complete;
|
|
|
|
struct k_work tx_complete_work;
|
|
|
|
|
|
|
|
|
2015-04-28 09:39:50 +02:00
|
|
|
/* Queue for outgoing ACL data */
|
2016-11-10 10:45:10 +01:00
|
|
|
struct k_fifo tx_queue;
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2017-03-17 09:09:06 +01:00
|
|
|
/* Active L2CAP channels */
|
2017-03-21 14:48:03 +01:00
|
|
|
sys_slist_t channels;
|
2015-05-18 11:37:48 +02:00
|
|
|
|
2015-06-23 14:38:24 +02:00
|
|
|
atomic_t ref;
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2019-06-17 18:26:47 +02:00
|
|
|
/* Delayed work for connection update and other deferred tasks */
|
|
|
|
struct k_delayed_work update_work;
|
|
|
|
|
2015-11-03 12:19:01 +01:00
|
|
|
union {
|
|
|
|
struct bt_conn_le le;
|
2017-08-09 08:21:11 +02:00
|
|
|
#if defined(CONFIG_BT_BREDR)
|
2015-11-03 12:19:01 +01:00
|
|
|
struct bt_conn_br br;
|
Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask
> HCI Event: Connect Request (0x04) plen 10 [hci0] 126.198264
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Class: 0x7a020c
Major class: Phone (cellular, cordless, payphone, modem)
Minor class: Smart phone
Networking (LAN, Ad hoc)
Capturing (Scanner, Microphone)
Object Transfer (v-Inbox, v-Folder)
Audio (Speaker, Microphone, Headset)
Telephony (Cordless telephony, Modem, Headset)
Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 7
Setting: 0x0060
Input Coding: Linear
Input Data Format: 2's complement
Input Sample Size: 16-bit
# of bits padding at MSB: 0
Air Coding Format: CVSD
Retransmission effort: Optimize for power consumption (0x01)
Packet type: 0x0006
HV2 may be used
HV3 may be used
> HCI Event: Command Status (0x0f) plen 4 [hci0] 126.205171
Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
Status: Success (0x00)
Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-15 09:59:11 +01:00
|
|
|
struct bt_conn_sco sco;
|
2015-11-18 15:57:58 +01:00
|
|
|
#endif
|
2015-11-03 12:19:01 +01:00
|
|
|
};
|
2019-09-27 14:53:40 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_BT_REMOTE_VERSION)
|
|
|
|
struct bt_conn_rv {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t version;
|
|
|
|
uint16_t manufacturer;
|
|
|
|
uint16_t subversion;
|
2019-09-27 14:53:40 +02:00
|
|
|
} rv;
|
|
|
|
#endif
|
2015-04-28 09:39:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Process incoming data for a connection */
|
2020-05-27 18:26:57 +02:00
|
|
|
void bt_conn_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags);
|
2015-04-28 09:39:50 +02:00
|
|
|
|
|
|
|
/* Send data over a connection */
|
2017-03-17 07:02:57 +01:00
|
|
|
int bt_conn_send_cb(struct bt_conn *conn, struct net_buf *buf,
|
2019-05-21 13:52:16 +02:00
|
|
|
bt_conn_tx_cb_t cb, void *user_data);
|
2017-03-17 07:02:57 +01:00
|
|
|
|
|
|
|
static inline int bt_conn_send(struct bt_conn *conn, struct net_buf *buf)
|
|
|
|
{
|
2019-05-21 13:52:16 +02:00
|
|
|
return bt_conn_send_cb(conn, buf, NULL, NULL);
|
2017-03-17 07:02:57 +01:00
|
|
|
}
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2020-04-09 20:06:02 +02:00
|
|
|
/* Check if a connection object with the peer already exists */
|
2020-05-27 18:26:57 +02:00
|
|
|
bool bt_conn_exists_le(uint8_t id, const bt_addr_le_t *peer);
|
2020-04-09 20:06:02 +02:00
|
|
|
|
2015-11-25 10:48:33 +01:00
|
|
|
/* Add a new LE connection */
|
2020-05-27 18:26:57 +02:00
|
|
|
struct bt_conn *bt_conn_add_le(uint8_t id, const bt_addr_le_t *peer);
|
2015-04-28 09:39:50 +02:00
|
|
|
|
2015-11-25 11:51:25 +01:00
|
|
|
/* Add a new BR/EDR connection */
|
|
|
|
struct bt_conn *bt_conn_add_br(const bt_addr_t *peer);
|
2015-12-03 17:05:51 +01:00
|
|
|
|
Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask
> HCI Event: Connect Request (0x04) plen 10 [hci0] 126.198264
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Class: 0x7a020c
Major class: Phone (cellular, cordless, payphone, modem)
Minor class: Smart phone
Networking (LAN, Ad hoc)
Capturing (Scanner, Microphone)
Object Transfer (v-Inbox, v-Folder)
Audio (Speaker, Microphone, Headset)
Telephony (Cordless telephony, Modem, Headset)
Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 7
Setting: 0x0060
Input Coding: Linear
Input Data Format: 2's complement
Input Sample Size: 16-bit
# of bits padding at MSB: 0
Air Coding Format: CVSD
Retransmission effort: Optimize for power consumption (0x01)
Packet type: 0x0006
HV2 may be used
HV3 may be used
> HCI Event: Command Status (0x0f) plen 4 [hci0] 126.205171
Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
Status: Success (0x00)
Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-15 09:59:11 +01:00
|
|
|
/* Add a new SCO connection */
|
|
|
|
struct bt_conn *bt_conn_add_sco(const bt_addr_t *peer, int link_type);
|
|
|
|
|
2017-02-15 10:48:13 +01:00
|
|
|
/* Cleanup SCO references */
|
|
|
|
void bt_sco_cleanup(struct bt_conn *sco_conn);
|
|
|
|
|
2017-02-15 10:38:25 +01:00
|
|
|
/* Look up an existing sco connection by BT address */
|
|
|
|
struct bt_conn *bt_conn_lookup_addr_sco(const bt_addr_t *peer);
|
|
|
|
|
2015-12-03 17:05:51 +01:00
|
|
|
/* Look up an existing connection by BT address */
|
|
|
|
struct bt_conn *bt_conn_lookup_addr_br(const bt_addr_t *peer);
|
2016-01-14 16:32:53 +01:00
|
|
|
|
|
|
|
void bt_conn_pin_code_req(struct bt_conn *conn);
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t bt_conn_get_io_capa(void);
|
|
|
|
uint8_t bt_conn_ssp_get_auth(const struct bt_conn *conn);
|
|
|
|
void bt_conn_ssp_auth(struct bt_conn *conn, uint32_t passkey);
|
|
|
|
void bt_conn_ssp_auth_complete(struct bt_conn *conn, uint8_t status);
|
2015-11-25 11:51:25 +01:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void bt_conn_disconnect_all(uint8_t id);
|
2016-11-04 20:34:05 +01:00
|
|
|
|
2015-04-28 09:39:50 +02:00
|
|
|
/* Look up an existing connection */
|
2020-05-27 18:26:57 +02:00
|
|
|
struct bt_conn *bt_conn_lookup_handle(uint16_t handle);
|
2015-06-19 10:52:58 +02:00
|
|
|
|
2020-06-03 14:48:04 +02:00
|
|
|
static inline bool bt_conn_is_handle_valid(struct bt_conn *conn)
|
|
|
|
{
|
|
|
|
return conn->state == BT_CONN_CONNECTED ||
|
|
|
|
conn->state == BT_CONN_DISCONNECT ||
|
|
|
|
conn->state == BT_CONN_DISCONNECT_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:48:53 +01:00
|
|
|
/* Check if the connection is with the given peer. */
|
2020-05-27 18:26:57 +02:00
|
|
|
bool bt_conn_is_peer_addr_le(const struct bt_conn *conn, uint8_t id,
|
2020-02-19 18:48:53 +01:00
|
|
|
const bt_addr_le_t *peer);
|
2017-10-12 13:02:29 +02:00
|
|
|
|
|
|
|
/* Helpers for identifying & looking up connections based on the the index to
|
|
|
|
* the connection list. This is useful for O(1) lookups, but can't be used
|
|
|
|
* e.g. as the handle since that's assigned to us by the controller.
|
|
|
|
*/
|
2020-02-19 17:52:38 +01:00
|
|
|
#define BT_CONN_INDEX_INVALID 0xff
|
2020-05-27 18:26:57 +02:00
|
|
|
struct bt_conn *bt_conn_lookup_index(uint8_t index);
|
2017-10-12 13:02:29 +02:00
|
|
|
|
2016-05-23 15:17:20 +02:00
|
|
|
/* Look up a connection state. For BT_ADDR_LE_ANY, returns the first connection
|
2015-06-25 11:31:17 +02:00
|
|
|
* with the specific state
|
|
|
|
*/
|
2020-05-27 18:26:57 +02:00
|
|
|
struct bt_conn *bt_conn_lookup_state_le(uint8_t id, const bt_addr_le_t *peer,
|
2015-12-07 09:45:41 +01:00
|
|
|
const bt_conn_state_t state);
|
2015-06-25 11:31:17 +02:00
|
|
|
|
2015-06-19 18:56:13 +02:00
|
|
|
/* Set connection object in certain state and perform action related to state */
|
2015-06-19 10:52:58 +02:00
|
|
|
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state);
|
2015-07-15 13:04:52 +02:00
|
|
|
|
2016-02-02 12:48:42 +01:00
|
|
|
int bt_conn_le_conn_update(struct bt_conn *conn,
|
|
|
|
const struct bt_le_conn_param *param);
|
|
|
|
|
2019-09-27 14:53:40 +02:00
|
|
|
void notify_remote_info(struct bt_conn *conn);
|
|
|
|
|
2016-02-02 12:48:42 +01:00
|
|
|
void notify_le_param_updated(struct bt_conn *conn);
|
2015-08-23 20:47:29 +02:00
|
|
|
|
2020-04-22 20:28:48 +02:00
|
|
|
void notify_le_data_len_updated(struct bt_conn *conn);
|
|
|
|
|
2020-04-22 20:37:55 +02:00
|
|
|
void notify_le_phy_updated(struct bt_conn *conn);
|
|
|
|
|
2017-01-16 12:26:53 +01:00
|
|
|
bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param);
|
|
|
|
|
2017-08-09 08:21:11 +02:00
|
|
|
#if defined(CONFIG_BT_SMP)
|
2015-10-02 12:39:11 +02:00
|
|
|
/* rand and ediv should be in BT order */
|
2020-05-27 18:26:57 +02:00
|
|
|
int bt_conn_le_start_encryption(struct bt_conn *conn, uint8_t rand[8],
|
|
|
|
uint8_t ediv[2], const uint8_t *ltk, size_t len);
|
2015-10-02 12:39:11 +02:00
|
|
|
|
2015-09-01 18:06:35 +02:00
|
|
|
/* Notify higher layers that RPA was resolved */
|
|
|
|
void bt_conn_identity_resolved(struct bt_conn *conn);
|
2017-08-09 08:21:11 +02:00
|
|
|
#endif /* CONFIG_BT_SMP */
|
2015-09-01 18:16:54 +02:00
|
|
|
|
2017-08-09 08:21:11 +02:00
|
|
|
#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)
|
2015-09-01 18:16:54 +02:00
|
|
|
/* Notify higher layers that connection security changed */
|
2019-08-19 16:20:59 +02:00
|
|
|
void bt_conn_security_changed(struct bt_conn *conn, enum bt_security_err err);
|
2017-08-09 08:21:11 +02:00
|
|
|
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
|
2015-11-03 16:15:40 +01:00
|
|
|
|
2015-11-05 14:46:25 +01:00
|
|
|
/* Prepare a PDU to be sent over a connection */
|
2019-11-14 15:07:00 +01:00
|
|
|
#if defined(CONFIG_NET_BUF_LOG)
|
|
|
|
struct net_buf *bt_conn_create_pdu_timeout_debug(struct net_buf_pool *pool,
|
2020-04-06 13:33:41 +02:00
|
|
|
size_t reserve,
|
|
|
|
k_timeout_t timeout,
|
2019-11-14 15:07:00 +01:00
|
|
|
const char *func, int line);
|
|
|
|
#define bt_conn_create_pdu_timeout(_pool, _reserve, _timeout) \
|
|
|
|
bt_conn_create_pdu_timeout_debug(_pool, _reserve, _timeout, \
|
|
|
|
__func__, __LINE__)
|
|
|
|
|
|
|
|
#define bt_conn_create_pdu(_pool, _reserve) \
|
|
|
|
bt_conn_create_pdu_timeout_debug(_pool, _reserve, K_FOREVER, \
|
|
|
|
__func__, __line__)
|
|
|
|
#else
|
2019-08-27 13:23:54 +02:00
|
|
|
struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
|
2020-04-06 13:33:41 +02:00
|
|
|
size_t reserve, k_timeout_t timeout);
|
2019-08-27 13:23:54 +02:00
|
|
|
|
|
|
|
#define bt_conn_create_pdu(_pool, _reserve) \
|
|
|
|
bt_conn_create_pdu_timeout(_pool, _reserve, K_FOREVER)
|
2019-11-14 15:07:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Prepare a PDU to be sent over a connection */
|
|
|
|
#if defined(CONFIG_NET_BUF_LOG)
|
2020-04-06 13:33:41 +02:00
|
|
|
struct net_buf *bt_conn_create_frag_timeout_debug(size_t reserve,
|
|
|
|
k_timeout_t timeout,
|
2019-11-14 15:07:00 +01:00
|
|
|
const char *func, int line);
|
|
|
|
|
|
|
|
#define bt_conn_create_frag_timeout(_reserve, _timeout) \
|
|
|
|
bt_conn_create_frag_timeout_debug(_reserve, _timeout, \
|
|
|
|
__func__, __LINE__)
|
|
|
|
|
|
|
|
#define bt_conn_create_frag(_reserve) \
|
|
|
|
bt_conn_create_frag_timeout_debug(_reserve, K_FOREVER, \
|
|
|
|
__func__, __LINE__)
|
|
|
|
#else
|
2020-04-06 13:33:41 +02:00
|
|
|
struct net_buf *bt_conn_create_frag_timeout(size_t reserve,
|
|
|
|
k_timeout_t timeout);
|
2019-11-14 15:07:00 +01:00
|
|
|
|
|
|
|
#define bt_conn_create_frag(_reserve) \
|
|
|
|
bt_conn_create_frag_timeout(_reserve, K_FOREVER)
|
|
|
|
#endif
|
2015-11-05 14:46:25 +01:00
|
|
|
|
2015-11-03 16:15:40 +01:00
|
|
|
/* Initialize connection management */
|
|
|
|
int bt_conn_init(void);
|
|
|
|
|
2015-11-19 12:01:58 +01:00
|
|
|
/* Selects based on connecton type right semaphore for ACL packets */
|
2017-03-19 12:35:09 +01:00
|
|
|
struct k_sem *bt_conn_get_pkts(struct bt_conn *conn);
|
2017-02-02 13:39:28 +01:00
|
|
|
|
|
|
|
/* k_poll related helpers for the TX thread */
|
|
|
|
int bt_conn_prepare_events(struct k_poll_event events[]);
|
|
|
|
void bt_conn_process_tx(struct bt_conn *conn);
|