diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index cf3278c7004..5d3cd36ce95 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1449,8 +1449,7 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer, { struct bt_conn *conn; - if (!bt_le_conn_params_valid(param->interval_min, param->interval_max, - param->latency, param->timeout)) { + if (!bt_le_conn_params_valid(param)) { return NULL; } @@ -1492,10 +1491,7 @@ int bt_le_set_auto_conn(bt_addr_le_t *addr, { struct bt_conn *conn; - if (param && !bt_le_conn_params_valid(param->interval_min, - param->interval_max, - param->latency, - param->timeout)) { + if (param && !bt_le_conn_params_valid(param)) { return -EINVAL; } diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 87fc699f887..3c2e7d3fc7f 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -784,21 +784,24 @@ static void le_remote_feat_complete(struct net_buf *buf) bt_conn_unref(conn); } -bool bt_le_conn_params_valid(uint16_t min, uint16_t max, - uint16_t latency, uint16_t timeout) +bool bt_le_conn_params_valid(const struct bt_le_conn_param *param) { - if (min > max || min < 6 || max > 3200) { + if (param->interval_min > param->interval_max || + param->interval_min < 6 || param->interval_max > 3200) { return false; } /* Limits according to BT Core spec 4.2 [Vol 2, Part E, 7.8.12] */ - if (timeout < 10 || timeout > 3200 || - (2 * timeout) < ((1 + latency) * max * 5)) { + if (param->timeout < 10 || param->timeout > 3200 || + ((2 * param->timeout) < + ((1 + param->latency) * param->interval_max * 5))) { return false; } /* Limits according to BT Core spec 4.2 [Vol 6, Part B, 4.5.1] */ - if (latency > 499 || ((latency + 1) * max) > (timeout * 4)) { + if (param->latency > 499 || + (((param->latency + 1) * param->interval_max) > + (param->timeout * 4))) { return false; } @@ -823,8 +826,8 @@ static int le_conn_param_neg_reply(uint16_t handle, uint8_t reason) return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, buf); } -static int le_conn_param_req_reply(uint16_t handle, uint16_t min, uint16_t max, - uint16_t latency, uint16_t timeout) +static int le_conn_param_req_reply(uint16_t handle, + const struct bt_le_conn_param *param) { struct bt_hci_cp_le_conn_param_req_reply *cp; struct net_buf *buf; @@ -838,10 +841,10 @@ static int le_conn_param_req_reply(uint16_t handle, uint16_t min, uint16_t max, memset(cp, 0, sizeof(*cp)); cp->handle = sys_cpu_to_le16(handle); - cp->interval_min = sys_cpu_to_le16(min); - cp->interval_max = sys_cpu_to_le16(max); - cp->latency = sys_cpu_to_le16(latency); - cp->timeout = sys_cpu_to_le16(timeout); + cp->interval_min = sys_cpu_to_le16(param->interval_min); + cp->interval_max = sys_cpu_to_le16(param->interval_max); + cp->latency = sys_cpu_to_le16(param->latency); + cp->timeout = sys_cpu_to_le16(param->timeout); return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY, buf); } @@ -849,14 +852,15 @@ static int le_conn_param_req_reply(uint16_t handle, uint16_t min, uint16_t max, static int le_conn_param_req(struct net_buf *buf) { struct bt_hci_evt_le_conn_param_req *evt = (void *)buf->data; + struct bt_le_conn_param param; struct bt_conn *conn; - uint16_t handle, min, max, latency, timeout; + uint16_t handle; handle = sys_le16_to_cpu(evt->handle); - min = sys_le16_to_cpu(evt->interval_min); - max = sys_le16_to_cpu(evt->interval_max); - latency = sys_le16_to_cpu(evt->latency); - timeout = sys_le16_to_cpu(evt->timeout); + param.interval_min = sys_le16_to_cpu(evt->interval_min); + param.interval_max = sys_le16_to_cpu(evt->interval_max); + param.latency = sys_le16_to_cpu(evt->latency); + param.timeout = sys_le16_to_cpu(evt->timeout); conn = bt_conn_lookup_handle(handle); if (!conn) { @@ -867,12 +871,12 @@ static int le_conn_param_req(struct net_buf *buf) bt_conn_unref(conn); - if (!bt_le_conn_params_valid(min, max, latency, timeout)) { + if (!bt_le_conn_params_valid(¶m)) { return le_conn_param_neg_reply(handle, BT_HCI_ERR_INVALID_LL_PARAMS); } - return le_conn_param_req_reply(handle, min, max, latency, timeout); + return le_conn_param_req_reply(handle, ¶m); } static void le_conn_update_complete(struct net_buf *buf) diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index 15264fcc3d1..4e54fa78f3d 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -142,8 +142,7 @@ extern const struct bt_storage *bt_storage; extern const struct bt_conn_auth_cb *bt_auth; #endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */ -bool bt_le_conn_params_valid(uint16_t min, uint16_t max, - uint16_t latency, uint16_t timeout); +bool bt_le_conn_params_valid(const struct bt_le_conn_param *param); struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len); int bt_hci_cmd_send(uint16_t opcode, struct net_buf *buf); diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index eea18e98d2f..6b04accd321 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 22b8b8a4645..7ec85f349d3 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -553,8 +553,7 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, uint8_t ident, struct net_buf *buf) { struct bt_conn *conn = l2cap->chan.chan.conn; - const struct bt_le_conn_param *param; - uint16_t min, max, latency, timeout; + struct bt_le_conn_param param; bool params_valid; struct bt_l2cap_conn_param_rsp *rsp; struct bt_l2cap_conn_param_req *req = (void *)buf->data; @@ -570,14 +569,14 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, uint8_t ident, return; } - min = sys_le16_to_cpu(req->min_interval); - max = sys_le16_to_cpu(req->max_interval); - latency = sys_le16_to_cpu(req->latency); - timeout = sys_le16_to_cpu(req->timeout); - param = BT_LE_CONN_PARAM(min, max, latency, timeout); + param.interval_min = sys_le16_to_cpu(req->min_interval); + param.interval_max = sys_le16_to_cpu(req->max_interval); + param.latency = sys_le16_to_cpu(req->latency); + param.timeout = sys_le16_to_cpu(req->timeout); BT_DBG("min 0x%04x max 0x%04x latency: 0x%04x timeout: 0x%04x", - min, max, latency, timeout); + param.interval_min, param.interval_max, param.latency, + param.timeout); buf = l2cap_create_le_sig_pdu(BT_L2CAP_CONN_PARAM_RSP, ident, sizeof(*rsp)); @@ -585,7 +584,7 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, uint8_t ident, return; } - params_valid = bt_le_conn_params_valid(min, max, latency, timeout); + params_valid = bt_le_conn_params_valid(¶m); rsp = net_buf_add(buf, sizeof(*rsp)); if (params_valid) { @@ -597,7 +596,7 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, uint8_t ident, bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf); if (params_valid) { - bt_conn_le_conn_update(conn, param); + bt_conn_le_conn_update(conn, ¶m); } } #endif /* CONFIG_BLUETOOTH_CENTRAL */