Bluetooth: Refactor LE Connection Params validator
Move le_validate_conn_params() interface to internal HCI header to be commonly shared between HCI and L2CAP layers. Refactor the interface and its users and rename related to Connection Parameters Update procedure values used for validation. < ACL Data TX: Handle 42 flags 0x00 dlen 16 [hci1] 2832.387859 LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8 Min interval: 40 Max interval: 56 Slave latency: 0 Timeout multiplier: 0 @ Device Connected: 00:AA:01:00:00:23 (1) flags 0x0000 < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2 [hci0] 2832.389374 Handle: 42 > ACL Data RX: Handle 42 flags 0x02 dlen 16 [hci0] 2832.389437 LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8 Min interval: 40 Max interval: 56 Slave latency: 0 Timeout multiplier: 0 > HCI Event: Number of Completed Packets (0x13) plen 5 [hci1] 2832.389440 Num handles: 1 Handle: 42 Count: 1 > HCI Event: Command Status (0x0f) plen 4 [hci0] 2832.389443 LE Read Remote Used Features (0x08|0x0016) ncmd 1 Status: Success (0x00) > HCI Event: LE Meta Event (0x3e) plen 12 [hci0] 2832.389444 LE Read Remote Used Features (0x04) Status: Success (0x00) Handle: 42 Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 LE Encryption Connection Parameter Request Procedure < ACL Data TX: Handle 42 flags 0x00 dlen 10 [hci0] 2832.393154 LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2 Result: Connection Parameters rejected (0x0001) > ACL Data RX: Handle 42 flags 0x02 dlen 10 [hci1] 2832.393181 LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2 Result: Connection Parameters rejected (0x0001) Rejected due to Timeout multiplier: 0. Change-Id: Idaf4f452f560ff71d9637ec5d793154190e94b35 Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com> Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
parent
26124136b1
commit
134ae99d35
3 changed files with 37 additions and 32 deletions
|
@ -156,6 +156,30 @@ static inline bool bt_addr_le_is_identity(const bt_addr_le_t *addr)
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline bool bt_le_conn_params_valid(uint16_t min, uint16_t max,
|
||||
uint16_t latency, uint16_t timeout)
|
||||
{
|
||||
uint16_t max_latency;
|
||||
|
||||
if (min > max || min < 6 || max > 3200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (timeout < 10 || timeout > 3200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* calculation based on BT spec 4.2 [Vol3, PartA, 4.20]
|
||||
* max_latency = ((timeout * 10)/(max * 1.25 * 2)) - 1;
|
||||
*/
|
||||
max_latency = (timeout * 4 / max) - 1;
|
||||
if (latency > 499 || latency > max_latency) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len);
|
||||
int bt_hci_cmd_send(uint16_t opcode, struct bt_buf *buf);
|
||||
int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
|
||||
|
|
|
@ -52,9 +52,6 @@
|
|||
#define BT_DBG(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define BT_L2CAP_CONN_PARAM_ACCEPTED 0
|
||||
#define BT_L2CAP_CONN_PARAM_REJECTED 1
|
||||
|
||||
static struct bt_l2cap_chan *channels;
|
||||
|
||||
static uint8_t get_ident(struct bt_conn *conn)
|
||||
|
@ -166,34 +163,11 @@ static void le_conn_param_rsp(struct bt_conn *conn, struct bt_buf *buf)
|
|||
bt_conn_connected(conn);
|
||||
}
|
||||
|
||||
static uint16_t le_validate_conn_params(uint16_t min, uint16_t max,
|
||||
uint16_t latency, uint16_t timeout)
|
||||
{
|
||||
uint16_t max_latency;
|
||||
|
||||
if (min > max || min < 6 || max > 3200) {
|
||||
return BT_L2CAP_CONN_PARAM_REJECTED;
|
||||
}
|
||||
|
||||
if (timeout < 10 || timeout > 3200) {
|
||||
return BT_L2CAP_CONN_PARAM_REJECTED;
|
||||
}
|
||||
|
||||
/* calculation based on BT spec 4.2 [Vol3, PartA, 4.20]
|
||||
* max_latency = ((timeout * 10)/(max * 1.25 * 2)) - 1;
|
||||
*/
|
||||
max_latency = (timeout * 4 / max) - 1;
|
||||
if (latency > 499 || latency > max_latency) {
|
||||
return BT_L2CAP_CONN_PARAM_REJECTED;
|
||||
}
|
||||
|
||||
return BT_L2CAP_CONN_PARAM_ACCEPTED;
|
||||
}
|
||||
|
||||
static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident,
|
||||
struct bt_buf *buf)
|
||||
{
|
||||
uint16_t min, max, latency, timeout, result;
|
||||
uint16_t min, max, latency, timeout;
|
||||
bool params_valid;
|
||||
struct bt_l2cap_sig_hdr *hdr;
|
||||
struct bt_l2cap_conn_param_rsp *rsp;
|
||||
struct bt_l2cap_conn_param_req *req = (void *)buf->data;
|
||||
|
@ -221,7 +195,7 @@ static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident,
|
|||
return;
|
||||
}
|
||||
|
||||
result = le_validate_conn_params(min, max, latency, timeout);
|
||||
params_valid = bt_le_conn_params_valid(min, max, latency, timeout);
|
||||
|
||||
hdr = bt_buf_add(buf, sizeof(*hdr));
|
||||
hdr->code = BT_L2CAP_CONN_PARAM_RSP;
|
||||
|
@ -229,11 +203,15 @@ static void le_conn_param_update_req(struct bt_conn *conn, uint8_t ident,
|
|||
hdr->len = sys_cpu_to_le16(sizeof(*rsp));
|
||||
|
||||
rsp = bt_buf_add(buf, sizeof(*rsp));
|
||||
memset(rsp, 0, sizeof(*rsp));
|
||||
rsp->result = sys_cpu_to_le16(result);
|
||||
if (params_valid) {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_CONN_PARAM_ACCEPTED);
|
||||
} else {
|
||||
rsp->result = sys_cpu_to_le16(BT_L2CAP_CONN_PARAM_REJECTED);
|
||||
}
|
||||
|
||||
bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
|
||||
|
||||
if (result == BT_L2CAP_CONN_PARAM_ACCEPTED) {
|
||||
if (params_valid) {
|
||||
bt_conn_le_conn_update(conn, min, max, latency, timeout);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ struct bt_l2cap_conn_param_req {
|
|||
uint16_t timeout;
|
||||
} __packed;
|
||||
|
||||
#define BT_L2CAP_CONN_PARAM_ACCEPTED 0x0000
|
||||
#define BT_L2CAP_CONN_PARAM_REJECTED 0x0001
|
||||
|
||||
#define BT_L2CAP_CONN_PARAM_RSP 0x13
|
||||
struct bt_l2cap_conn_param_rsp {
|
||||
uint16_t result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue