Bluetooth: Add bt_conn_enc_key_size function
This patch adds bt_conn_enc_key_size function which will be used by application to check encryption keys size of a encrypted connection. This will be used especialy by GATT applications, because some attributes to be accessed require encryption with specified minimum encryption key length. > ACL Data RX: Handle 64 flags 0x02 dlen 7 [hci0] 708547.536685 ATT: Read Request (0x0a) len 2 Handle: 0x0003 < ACL Data TX: Handle 64 flags 0x00 dlen 9 [hci0] 708547.544302 ATT: Error Response (0x01) len 4 Read Request (0x0a) Handle: 0x0003 Error: Insufficient Encryption Key Size (0x0c) Change-Id: Idbc9afde7ec80504898bd8d1e193f3e71a93f3f9 Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
parent
89cfd86f2f
commit
992237bc51
3 changed files with 18 additions and 0 deletions
|
@ -146,6 +146,17 @@ struct bt_conn_cb {
|
|||
*/
|
||||
void bt_conn_cb_register(struct bt_conn_cb *cb);
|
||||
|
||||
/** @brief Get encryption key size.
|
||||
*
|
||||
* This function gets encryption key size.
|
||||
* If there is no security (encryption) enabled 0 will be returned.
|
||||
*
|
||||
* @param conn Existing connection object.
|
||||
*
|
||||
* @return Encryption key size.
|
||||
*/
|
||||
uint8_t bt_conn_enc_key_size(struct bt_conn *conn);
|
||||
|
||||
#if defined(CONFIG_BLUETOOTH_CENTRAL)
|
||||
/** @brief Automatically connect to remote device if it's in range.
|
||||
*
|
||||
|
|
|
@ -628,6 +628,8 @@ static uint8_t err_to_att(int err)
|
|||
return BT_ATT_ERR_INVALID_OFFSET;
|
||||
case -EFBIG:
|
||||
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
|
||||
case -EACCES:
|
||||
return BT_ATT_ERR_ENCRYPTION_KEY_SIZE;
|
||||
default:
|
||||
return BT_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
|
|
@ -762,3 +762,8 @@ int bt_conn_le_conn_update(struct bt_conn *conn, uint16_t min, uint16_t max,
|
|||
|
||||
return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_UPDATE, buf);
|
||||
}
|
||||
|
||||
uint8_t bt_conn_enc_key_size(struct bt_conn *conn)
|
||||
{
|
||||
return conn->keys ? conn->keys->enc_size : 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue