Skip to content

Commit 7b69f8f

Browse files
KKopyscinskijhedberg
authored andcommitted
Tests: Bluetooth: Tester: Add BTP command to enable Private NID
This allows to advertise beacons with Private Node Identity on demand, like was available for regular Node Identity. Signed-off-by: Krzysztof Kopyściński <[email protected]>
1 parent 1e5eeb8 commit 7b69f8f

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed

tests/bluetooth/tester/overlay-mesh.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@ CONFIG_BT_MESH_BLOB_SRV=y
4343
CONFIG_BT_MESH_DFU_SRV=y
4444
CONFIG_BT_MESH_DFD_SRV=y
4545
CONFIG_BT_MESH_DFU_SLOT_CNT=2
46+
CONFIG_BT_MESH_PRIV_BEACONS=y
47+
CONFIG_BT_MESH_PRIV_BEACON_SRV=y
48+
CONFIG_BT_MESH_PRIV_BEACON_CLI=y
4649

4750
CONFIG_SETTINGS=y

tests/bluetooth/tester/src/btp/btp_mesh.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,44 @@ struct btp_mmdl_blob_transfer_start_cmd {
971971
#define BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY 0x6A
972972
#define BTP_MMDL_DFU_SRV_APPLY 0x6B
973973

974+
#define BTP_MESH_PRIV_BEACON_GET 0x6c
975+
struct btp_priv_beacon_get_cmd {
976+
uint16_t dst;
977+
} __packed;
978+
979+
#define BTP_MESH_PRIV_BEACON_SET 0x6d
980+
struct btp_priv_beacon_set_cmd {
981+
uint16_t dst;
982+
uint8_t enabled;
983+
uint8_t rand_interval;
984+
} __packed;
985+
986+
#define BTP_MESH_PRIV_GATT_PROXY_GET 0x6e
987+
struct btp_priv_gatt_proxy_get_cmd {
988+
uint16_t dst;
989+
} __packed;
990+
991+
#define BTP_MESH_PRIV_GATT_PROXY_SET 0x6f
992+
struct btp_priv_gatt_proxy_set_cmd {
993+
uint16_t dst;
994+
uint8_t state;
995+
} __packed;
996+
997+
#define BTP_MESH_PRIV_NODE_ID_GET 0x70
998+
struct btp_priv_node_id_get_cmd {
999+
uint16_t dst;
1000+
uint16_t key_net_idx;
1001+
} __packed;
1002+
1003+
#define BTP_MESH_PRIV_NODE_ID_SET 0x71
1004+
struct btp_priv_node_id_set_cmd {
1005+
uint16_t dst;
1006+
uint16_t net_idx;
1007+
uint8_t state;
1008+
} __packed;
1009+
1010+
#define BTP_MESH_PROXY_PRIVATE_IDENTITY 0x72
1011+
9741012
/* events */
9751013
#define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80
9761014
struct btp_mesh_out_number_action_ev {

tests/bluetooth/tester/src/btp_mesh.c

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,139 @@ static uint8_t dfu_srv_apply(const void *cmd, uint16_t cmd_len,
617617
}
618618
#endif
619619

620+
#ifdef CONFIG_BT_MESH_PRIV_BEACON_CLI
621+
static struct bt_mesh_priv_beacon_cli priv_beacon_cli;
622+
623+
static uint8_t priv_beacon_get(const void *cmd, uint16_t cmd_len,
624+
void *rsp, uint16_t *rsp_len)
625+
{
626+
const struct btp_priv_beacon_get_cmd *cp = cmd;
627+
628+
struct bt_mesh_priv_beacon val;
629+
int err;
630+
631+
err = bt_mesh_priv_beacon_cli_get(net.net_idx, cp->dst, &val);
632+
if (err) {
633+
LOG_ERR("Failed to send Private Beacon Get (err %d)", err);
634+
return BTP_STATUS_FAILED;
635+
}
636+
637+
LOG_DBG("Private Beacon state: %u, %u", val.enabled, val.rand_interval);
638+
return BTP_STATUS_SUCCESS;
639+
}
640+
641+
static uint8_t priv_beacon_set(const void *cmd, uint16_t cmd_len,
642+
void *rsp, uint16_t *rsp_len)
643+
{
644+
const struct btp_priv_beacon_set_cmd *cp = cmd;
645+
struct bt_mesh_priv_beacon val;
646+
int err;
647+
648+
val.enabled = cp->enabled;
649+
val.rand_interval = cp->rand_interval;
650+
651+
err = bt_mesh_priv_beacon_cli_set(net.net_idx, cp->dst, &val);
652+
if (err) {
653+
LOG_ERR("Failed to send Private Beacon Set (err %d)", err);
654+
return BTP_STATUS_FAILED;
655+
}
656+
657+
return BTP_STATUS_SUCCESS;
658+
}
659+
660+
static uint8_t priv_gatt_proxy_get(const void *cmd, uint16_t cmd_len,
661+
void *rsp, uint16_t *rsp_len)
662+
{
663+
const struct btp_priv_gatt_proxy_get_cmd *cp = cmd;
664+
665+
uint8_t state;
666+
int err;
667+
668+
err = bt_mesh_priv_beacon_cli_gatt_proxy_get(net.net_idx, cp->dst, &state);
669+
if (err) {
670+
LOG_ERR("Failed to send Private GATT Proxy Get (err %d)", err);
671+
return BTP_STATUS_FAILED;
672+
}
673+
674+
LOG_DBG("Private GATT Proxy state: %u", state);
675+
return BTP_STATUS_SUCCESS;
676+
}
677+
678+
static uint8_t priv_gatt_proxy_set(const void *cmd, uint16_t cmd_len,
679+
void *rsp, uint16_t *rsp_len)
680+
{
681+
const struct btp_priv_gatt_proxy_set_cmd *cp = cmd;
682+
683+
uint8_t state;
684+
int err;
685+
686+
state = cp->state;
687+
688+
err = bt_mesh_priv_beacon_cli_gatt_proxy_set(net.net_idx, cp->dst, &state);
689+
if (err) {
690+
LOG_ERR("Failed to send Private GATT Proxy Set (err %d)", err);
691+
return BTP_STATUS_FAILED;
692+
}
693+
694+
return BTP_STATUS_SUCCESS;
695+
}
696+
697+
static uint8_t priv_node_id_get(const void *cmd, uint16_t cmd_len,
698+
void *rsp, uint16_t *rsp_len)
699+
{
700+
const struct btp_priv_node_id_get_cmd *cp = cmd;
701+
struct bt_mesh_priv_node_id val;
702+
uint16_t key_net_idx;
703+
int err;
704+
705+
key_net_idx = cp->key_net_idx;
706+
707+
err = bt_mesh_priv_beacon_cli_node_id_get(net.net_idx, cp->dst, key_net_idx, &val);
708+
if (err) {
709+
LOG_ERR("Failed to send Private Node Identity Get (err %d)", err);
710+
return BTP_STATUS_FAILED;
711+
}
712+
713+
LOG_DBG("Private Node Identity state: %u %u %u", val.net_idx, val.state, val.status);
714+
return BTP_STATUS_SUCCESS;
715+
}
716+
717+
static uint8_t priv_node_id_set(const void *cmd, uint16_t cmd_len,
718+
void *rsp, uint16_t *rsp_len)
719+
{
720+
const struct btp_priv_node_id_set_cmd *cp = cmd;
721+
struct bt_mesh_priv_node_id val;
722+
int err;
723+
724+
val.net_idx = cp->net_idx;
725+
val.state = cp->state;
726+
727+
err = bt_mesh_priv_beacon_cli_node_id_set(net.net_idx, cp->dst, &val);
728+
if (err) {
729+
LOG_ERR("Failed to send Private Node Identity Set (err %d)", err);
730+
return BTP_STATUS_FAILED;
731+
}
732+
733+
return BTP_STATUS_SUCCESS;
734+
}
735+
736+
static uint8_t proxy_private_identity_enable(const void *cmd, uint16_t cmd_len,
737+
void *rsp, uint16_t *rsp_len)
738+
{
739+
int err;
740+
741+
LOG_DBG("");
742+
743+
err = bt_mesh_proxy_private_identity_enable();
744+
if (err) {
745+
LOG_ERR("Failed to enable proxy private identity (err %d)", err);
746+
return BTP_STATUS_FAILED;
747+
}
748+
749+
return BTP_STATUS_SUCCESS;
750+
}
751+
#endif
752+
620753
static struct bt_mesh_model root_models[] = {
621754
BT_MESH_MODEL_CFG_SRV,
622755
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
@@ -655,6 +788,12 @@ static struct bt_mesh_model root_models[] = {
655788
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
656789
BT_MESH_MODEL_BLOB_CLI(&blob_cli),
657790
#endif
791+
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
792+
BT_MESH_MODEL_PRIV_BEACON_SRV,
793+
#endif
794+
#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI)
795+
BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli),
796+
#endif
658797
};
659798
struct model_data *lookup_model_bound(uint16_t id)
660799
{
@@ -4576,6 +4715,44 @@ static const struct btp_handler handlers[] = {
45764715
.expect_len = sizeof(struct btp_rpr_reprov_remote_cmd),
45774716
.func = rpr_reprov_remote
45784717
},
4718+
#endif
4719+
#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI)
4720+
{
4721+
.opcode = BTP_MESH_PRIV_BEACON_GET,
4722+
.expect_len = sizeof(struct btp_priv_beacon_get_cmd),
4723+
.func = priv_beacon_get
4724+
},
4725+
{
4726+
.opcode = BTP_MESH_PRIV_BEACON_SET,
4727+
.expect_len = sizeof(struct btp_priv_beacon_set_cmd),
4728+
.func = priv_beacon_set
4729+
},
4730+
{
4731+
.opcode = BTP_MESH_PRIV_GATT_PROXY_GET,
4732+
.expect_len = sizeof(struct btp_priv_gatt_proxy_get_cmd),
4733+
.func = priv_gatt_proxy_get
4734+
},
4735+
{
4736+
.opcode = BTP_MESH_PRIV_GATT_PROXY_SET,
4737+
.expect_len = sizeof(struct btp_priv_gatt_proxy_set_cmd),
4738+
.func = priv_gatt_proxy_set
4739+
},
4740+
{
4741+
.opcode = BTP_MESH_PRIV_NODE_ID_GET,
4742+
.expect_len = sizeof(struct btp_priv_node_id_get_cmd),
4743+
.func = priv_node_id_get
4744+
},
4745+
{
4746+
.opcode = BTP_MESH_PRIV_NODE_ID_SET,
4747+
.expect_len = sizeof(struct btp_priv_node_id_set_cmd),
4748+
.func = priv_node_id_set
4749+
},
4750+
{
4751+
.opcode = BTP_MESH_PROXY_PRIVATE_IDENTITY,
4752+
.expect_len = 0,
4753+
.func = proxy_private_identity_enable
4754+
},
4755+
#endif
45794756
};
45804757

45814758

0 commit comments

Comments
 (0)