Bluetooth: Mesh: fix static oob setting

According to specification it is possible to provide
static oob value with any length. Mesh should trim or
append\prepend by zeroes if it is longer\shorter than
required value.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
This commit is contained in:
Aleksandr Khromykh 2023-09-26 12:11:00 +02:00 committed by Carles Cufí
commit 707d1ed819
2 changed files with 15 additions and 11 deletions

View file

@ -183,9 +183,14 @@ static void prov_start(const uint8_t *data)
}
if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) {
memcpy(bt_mesh_prov_link.auth + auth_size - bt_mesh_prov->static_val_len,
bt_mesh_prov->static_val, bt_mesh_prov->static_val_len);
memset(bt_mesh_prov_link.auth, 0, auth_size - bt_mesh_prov->static_val_len);
uint8_t tail_size = bt_mesh_prov->static_val_len < auth_size
? auth_size - bt_mesh_prov->static_val_len
: 0;
memcpy(bt_mesh_prov_link.auth + tail_size, bt_mesh_prov->static_val,
tail_size ? bt_mesh_prov->static_val_len : auth_size);
memset(bt_mesh_prov_link.auth, 0, tail_size);
}
}

View file

@ -254,8 +254,7 @@ static void prov_capabilities(const uint8_t *data)
return;
}
if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) &&
(caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED)) {
if (caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED) {
bool oob_availability = caps.output_size > 0 || caps.input_size > 0 ||
(caps.oob_type & BT_MESH_STATIC_OOB_AVAILABLE);
@ -752,18 +751,18 @@ int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size)
int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size)
{
uint8_t auth_size = bt_mesh_prov_auth_size_get();
uint8_t tail_size = size < PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN - size : 0;
if (!size || !static_val || size > auth_size) {
if (!size || !static_val) {
return -EINVAL;
}
prov_set_method(AUTH_METHOD_STATIC, 0, 0);
memcpy(bt_mesh_prov_link.auth + auth_size - size, static_val, size);
if (size < auth_size) {
(void)memset(bt_mesh_prov_link.auth, 0, auth_size - size);
}
memcpy(bt_mesh_prov_link.auth + tail_size, static_val,
tail_size ? size : PROV_AUTH_MAX_LEN);
memset(bt_mesh_prov_link.auth, 0, tail_size);
return 0;
}