mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-13 05:51:57 +00:00
This allows to pair with devices that use reduced encryption key size. Encryption key size is stored with keys for future use. LTKs are kept in full form (16 bytes) and are reduced only when used. As master: < ACL Data TX: Handle 64 flags 0x00 dlen 11 SMP: Pairing Request (0x01) len 6 IO capability: NoInputNoOutput (0x03) OOB data: Authentication data not present (0x00) Authentication requirement: Bonding, No MITM, Legacy, No Keypresses (0x01) Max encryption key size: 16 Initiator key distribution: EncKey Sign (0x05) Responder key distribution: EncKey IdKey Sign (0x07) > ACL Data RX: Handle 64 flags 0x02 dlen 11 SMP: Pairing Response (0x02) len 6 IO capability: KeyboardDisplay (0x04) OOB data: Authentication data not present (0x00) Authentication requirement: No bonding, No MITM, Legacy, No Keypresses (0x00) Max encryption key size: 7 Initiator key distribution: <none> (0x00) Responder key distribution: <none> (0x00) ... < HCI Command: LE Start Encryption (0x08|0x0019) plen 28 Handle: 64 Random number: 0x0000000000000000 Encrypted diversifier: 0x0000 Long term key: df3cff52a981d6000000000000000000 As slave: > ACL Data RX: Handle 64 flags 0x02 dlen 11 SMP: Pairing Request (0x01) len 6 IO capability: KeyboardDisplay (0x04) OOB data: Authentication data not present (0x00) Authentication requirement: No bonding, No MITM, Legacy, No Keypresses (0x00) Max encryption key size: 7 Initiator key distribution: <none> (0x00) Responder key distribution: <none> (0x00) < ACL Data TX: Handle 64 flags 0x00 dlen 11 SMP: Pairing Response (0x02) len 6 IO capability: NoInputNoOutput (0x03) OOB data: Authentication data not present (0x00) Authentication requirement: No bonding, No MITM, Legacy, No Keypresses (0x00) Max encryption key size: 16 Initiator key distribution: <none> (0x00) Responder key distribution: <none> (0x00) ... > HCI Event: LE Meta Event (0x3e) plen 13 LE Long Term Key Request (0x05) Handle: 64 Random number: 0x0000000000000000 Encrypted diversifier: 0x0000 < HCI Command: LE Long Term Key Request Reply (0x08|0x001a) plen 18 Handle: 64 Long term key: 701b431a9e17bb000000000000000000 Change-Id: Ibc70aa01c040aff0d39410d273d6880d35aa5ae0 Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
81 lines
2.1 KiB
C
81 lines
2.1 KiB
C
/* keys.h - Bluetooth key handling */
|
|
|
|
/*
|
|
* Copyright (c) 2015 Intel Corporation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#if defined(CONFIG_BLUETOOTH_SMP)
|
|
enum {
|
|
BT_KEYS_SLAVE_LTK = (1 << 0),
|
|
BT_KEYS_IRK = (1 << 1),
|
|
BT_KEYS_LTK = (1 << 2),
|
|
BT_KEYS_LOCAL_CSRK = (1 << 3),
|
|
BT_KEYS_REMOTE_CSRK = (1 << 4),
|
|
|
|
BT_KEYS_ALL = (BT_KEYS_SLAVE_LTK | BT_KEYS_IRK | \
|
|
BT_KEYS_LTK | BT_KEYS_LOCAL_CSRK | \
|
|
BT_KEYS_REMOTE_CSRK),
|
|
};
|
|
|
|
enum {
|
|
BT_KEYS_UNAUTHENTICATED,
|
|
BT_KEYS_AUTHENTICATED,
|
|
};
|
|
|
|
struct bt_ltk {
|
|
uint64_t rand;
|
|
uint16_t ediv;
|
|
uint8_t val[16];
|
|
};
|
|
|
|
struct bt_irk {
|
|
uint8_t val[16];
|
|
bt_addr_t rpa;
|
|
};
|
|
|
|
struct bt_csrk {
|
|
uint8_t val[16];
|
|
uint32_t cnt;
|
|
};
|
|
|
|
struct bt_keys {
|
|
bt_addr_le_t addr;
|
|
int keys;
|
|
uint8_t type;
|
|
uint8_t enc_size;
|
|
|
|
struct bt_ltk slave_ltk;
|
|
struct bt_ltk ltk;
|
|
struct bt_irk irk;
|
|
#if defined(CONFIG_BLUETOOTH_SIGNING)
|
|
struct bt_csrk local_csrk;
|
|
struct bt_csrk remote_csrk;
|
|
#endif /* BLUETOOTH_SIGNING */
|
|
};
|
|
|
|
struct bt_keys *bt_keys_get_addr(const bt_addr_le_t *addr);
|
|
struct bt_keys *bt_keys_get_type(int type, const bt_addr_le_t *addr);
|
|
void bt_keys_add_type(struct bt_keys *keys, int type);
|
|
void bt_keys_clear(struct bt_keys *keys, int type);
|
|
struct bt_keys *bt_keys_find(int type, const bt_addr_le_t *addr);
|
|
struct bt_keys *bt_keys_find_irk(const bt_addr_le_t *addr);
|
|
struct bt_keys *bt_keys_find_addr(const bt_addr_le_t *addr);
|
|
#else
|
|
static inline struct bt_keys *bt_keys_find_addr(const bt_addr_le_t *addr)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif /* CONFIG_BLUETOOTH_SMP */
|