2015-07-06 18:22:48 +08:00
|
|
|
/** @file
|
2015-06-15 16:05:35 +08:00
|
|
|
* @brief Internal APIs for Bluetooth connection handling.
|
|
|
|
*/
|
2015-04-28 15:39:50 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-28 15:39:50 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-28 15:39:50 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-28 15:39:50 +08:00
|
|
|
*/
|
|
|
|
|
2015-06-19 16:52:58 +08:00
|
|
|
typedef enum {
|
2015-04-28 15:39:50 +08:00
|
|
|
BT_CONN_DISCONNECTED,
|
2015-07-02 17:16:55 +08:00
|
|
|
BT_CONN_CONNECT_SCAN,
|
2015-06-19 17:18:34 +08:00
|
|
|
BT_CONN_CONNECT,
|
2015-04-28 15:39:50 +08:00
|
|
|
BT_CONN_CONNECTED,
|
2015-06-19 17:18:34 +08:00
|
|
|
BT_CONN_DISCONNECT,
|
2015-06-19 16:52:58 +08:00
|
|
|
} bt_conn_state_t;
|
2015-04-28 15:39:50 +08:00
|
|
|
|
2015-07-13 18:43:02 +08:00
|
|
|
/* bt_conn flags: the flags defined here represent connection parameters */
|
|
|
|
enum {
|
|
|
|
BT_CONN_AUTO_CONNECT,
|
|
|
|
};
|
|
|
|
|
2015-04-28 15:39:50 +08:00
|
|
|
struct bt_conn {
|
|
|
|
uint16_t handle;
|
2015-06-10 03:32:44 +08:00
|
|
|
uint8_t role;
|
2015-07-13 18:43:02 +08:00
|
|
|
atomic_t flags[1];
|
2015-04-28 15:39:50 +08:00
|
|
|
|
2015-05-25 14:13:33 +08:00
|
|
|
bt_addr_le_t dst;
|
2015-05-20 02:07:24 +08:00
|
|
|
|
2015-09-01 23:30:58 +08:00
|
|
|
bt_addr_le_t init_addr;
|
|
|
|
bt_addr_le_t resp_addr;
|
|
|
|
|
2015-09-15 22:19:45 +08:00
|
|
|
uint8_t pending_pkts;
|
|
|
|
|
2015-09-09 23:27:16 +08:00
|
|
|
#if defined(CONFIG_BLUETOOTH_SMP)
|
2015-05-22 02:00:50 +08:00
|
|
|
uint8_t encrypt;
|
2015-08-05 22:18:05 +08:00
|
|
|
bt_security_t sec_level;
|
|
|
|
bt_security_t required_sec_level;
|
2015-09-09 23:27:16 +08:00
|
|
|
#endif /* CONFIG_BLUETOOTH_SMP */
|
2015-05-22 02:00:50 +08:00
|
|
|
|
2015-04-28 15:39:50 +08:00
|
|
|
uint16_t rx_len;
|
|
|
|
struct bt_buf *rx;
|
|
|
|
|
|
|
|
/* Queue for outgoing ACL data */
|
|
|
|
struct nano_fifo tx_queue;
|
|
|
|
|
2015-06-01 01:17:48 +08:00
|
|
|
struct bt_keys *keys;
|
|
|
|
|
2015-10-02 21:21:18 +08:00
|
|
|
/* L2CAP channels */
|
|
|
|
void *channels;
|
2015-05-18 17:37:48 +08:00
|
|
|
|
2015-04-28 15:39:50 +08:00
|
|
|
uint8_t le_conn_interval;
|
|
|
|
|
2015-06-23 20:38:24 +08:00
|
|
|
atomic_t ref;
|
2015-04-28 15:39:50 +08:00
|
|
|
|
2015-06-19 16:52:58 +08:00
|
|
|
bt_conn_state_t state;
|
2015-04-28 15:39:50 +08:00
|
|
|
|
2015-07-17 19:11:53 +08:00
|
|
|
/* Handle allowing to cancel timeout fiber */
|
|
|
|
void *timeout;
|
|
|
|
|
2015-07-27 22:09:51 +08:00
|
|
|
uint8_t le_features[8];
|
|
|
|
|
2015-07-22 18:03:51 +08:00
|
|
|
/* Stack for TX fiber and timeout fiber.
|
|
|
|
* Since these fibers don't overlap, one stack can be used by
|
|
|
|
* both of them.
|
2015-07-17 19:11:53 +08:00
|
|
|
*/
|
|
|
|
BT_STACK(stack, 256);
|
2015-04-28 15:39:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Process incoming data for a connection */
|
|
|
|
void bt_conn_recv(struct bt_conn *conn, struct bt_buf *buf, uint8_t flags);
|
|
|
|
|
|
|
|
/* Send data over a connection */
|
|
|
|
void bt_conn_send(struct bt_conn *conn, struct bt_buf *buf);
|
|
|
|
|
|
|
|
/* Add a new connection */
|
2015-09-02 16:47:35 +08:00
|
|
|
struct bt_conn *bt_conn_add(const bt_addr_le_t *peer);
|
2015-04-28 15:39:50 +08:00
|
|
|
|
|
|
|
/* Look up an existing connection */
|
2015-05-28 02:08:39 +08:00
|
|
|
struct bt_conn *bt_conn_lookup_handle(uint16_t handle);
|
2015-06-19 16:52:58 +08:00
|
|
|
|
2015-06-25 17:31:17 +08:00
|
|
|
/* Look up a connection state. For BT_ADDR_LE_ANY, returns the first connection
|
|
|
|
* with the specific state
|
|
|
|
*/
|
|
|
|
struct bt_conn *bt_conn_lookup_state(const bt_addr_le_t *peer,
|
|
|
|
const bt_conn_state_t state);
|
|
|
|
|
2015-06-20 00:56:13 +08:00
|
|
|
/* Set connection object in certain state and perform action related to state */
|
2015-06-19 16:52:58 +08:00
|
|
|
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state);
|
2015-07-15 19:04:52 +08:00
|
|
|
|
2015-07-15 19:08:53 +08:00
|
|
|
int bt_conn_le_conn_update(struct bt_conn *conn, uint16_t min, uint16_t max,
|
|
|
|
uint16_t latency, uint16_t timeout);
|
2015-08-24 02:47:29 +08:00
|
|
|
|
2015-09-09 23:27:16 +08:00
|
|
|
#if defined(CONFIG_BLUETOOTH_SMP)
|
2015-10-02 18:39:11 +08:00
|
|
|
/* rand and ediv should be in BT order */
|
|
|
|
int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
|
2015-10-07 21:41:19 +08:00
|
|
|
uint16_t ediv, const uint8_t *ltk, size_t len);
|
2015-10-02 18:39:11 +08:00
|
|
|
|
2015-09-02 00:06:35 +08:00
|
|
|
/* Notify higher layers that RPA was resolved */
|
|
|
|
void bt_conn_identity_resolved(struct bt_conn *conn);
|
2015-09-02 00:16:54 +08:00
|
|
|
|
|
|
|
/* Notify higher layers that connection security changed */
|
|
|
|
void bt_conn_security_changed(struct bt_conn *conn);
|
2015-09-09 23:27:16 +08:00
|
|
|
#endif /* CONFIG_BLUETOOTH_SMP */
|