Bluetooth: pairing: OOB: Separate LE SC OOB from legacy OOB logic

Some systems can support only legacy OOB pairing while others only
LE SC OOB pairing.

The existent API function "bt_set_oob_data_flag" was removed.

Two new API functions were added:

 * "bt_le_oob_set_legacy_flag" to signal that legacy OOB pairing is used
 * "bt_le_oob_set_sc_flag" to signal that LE SC OOB pairing is used

The code will now advertise the presence of OOB flag depending
on the type of pairing method(SC vs legacy)

Signed-off-by: Sebastian Panceac <sebastian.panceac@ext.grandcentrix.net>
This commit is contained in:
Sebastian Panceac 2022-09-21 18:57:36 +03:00 committed by Carles Cufí
parent 89ef7614f3
commit 2e7c02bef6
5 changed files with 47 additions and 18 deletions

View file

@ -126,6 +126,10 @@ Deprecated in this release
Stable API changes in this release
==================================
* Removed `bt_set_oob_data_flag` and replaced it with two new API calls:
* :c:func:`bt_le_oob_set_sc_flag` for setting/clearing OOB flag in SC pairing
* :c:func:`bt_le_oob_set_legacy_flag` for setting/clearing OOB flag in legacy paring
New APIs in this release
========================

View file

@ -1046,15 +1046,21 @@ void bt_conn_cb_register(struct bt_conn_cb *cb);
*/
void bt_set_bondable(bool enable);
/** @brief Allow/disallow remote OOB data to be used for pairing.
/** @brief Allow/disallow remote LE SC OOB data to be used for pairing.
*
* Set/clear the OOB data flag for SMP Pairing Request/Response data.
* The initial value of this flag depends on BT_OOB_DATA_PRESENT Kconfig
* setting.
* Set/clear the OOB data flag for LE SC SMP Pairing Request/Response data.
*
* @param enable Value allowing/disallowing remote OOB data.
* @param enable Value allowing/disallowing remote LE SC OOB data.
*/
void bt_set_oob_data_flag(bool enable);
void bt_le_oob_set_sc_flag(bool enable);
/** @brief Allow/disallow remote legacy OOB data to be used for pairing.
*
* Set/clear the OOB data flag for legacy SMP Pairing Request/Response data.
*
* @param enable Value allowing/disallowing remote legacy OOB data.
*/
void bt_le_oob_set_legacy_flag(bool enable);
/** @brief Set OOB Temporary Key to be used for pairing
*

View file

@ -277,7 +277,8 @@ static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN];
static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN];
static bool bondable = IS_ENABLED(CONFIG_BT_BONDABLE);
static bool oobd_present;
static bool sc_oobd_present;
static bool legacy_oobd_present;
static bool sc_supported;
static const uint8_t *sc_public_key;
static K_SEM_DEFINE(sc_local_pkey_ready, 0, 1);
@ -2555,9 +2556,14 @@ void bt_set_bondable(bool enable)
bondable = enable;
}
void bt_set_oob_data_flag(bool enable)
void bt_le_oob_set_sc_flag(bool enable)
{
oobd_present = enable;
sc_oobd_present = enable;
}
void bt_le_oob_set_legacy_flag(bool enable)
{
legacy_oobd_present = enable;
}
static uint8_t get_auth(struct bt_smp *smp, uint8_t auth)
@ -2860,8 +2866,6 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
rsp->auth_req = get_auth(smp, req->auth_req);
rsp->io_capability = get_io_capa(smp);
rsp->oob_flag = oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
rsp->max_key_size = BT_SMP_MAX_ENC_KEY_SIZE;
rsp->init_key_dist = (req->init_key_dist & RECV_KEYS);
rsp->resp_key_dist = (req->resp_key_dist & SEND_KEYS);
@ -2874,6 +2878,14 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
rsp->resp_key_dist &= SEND_KEYS_SC;
}
if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) {
rsp->oob_flag = sc_oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
} else {
rsp->oob_flag = legacy_oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
}
if ((rsp->auth_req & BT_SMP_AUTH_CT2) &&
(req->auth_req & BT_SMP_AUTH_CT2)) {
atomic_set_bit(smp->flags, SMP_FLAG_CT2);
@ -3039,8 +3051,15 @@ static int smp_send_pairing_req(struct bt_conn *conn)
req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT);
req->io_capability = get_io_capa(smp);
req->oob_flag = oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
if (req->auth_req & BT_SMP_AUTH_SC) {
req->oob_flag = sc_oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
} else {
req->oob_flag = legacy_oobd_present ? BT_SMP_OOB_PRESENT :
BT_SMP_OOB_NOT_PRESENT;
}
req->max_key_size = BT_SMP_MAX_ENC_KEY_SIZE;
if (req->auth_req & BT_SMP_AUTH_BONDING) {

View file

@ -721,7 +721,7 @@ static void bt_ready(int err)
}
if (IS_ENABLED(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY)) {
bt_set_oob_data_flag(true);
bt_le_oob_set_legacy_flag(true);
}
#if defined(CONFIG_BT_OBSERVER)
@ -2836,7 +2836,7 @@ static int cmd_oob_remote(const struct shell *sh, size_t argc,
sizeof(oob_remote.le_sc_data.r));
hex2bin(argv[4], strlen(argv[4]), oob_remote.le_sc_data.c,
sizeof(oob_remote.le_sc_data.c));
bt_set_oob_data_flag(true);
bt_le_oob_set_sc_flag(true);
} else {
shell_help(sh);
return -ENOEXEC;
@ -2848,7 +2848,7 @@ static int cmd_oob_remote(const struct shell *sh, size_t argc,
static int cmd_oob_clear(const struct shell *sh, size_t argc, char *argv[])
{
memset(&oob_remote, 0, sizeof(oob_remote));
bt_set_oob_data_flag(false);
bt_le_oob_set_sc_flag(false);
return 0;
}

View file

@ -429,7 +429,7 @@ static uint8_t set_oob_sc_remote_data(const void *cmd, uint16_t cmd_len,
const struct btp_gap_oob_sc_set_remote_data_cmd *cp = cmd;
cb.oob_data_request = oob_data_request;
bt_set_oob_data_flag(true);
bt_le_oob_set_sc_flag(true);
/* Note that the .addr field
* will be set by the oob_data_request callback
@ -1183,7 +1183,7 @@ static uint8_t set_oob_legacy_data(const void *cmd, uint16_t cmd_len,
memcpy(oob_legacy_tk, cp->oob_data, 16);
bt_set_oob_data_flag(true);
bt_le_oob_set_legacy_flag(true);
cb.oob_data_request = oob_data_request;
return BTP_STATUS_SUCCESS;