Bluetooth: Pass LTK length to bt_conn_le_start_encryption
This is in preparation for supporting different encryption key sizes. Change-Id: I36ed61a35fbe4988ce863127ae318c63f9298dd3 Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
parent
e8bc54d9d8
commit
36d5294f8c
3 changed files with 12 additions and 6 deletions
|
@ -121,7 +121,7 @@ void bt_conn_security_changed(struct bt_conn *conn)
|
|||
}
|
||||
|
||||
int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
|
||||
uint16_t ediv, const uint8_t *ltk)
|
||||
uint16_t ediv, const uint8_t *ltk, size_t len)
|
||||
{
|
||||
struct bt_hci_cp_le_start_encryption *cp;
|
||||
struct bt_buf *buf;
|
||||
|
@ -135,7 +135,11 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
|
|||
cp->handle = sys_cpu_to_le16(conn->handle);
|
||||
cp->rand = rand;
|
||||
cp->ediv = ediv;
|
||||
memcpy(cp->ltk, ltk, sizeof(cp->ltk));
|
||||
|
||||
memcpy(cp->ltk, ltk, len);
|
||||
if (len < sizeof(cp->ltk)) {
|
||||
memset(cp->ltk + len, 0, sizeof(cp->ltk) - len);
|
||||
}
|
||||
|
||||
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_START_ENCRYPTION, buf, NULL);
|
||||
}
|
||||
|
@ -174,7 +178,8 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
|
|||
|
||||
err = bt_conn_le_start_encryption(conn, keys->ltk.rand,
|
||||
keys->ltk.ediv,
|
||||
keys->ltk.val);
|
||||
keys->ltk.val,
|
||||
sizeof(keys->ltk.val));
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ int bt_conn_le_conn_update(struct bt_conn *conn, uint16_t min, uint16_t max,
|
|||
#if defined(CONFIG_BLUETOOTH_SMP)
|
||||
/* rand and ediv should be in BT order */
|
||||
int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand,
|
||||
uint16_t ediv, const uint8_t *ltk);
|
||||
uint16_t ediv, const uint8_t *ltk, size_t len);
|
||||
|
||||
/* Notify higher layers that RPA was resolved */
|
||||
void bt_conn_identity_resolved(struct bt_conn *conn);
|
||||
|
|
|
@ -930,7 +930,7 @@ static uint8_t smp_pairing_random(struct bt_conn *conn, struct bt_buf *buf)
|
|||
keys->type = get_keys_type(smp->method);
|
||||
|
||||
/* Rand and EDiv are 0 for the STK */
|
||||
if (bt_conn_le_start_encryption(conn, 0, 0, stk)) {
|
||||
if (bt_conn_le_start_encryption(conn, 0, 0, stk, sizeof(stk))) {
|
||||
BT_ERR("Failed to start encryption\n");
|
||||
return BT_SMP_ERR_UNSPECIFIED;
|
||||
}
|
||||
|
@ -1319,7 +1319,8 @@ static uint8_t smp_security_request(struct bt_conn *conn, struct bt_buf *buf)
|
|||
}
|
||||
|
||||
if (bt_conn_le_start_encryption(conn, keys->ltk.rand, keys->ltk.ediv,
|
||||
keys->ltk.val) < 0) {
|
||||
keys->ltk.val,
|
||||
sizeof(keys->ltk.val)) < 0) {
|
||||
return BT_SMP_ERR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue