0%

Connection Update

BLE connection upate 流程。

Connection Update Procedure

根据Core_4.0 | Vol 6, Part B, 5.1.1 Connection Update procedure

The Link Layer parameters for a connection (connInterval, connSlaveLatency and connSupervisionTimeout) may be updated after entering the Connection State. The master can update the connection parameters by sending an LL_CONNECTION_UPDATE_REQ PDU. The slave shall not send this PDU; the slave may request a change to the connection parameters using the L2CAP LE signaling channel.

Connection Parameters Request procedure

根据Core_5.2 | Vol 6, Part B, 5.1.7 Connection Parameters Request procedure

The master or slave may initiate a Connection Parameters Request procedure to request the remote device to have the Link Layer parameters for the connection (connInterval, connSlaveLatency and connSupervisionTimeout) updated any time after entering the Connection State.

Master 和 Slave 都可以发起 Connection Parameters Request procedure。

发起者发送LL_CONNECTION_PARAM_REQ,包含 Interval_Min 和 Interval_Max。

对端若是 maste,则回复LL_CONNECTION_UPDATE_IND,若是 slave,则回复 LL_CONNECTION_PARAM_RSP

若对端不接受参数更新请求,则回复二者之一:

  • 包含了替代参数的LL_CONNECTION_PARAM_RSP(slave)或者 LL_CONNECTION_UPDATE_IND PDU(master)
  • LL_REJECT_EXT_IND,其中ErrorCode 设置为Unsupported LL Parameter Value (0x20).

Slave 发送了LL_CONNECTION_PARAM_REQ,Interval Min = 20,Interval Max = 40,Master 在LL_CONNECTION_UPDATE_REQ中选择了 Interval = 40。

Zephyrbt_conn_le_create函数参数conn_param可以设置 connInterval。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/** @brief Initiate an LE connection to a remote device.
*
* Allows initiate new LE link to remote peer using its address.
*
* The caller gets a new reference to the connection object which must be
* released with bt_conn_unref() once done using the object.
*
* This uses the General Connection Establishment procedure.
*
* @param[in] peer Remote address.
* @param[in] create_param Create connection parameters.
* @param[in] conn_param Initial connection parameters.
* @param[out] conn Valid connection object on success.
*
* @return Zero on success or (negative) error code on failure.
*/
int bt_conn_le_create(const bt_addr_le_t *peer,
const struct bt_conn_le_create_param *create_param,
const struct bt_le_conn_param *conn_param,
struct bt_conn **conn);
1
2
3
4
5
6
7
8
9
10
11
/** Helper to declare connection parameters inline
*
* @param int_min Minimum Connection Interval (N * 1.25 ms)
* @param int_max Maximum Connection Interval (N * 1.25 ms)
* @param lat Connection Latency
* @param to Supervision Timeout (N * 10 ms)
*/
#define BT_LE_CONN_PARAM(int_min, int_max, lat, to) \
((struct bt_le_conn_param[]) { \
BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
})

区别

Connection Update ProcedureConnection Parameters Request procedure都实现了在连接后设置连接参数的功能(connInterval, connSlaveLatency and connSupervisionTimeout) ,那么它们有什么区别呢?

一开始在 BLE 4.0 中只有Connection Update Procedure,只能由 master 主动发起,slave 只能请求 master 发起更新,可能后来有 slave 主动发起更新的需求,又为了向后兼容,于是定义了新的Connection Parameters Request procedure,支持 slave 主动发起更新。

坚持原创技术分享,您的支持将鼓励我继续创作!