Bluetooth: host: Refactor out identity handling from hci_core to id

Refactor out the identity handling from hci_core to its own source file
in id.c
Identity consistes of managing the identities of the device, the privacy
feature which hides the identities. And handling of the identity
resolving list in the controller, needed to support privacy-enabled
remote devices.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2021-03-08 14:24:34 +01:00 committed by Johan Hedberg
commit 54fe1cd1b3
6 changed files with 1872 additions and 1787 deletions

View file

@ -34,6 +34,7 @@ if(CONFIG_BT_HCI_HOST)
buf.c buf.c
hci_core.c hci_core.c
hci_common.c hci_common.c
id.c
) )
zephyr_library_sources_ifdef( zephyr_library_sources_ifdef(
CONFIG_BT_HOST_CRYPTO CONFIG_BT_HOST_CRYPTO

View file

@ -28,6 +28,7 @@
#include "common/log.h" #include "common/log.h"
#include "hci_core.h" #include "hci_core.h"
#include "id.h"
#include "conn_internal.h" #include "conn_internal.h"
#include "l2cap_internal.h" #include "l2cap_internal.h"
#include "keys.h" #include "keys.h"
@ -2258,7 +2259,7 @@ int bt_conn_le_create_auto(const struct bt_conn_le_create_param *create_param,
return -EINVAL; return -EINVAL;
} }
if (!bt_le_scan_random_addr_check()) { if (!bt_id_scan_random_addr_check()) {
return -EINVAL; return -EINVAL;
} }
@ -2350,7 +2351,7 @@ int bt_conn_le_create(const bt_addr_le_t *peer,
return -EALREADY; return -EALREADY;
} }
if (!bt_le_scan_random_addr_check()) { if (!bt_id_scan_random_addr_check()) {
return -EINVAL; return -EINVAL;
} }
@ -2422,7 +2423,7 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
return -EINVAL; return -EINVAL;
} }
if (!bt_le_scan_random_addr_check()) { if (!bt_id_scan_random_addr_check()) {
return -EINVAL; return -EINVAL;
} }

File diff suppressed because it is too large Load diff

View file

@ -326,6 +326,11 @@ struct bt_hci_cmd_state_set {
bool val; bool val;
}; };
struct bt_adv_id_check_data {
uint8_t id;
bool adv_enabled;
};
/* Set command state related with the command buffer */ /* Set command state related with the command buffer */
void bt_hci_cmd_state_set_init(struct net_buf *buf, void bt_hci_cmd_state_set_init(struct net_buf *buf,
struct bt_hci_cmd_state_set *state, struct bt_hci_cmd_state_set *state,
@ -364,7 +369,16 @@ int bt_le_adv_start_internal(const struct bt_le_adv_param *param,
const bt_addr_le_t *peer); const bt_addr_le_t *peer);
void bt_le_adv_resume(void); void bt_le_adv_resume(void);
bool bt_le_scan_random_addr_check(void); int bt_le_adv_set_enable_legacy(struct bt_le_ext_adv *adv, bool enable);
int bt_le_adv_set_enable_ext(struct bt_le_ext_adv *adv,
bool enable,
const struct bt_le_ext_adv_start_param *param);
struct bt_le_ext_adv *bt_le_adv_lookup_legacy(void);
int bt_le_adv_set_enable(struct bt_le_ext_adv *adv, bool enable);
void bt_le_ext_adv_foreach(void (*func)(struct bt_le_ext_adv *adv, void *data),
void *data);
int bt_le_scan_set_enable(uint8_t enable);
void bt_hci_host_num_completed_packets(struct net_buf *buf); void bt_hci_host_num_completed_packets(struct net_buf *buf);

1748
subsys/bluetooth/host/id.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2017-2021 Nordic Semiconductor ASA
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#define RPA_TIMEOUT_MS (CONFIG_BT_RPA_TIMEOUT * MSEC_PER_SEC)
#define RPA_TIMEOUT K_MSEC(RPA_TIMEOUT_MS)
static inline bool bt_id_rpa_is_new(void)
{
#if defined(CONFIG_BT_PRIVACY)
/* RPA is considered new if there is less than half a second since the
* timeout was started.
*/
return k_delayed_work_remaining_get(&bt_dev.rpa_update) >
(RPA_TIMEOUT_MS - 500);
#else
return false;
#endif
}
int bt_id_init(void);
uint8_t bt_id_read_public_addr(bt_addr_le_t *addr);
int bt_id_set_create_conn_own_addr(bool use_filter, uint8_t *own_addr_type);
int bt_id_set_scan_own_addr(bool active_scan, uint8_t *own_addr_type);
int bt_id_set_adv_own_addr(struct bt_le_ext_adv *adv, uint32_t options,
bool dir_adv, uint8_t *own_addr_type);
bool bt_id_adv_random_addr_check(const struct bt_le_adv_param *param);
bool bt_id_scan_random_addr_check(void);
int bt_id_set_adv_random_addr(struct bt_le_ext_adv *adv,
const bt_addr_t *addr);
int bt_id_set_adv_private_addr(struct bt_le_ext_adv *adv);
int bt_id_set_private_addr(uint8_t id);
void bt_id_pending_keys_update(void);