Skip to content

Commit 9ad64e8

Browse files
agata-ponitkacfriedt
authored andcommitted
Bluetooth: Tester: Add the OOB Authentication method
Adding support for automatic testing OOB Authentication method. Signed-off-by: Agata Ponitka <[email protected]>
1 parent cf112e2 commit 9ad64e8

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

tests/bluetooth/tester/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CONFIG_BT_MESH_TX_SEG_MSG_COUNT=2
4444
CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100
4545
CONFIG_BT_MESH_PROVISIONER=y
4646
CONFIG_BT_MESH_CDB_NODE_COUNT=3
47+
CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y
4748

4849
CONFIG_BT_TINYCRYPT_ECC=y
4950
CONFIG_BT_TESTING=y

tests/bluetooth/tester/src/bttester.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,21 @@ struct mesh_read_supported_commands_rp {
855855
#define MESH_IN_ENTER_STRING BIT(3)
856856

857857
#define MESH_CONFIG_PROVISIONING 0x02
858+
859+
struct set_keys {
860+
uint8_t pub_key[64];
861+
uint8_t priv_key[32];
862+
} __packed;
863+
858864
struct mesh_config_provisioning_cmd {
859865
uint8_t uuid[16];
860866
uint8_t static_auth[16];
861867
uint8_t out_size;
862868
uint16_t out_actions;
863869
uint8_t in_size;
864870
uint16_t in_actions;
871+
uint8_t auth_method;
872+
struct set_keys set_keys[0];
865873
} __packed;
866874

867875
#define MESH_PROVISION_NODE 0x03
@@ -873,6 +881,7 @@ struct mesh_provision_node_cmd {
873881
uint32_t seq_num;
874882
uint16_t addr;
875883
uint8_t dev_key[16];
884+
uint8_t pub_key[0];
876885
} __packed;
877886

878887
#define MESH_INIT 0x04

tests/bluetooth/tester/src/mesh.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ static uint32_t iv_index;
3838
static uint16_t addr;
3939
static uint8_t dev_key[16];
4040
static uint8_t input_size;
41+
static uint8_t pub_key[64];
42+
static uint8_t priv_key[32];
4143

4244
/* Configured provisioning data */
4345
static uint8_t dev_uuid[16];
@@ -51,6 +53,11 @@ static uint16_t vnd_app_key_idx = 0x000f;
5153
/* Model send data */
5254
#define MODEL_BOUNDS_MAX 2
5355

56+
/* Model Authentication Method */
57+
#define AUTH_METHOD_STATIC 0x01
58+
#define AUTH_METHOD_OUTPUT 0x02
59+
#define AUTH_METHOD_INPUT 0x03
60+
5461
static struct model_data {
5562
struct bt_mesh_model *model;
5663
uint16_t addr;
@@ -436,6 +443,7 @@ static struct bt_mesh_prov prov = {
436443
static void config_prov(uint8_t *data, uint16_t len)
437444
{
438445
const struct mesh_config_provisioning_cmd *cmd = (void *) data;
446+
int err = 0;
439447

440448
LOG_DBG("");
441449

@@ -447,8 +455,27 @@ static void config_prov(uint8_t *data, uint16_t len)
447455
prov.input_size = cmd->in_size;
448456
prov.input_actions = sys_le16_to_cpu(cmd->in_actions);
449457

450-
tester_rsp(BTP_SERVICE_ID_MESH, MESH_CONFIG_PROVISIONING,
451-
CONTROLLER_INDEX, BTP_STATUS_SUCCESS);
458+
if (cmd->auth_method == AUTH_METHOD_OUTPUT) {
459+
err = bt_mesh_auth_method_set_output(prov.output_actions, prov.output_size);
460+
} else if (cmd->auth_method == AUTH_METHOD_INPUT) {
461+
err = bt_mesh_auth_method_set_input(prov.input_actions, prov.input_size);
462+
} else if (cmd->auth_method == AUTH_METHOD_STATIC) {
463+
err = bt_mesh_auth_method_set_static(static_auth, sizeof(static_auth));
464+
}
465+
466+
if (len > sizeof(*cmd)) {
467+
memcpy(pub_key, cmd->set_keys->pub_key, sizeof(cmd->set_keys->pub_key));
468+
memcpy(priv_key, cmd->set_keys->priv_key, sizeof(cmd->set_keys->priv_key));
469+
prov.public_key_be = pub_key;
470+
prov.private_key_be = priv_key;
471+
}
472+
473+
if (err) {
474+
LOG_ERR("err %d", err);
475+
}
476+
477+
tester_rsp(BTP_SERVICE_ID_MESH, MESH_CONFIG_PROVISIONING, CONTROLLER_INDEX,
478+
err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS);
452479
}
453480

454481
static void provision_node(uint8_t *data, uint16_t len)
@@ -465,6 +492,16 @@ static void provision_node(uint8_t *data, uint16_t len)
465492
flags = cmd->flags;
466493
iv_index = sys_le32_to_cpu(cmd->iv_index);
467494
net_key_idx = sys_le16_to_cpu(cmd->net_key_idx);
495+
496+
if (len > sizeof(*cmd)) {
497+
memcpy(pub_key, cmd->pub_key, sizeof(pub_key));
498+
499+
err = bt_mesh_prov_remote_pub_key_set(pub_key);
500+
if (err) {
501+
LOG_ERR("err %d", err);
502+
goto fail;
503+
}
504+
}
468505
#if defined(CONFIG_BT_MESH_PROVISIONER)
469506
err = bt_mesh_cdb_create(net_key);
470507
if (err) {

0 commit comments

Comments
 (0)