Bluetooth: Mesh: Allow changing cfg client message timeout

10 seconds is quite long for configuration messages, and way too much
currently since we only talk through the local networking interface.
Set the default timeout to 2 seconds, and provide APIs through which
the timeout may be changed at run-time (mainly useful for the shell).

Note: The timeout_set() API is normally assumed to be called just once
for an application, based on the expected size of the network (hops &
latency). Trying to change it e.g. in a multi-threaded environment for
every message may not yield the expected results.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-14 20:45:26 +02:00 committed by Johan Hedberg
commit d4be608036
3 changed files with 62 additions and 14 deletions

View file

@ -91,6 +91,9 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
u8_t *count, u8_t *period, u8_t *ttl, u16_t *feat,
u16_t *pub_net_idx, u8_t *status);
s32_t bt_mesh_cfg_cli_timeout_get(void);
void bt_mesh_cfg_cli_timeout_set(s32_t timeout);
/**
* @}
*/

View file

@ -23,13 +23,13 @@
#include "foundation.h"
#define MSG_TIMEOUT K_SECONDS(10)
struct comp_data {
u8_t *status;
struct net_buf_simple *comp;
};
static s32_t msg_timeout = K_SECONDS(2);
static struct bt_mesh_cfg_cli *cli;
static void comp_data_status(struct bt_mesh_model *model,
@ -420,7 +420,7 @@ int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
cli->op_param = &param;
cli->op_pending = OP_DEV_COMP_DATA_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -456,7 +456,7 @@ static int get_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
cli->op_param = val;
cli->op_pending = rsp;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -493,7 +493,7 @@ static int set_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
cli->op_param = val;
cli->op_pending = rsp;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -582,7 +582,7 @@ int bt_mesh_cfg_relay_get(u16_t net_idx, u16_t addr, u8_t *status,
cli->op_param = &param;
cli->op_pending = OP_RELAY_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -624,7 +624,7 @@ int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
cli->op_param = &param;
cli->op_pending = OP_RELAY_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -672,7 +672,7 @@ int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
cli->op_param = &param;
cli->op_pending = OP_APP_KEY_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -728,7 +728,7 @@ int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr, u16_t mod_app_idx,
cli->op_param = &param;
cli->op_pending = OP_MOD_APP_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -799,7 +799,7 @@ int mod_sub_add(u16_t net_idx, u16_t addr, u16_t elem_addr, u16_t sub_addr,
cli->op_param = &param;
cli->op_pending = OP_MOD_SUB_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -860,7 +860,7 @@ int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr, u16_t src, u16_t dst,
cli->op_param = &param;
cli->op_pending = OP_HEARTBEAT_SUB_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -910,7 +910,7 @@ int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr, u16_t *src, u16_t *dst,
cli->op_param = &param;
cli->op_pending = OP_HEARTBEAT_SUB_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -966,7 +966,7 @@ int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
cli->op_param = &param;
cli->op_pending = OP_HEARTBEAT_PUB_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -1016,7 +1016,7 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
cli->op_param = &param;
cli->op_pending = OP_HEARTBEAT_PUB_STATUS;
err = k_sem_take(&cli->op_sync, MSG_TIMEOUT);
err = k_sem_take(&cli->op_sync, msg_timeout);
cli->op_pending = 0;
cli->op_param = NULL;
@ -1024,6 +1024,16 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
return err;
}
s32_t bt_mesh_cfg_cli_timeout_get(void)
{
return msg_timeout;
}
void bt_mesh_cfg_cli_timeout_set(s32_t timeout)
{
msg_timeout = timeout;
}
int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
{
BT_DBG("primary %u", primary);

View file

@ -885,8 +885,43 @@ static int cmd_provision(int argc, char *argv[])
return 0;
}
int cmd_timeout(int argc, char *argv[])
{
s32_t timeout;
if (argc < 2) {
timeout = bt_mesh_cfg_cli_timeout_get();
if (timeout == K_FOREVER) {
printk("Message timeout: forever\n");
} else {
printk("Message timeout: %u seconds\n",
timeout / 1000);
}
return 0;
}
timeout = strtol(argv[1], NULL, 0);
if (timeout < 0 || timeout > (INT32_MAX / 1000)) {
timeout = K_FOREVER;
} else {
timeout = timeout * 1000;
}
bt_mesh_cfg_cli_timeout_set(timeout);
if (timeout == K_FOREVER) {
printk("Message timeout: forever\n");
} else {
printk("Message timeout: %u seconds\n",
timeout / 1000);
}
return 0;
}
static const struct shell_cmd mesh_commands[] = {
{ "init", cmd_init, NULL },
{ "timeout", cmd_timeout, "[timeout in seconds]" },
#if defined(CONFIG_BT_MESH_PB_ADV)
{ "pb-adv", cmd_pb_adv, "<val: off, on>" },
#endif