Merge branch 'bugfix/ble_mesh_get_timer_remaining_time' into 'master'

ble_mesh: fix ble mesh get timer remaining time

See merge request espressif/esp-idf!6060
This commit is contained in:
Jiang Jiang Jian 2019-09-18 16:38:24 +08:00
commit 5051bb906a
19 changed files with 355 additions and 96 deletions

View File

@ -315,6 +315,8 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
return; return;
} }
bt_mesh_client_model_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false);
if (node == NULL) { if (node == NULL) {
msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT; msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT;
@ -334,12 +336,21 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
msg.sig = BTC_SIG_API_CB; msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL; msg.pid = BTC_PID_MODEL;
if (msg.act != ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) { if (msg.act == ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) {
// Don't forget to release the node at the end. ret = btc_transfer_context(&msg, &mesh_param,
bt_mesh_client_free_node(&data->queue, node); sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
} else {
if (!k_delayed_work_free(&node->timer)) {
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
} else {
ret = BT_STATUS_SUCCESS;
}
} }
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); bt_mesh_client_model_unlock();
if (ret != BT_STATUS_SUCCESS) { if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s, btc_transfer_context failed", __func__); LOG_ERROR("%s, btc_transfer_context failed", __func__);
@ -611,21 +622,29 @@ static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work)
return; return;
} }
mesh_param.client_send_timeout.opcode = node->opcode; bt_mesh_client_model_lock();
mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model;
mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx;
msg.sig = BTC_SIG_API_CB; if (!k_delayed_work_free(&node->timer)) {
msg.pid = BTC_PID_MODEL; mesh_param.client_send_timeout.opcode = node->opcode;
msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT; mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model;
ret = btc_transfer_context(&msg, &mesh_param, mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx;
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
if (ret != BT_STATUS_SUCCESS) { msg.sig = BTC_SIG_API_CB;
LOG_ERROR("%s btc_transfer_context failed", __func__); msg.pid = BTC_PID_MODEL;
msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT;
ret = btc_transfer_context(&msg, &mesh_param,
sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed", __func__);
}
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
} }
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node); bt_mesh_client_model_unlock();
return; return;
} }

View File

@ -505,17 +505,21 @@ static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem,
struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr) struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr)
{ {
int i; u16_t index;
for (i = 0; i < dev_comp->elem_count; i++) { if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
struct bt_mesh_elem *elem = &dev_comp->elem[i]; index = (addr - dev_comp->elem[0].addr);
if (index < dev_comp->elem_count) {
return &dev_comp->elem[index];
} else {
return NULL;
}
}
if (BLE_MESH_ADDR_IS_GROUP(addr) || for (index = 0; index < dev_comp->elem_count; index++) {
BLE_MESH_ADDR_IS_VIRTUAL(addr)) { struct bt_mesh_elem *elem = &dev_comp->elem[index];
if (bt_mesh_elem_find_group(elem, addr)) {
return elem; if (bt_mesh_elem_find_group(elem, addr)) {
}
} else if (elem->addr == addr) {
return elem; return elem;
} }
} }

View File

@ -12,6 +12,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
@ -82,6 +83,28 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
{ OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS }, { OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS },
}; };
static osi_mutex_t cfg_client_mutex;
static void bt_mesh_cfg_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&cfg_client_mutex);
init = true;
}
}
static void bt_mesh_cfg_client_lock(void)
{
osi_mutex_lock(&cfg_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_cfg_client_unlock(void)
{
osi_mutex_unlock(&cfg_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
config_internal_data_t *internal = NULL; config_internal_data_t *internal = NULL;
@ -108,10 +131,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_config_client_cb_evt_to_btc(node->opcode, bt_mesh_cfg_client_lock();
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_config_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_cfg_client_unlock();
return; return;
} }
@ -139,6 +168,9 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
/* If it is a publish message, sent to the user directly. */ /* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status; buf.data = (u8_t *)status;
buf.len = (u16_t)len; buf.len = (u16_t)len;
bt_mesh_cfg_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected config status message 0x%x", ctx->recv_op); BT_DBG("Unexpected config status message 0x%x", ctx->recv_op);
@ -199,12 +231,16 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_config_client_cb_evt_to_btc( if (!k_delayed_work_free(&node->timer)) {
node->opcode, evt_type, model, ctx, (const u8_t *)status, len); bt_mesh_config_client_cb_evt_to_btc(
// Don't forget to release the node at the end. node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
bt_mesh_client_free_node(&data->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
}
} }
bt_mesh_cfg_client_unlock();
switch (ctx->recv_op) { switch (ctx->recv_op) {
case OP_DEV_COMP_DATA_STATUS: { case OP_DEV_COMP_DATA_STATUS: {
struct bt_mesh_cfg_comp_data_status *val; struct bt_mesh_cfg_comp_data_status *val;
@ -1653,5 +1689,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
/* Configuration Model security is device-key based */ /* Configuration Model security is device-key based */
model->keys[0] = BLE_MESH_KEY_DEV; model->keys[0] = BLE_MESH_KEY_DEV;
bt_mesh_cfg_client_mutex_new();
return 0; return 0;
} }

View File

@ -12,6 +12,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
@ -38,6 +39,28 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = {
{ OP_ATTENTION_SET, OP_ATTENTION_STATUS }, { OP_ATTENTION_SET, OP_ATTENTION_STATUS },
}; };
static osi_mutex_t health_client_mutex;
static void bt_mesh_health_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&health_client_mutex);
init = true;
}
}
static void bt_mesh_health_client_lock(void)
{
osi_mutex_lock(&health_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_health_client_unlock(void)
{
osi_mutex_unlock(&health_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
health_internal_data_t *internal = NULL; health_internal_data_t *internal = NULL;
@ -64,10 +87,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_health_client_cb_evt_to_btc(node->opcode, bt_mesh_health_client_lock();
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_health_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_health_client_unlock();
return; return;
} }
@ -95,6 +124,9 @@ static void health_client_cancel(struct bt_mesh_model *model,
/* If it is a publish message, sent to the user directly. */ /* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status; buf.data = (u8_t *)status;
buf.len = (u16_t)len; buf.len = (u16_t)len;
bt_mesh_health_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected health status message 0x%x", ctx->recv_op); BT_DBG("Unexpected health status message 0x%x", ctx->recv_op);
@ -115,12 +147,16 @@ static void health_client_cancel(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_health_client_cb_evt_to_btc( if (!k_delayed_work_free(&node->timer)) {
node->opcode, evt_type, model, ctx, (const u8_t *)status, len); bt_mesh_health_client_cb_evt_to_btc(
// Don't forget to release the node at the end. node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
bt_mesh_client_free_node(&data->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&data->queue, node);
}
} }
bt_mesh_health_client_unlock();
switch (ctx->recv_op) { switch (ctx->recv_op) {
case OP_HEALTH_FAULT_STATUS: { case OP_HEALTH_FAULT_STATUS: {
struct bt_mesh_health_fault_status *val; struct bt_mesh_health_fault_status *val;
@ -453,6 +489,8 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
client->op_pair = health_op_pair; client->op_pair = health_op_pair;
client->internal_data = internal; client->internal_data = internal;
bt_mesh_health_client_mutex_new();
/* Set the default health client pointer */ /* Set the default health client pointer */
if (!health_cli) { if (!health_cli) {
health_cli = client; health_cli = client;

View File

@ -38,14 +38,6 @@ typedef struct alarm_t {
int64_t deadline_us; int64_t deadline_us;
} osi_alarm_t; } osi_alarm_t;
static void bt_mesh_alarm_cb(void *data)
{
assert(data != NULL);
struct k_delayed_work *work = (struct k_delayed_work *)data;
work->work.handler(&work->work);
return;
}
unsigned int bt_mesh_irq_lock(void) unsigned int bt_mesh_irq_lock(void)
{ {
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK #if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
@ -111,7 +103,7 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) { if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
alarm = osi_alarm_new("bt_mesh", bt_mesh_alarm_cb, (void *)work, 0); alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)work, 0);
if (alarm == NULL) { if (alarm == NULL) {
BT_ERR("%s, Unable to create alarm", __func__); BT_ERR("%s, Unable to create alarm", __func__);
return; return;
@ -189,17 +181,5 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
return 0; return 0;
} }
if (!alarm->deadline_us) { return osi_alarm_get_remaining_ms(alarm);
return 0;
}
s32_t remain_time = 0;
int64_t now = esp_timer_get_time();
if ((alarm->deadline_us - now) < 0x1FFFFFFFFFF) {
remain_time = (alarm->deadline_us - now) / 1000;
} else {
return 0;
}
return remain_time;
} }

View File

@ -16,6 +16,7 @@
#include <errno.h> #include <errno.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "mesh_access.h" #include "mesh_access.h"
#include "mesh_buf.h" #include "mesh_buf.h"
@ -222,6 +223,28 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
return err; return err;
} }
static osi_mutex_t client_model_mutex;
static void bt_mesh_client_model_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&client_model_mutex);
init = true;
}
}
void bt_mesh_client_model_lock(void)
{
osi_mutex_lock(&client_model_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
void bt_mesh_client_model_unlock(void)
{
osi_mutex_unlock(&client_model_mutex);
}
int bt_mesh_client_init(struct bt_mesh_model *model) int bt_mesh_client_init(struct bt_mesh_model *model)
{ {
bt_mesh_client_internal_data_t *data = NULL; bt_mesh_client_internal_data_t *data = NULL;
@ -256,17 +279,18 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
cli->model = model; cli->model = model;
cli->internal_data = data; cli->internal_data = data;
bt_mesh_client_model_mutex_new();
return 0; return 0;
} }
int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node) int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node)
{ {
if (!queue || !node) { if (!queue || !node) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL; return -EINVAL;
} }
// Free the node timer
k_delayed_work_free(&node->timer);
// Release the client node from the queue // Release the client node from the queue
sys_slist_find_and_remove(queue, &node->client_node); sys_slist_find_and_remove(queue, &node->client_node);
// Free the node // Free the node

View File

@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "mesh_types.h" #include "mesh_types.h"
@ -119,6 +120,28 @@ static const bt_mesh_client_op_pair_t gen_op_pair[] = {
{ BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS },
}; };
static osi_mutex_t generic_client_mutex;
static void bt_mesh_generic_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&generic_client_mutex);
init = true;
}
}
static void bt_mesh_generic_client_lock(void)
{
osi_mutex_lock(&generic_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_generic_client_unlock(void)
{
osi_mutex_unlock(&generic_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
generic_internal_data_t *internal = NULL; generic_internal_data_t *internal = NULL;
@ -145,10 +168,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_generic_client_cb_evt_to_btc(node->opcode, bt_mesh_generic_client_lock();
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_generic_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_generic_client_unlock();
return; return;
} }
@ -535,6 +564,9 @@ static void generic_status(struct bt_mesh_model *model,
buf->data = val; buf->data = val;
buf->len = len; buf->len = len;
bt_mesh_generic_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected generic status message 0x%x", rsp); BT_DBG("Unexpected generic status message 0x%x", rsp);
@ -580,11 +612,15 @@ static void generic_status(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); if (!k_delayed_work_free(&node->timer)) {
// Don't forget to release the node at the end. bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
bt_mesh_client_free_node(&internal->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
} }
bt_mesh_generic_client_unlock();
switch (rsp) { switch (rsp) {
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
struct bt_mesh_gen_user_properties_status *status; struct bt_mesh_gen_user_properties_status *status;
@ -1181,6 +1217,8 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = gen_op_pair; client->op_pair = gen_op_pair;
client->internal_data = internal; client->internal_data = internal;
bt_mesh_generic_client_mutex_new();
return 0; return 0;
} }

View File

@ -78,6 +78,10 @@ typedef struct {
void *cb_data; /* User defined callback value */ void *cb_data; /* User defined callback value */
} bt_mesh_client_common_param_t; } bt_mesh_client_common_param_t;
void bt_mesh_client_model_lock(void);
void bt_mesh_client_model_unlock(void);
int bt_mesh_client_init(struct bt_mesh_model *model); int bt_mesh_client_init(struct bt_mesh_model *model);
/** /**

View File

@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "mesh_types.h" #include "mesh_types.h"
@ -128,6 +129,28 @@ static const bt_mesh_client_op_pair_t light_op_pair[] = {
{ BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS },
}; };
static osi_mutex_t light_client_mutex;
static void bt_mesh_light_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&light_client_mutex);
init = true;
}
}
static void bt_mesh_light_client_lock(void)
{
osi_mutex_lock(&light_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_light_client_unlock(void)
{
osi_mutex_unlock(&light_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
light_internal_data_t *internal = NULL; light_internal_data_t *internal = NULL;
@ -154,10 +177,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, bt_mesh_light_client_lock();
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_light_client_unlock();
return; return;
} }
@ -650,6 +679,9 @@ static void light_status(struct bt_mesh_model *model,
buf->data = val; buf->data = val;
buf->len = len; buf->len = len;
bt_mesh_light_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected light status message 0x%x", rsp); BT_DBG("Unexpected light status message 0x%x", rsp);
@ -706,11 +738,15 @@ static void light_status(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); if (!k_delayed_work_free(&node->timer)) {
// Don't forget to release the node at the end. bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
bt_mesh_client_free_node(&internal->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
} }
bt_mesh_light_client_unlock();
switch (rsp) { switch (rsp) {
case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: {
struct bt_mesh_light_lc_property_status *status; struct bt_mesh_light_lc_property_status *status;
@ -1371,6 +1407,8 @@ static int light_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = light_op_pair; client->op_pair = light_op_pair;
client->internal_data = internal; client->internal_data = internal;
bt_mesh_light_client_mutex_new();
return 0; return 0;
} }

View File

@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "mesh_types.h" #include "mesh_types.h"
@ -57,6 +58,28 @@ static const bt_mesh_client_op_pair_t sensor_op_pair[] = {
{ BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS }, { BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS },
}; };
static osi_mutex_t sensor_client_mutex;
static void bt_mesh_sensor_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&sensor_client_mutex);
init = true;
}
}
static void bt_mesh_sensor_client_lock(void)
{
osi_mutex_lock(&sensor_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_sensor_client_unlock(void)
{
osi_mutex_unlock(&sensor_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
sensor_internal_data_t *internal = NULL; sensor_internal_data_t *internal = NULL;
@ -83,10 +106,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, bt_mesh_sensor_client_lock();
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_sensor_client_unlock();
return; return;
} }
@ -262,6 +291,9 @@ static void sensor_status(struct bt_mesh_model *model,
buf->data = val; buf->data = val;
buf->len = len; buf->len = len;
bt_mesh_sensor_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected sensor status message 0x%x", rsp); BT_DBG("Unexpected sensor status message 0x%x", rsp);
@ -284,11 +316,15 @@ static void sensor_status(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); if (!k_delayed_work_free(&node->timer)) {
// Don't forget to release the node at the end. bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
bt_mesh_client_free_node(&internal->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
} }
bt_mesh_sensor_client_unlock();
switch (rsp) { switch (rsp) {
case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: {
struct bt_mesh_sensor_descriptor_status *status; struct bt_mesh_sensor_descriptor_status *status;
@ -612,5 +648,7 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary)
client->op_pair = sensor_op_pair; client->op_pair = sensor_op_pair;
client->internal_data = internal; client->internal_data = internal;
bt_mesh_sensor_client_mutex_new();
return 0; return 0;
} }

View File

@ -17,6 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "osi/allocator.h" #include "osi/allocator.h"
#include "osi/mutex.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "mesh_types.h" #include "mesh_types.h"
@ -73,6 +74,28 @@ static const bt_mesh_client_op_pair_t time_scene_op_pair[] = {
{ BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS },
}; };
static osi_mutex_t time_scene_client_mutex;
static void bt_mesh_time_scene_client_mutex_new(void)
{
static bool init;
if (!init) {
osi_mutex_new(&time_scene_client_mutex);
init = true;
}
}
static void bt_mesh_time_scene_client_lock(void)
{
osi_mutex_lock(&time_scene_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
}
static void bt_mesh_time_scene_client_unlock(void)
{
osi_mutex_unlock(&time_scene_client_mutex);
}
static void timeout_handler(struct k_work *work) static void timeout_handler(struct k_work *work)
{ {
time_scene_internal_data_t *internal = NULL; time_scene_internal_data_t *internal = NULL;
@ -99,10 +122,16 @@ static void timeout_handler(struct k_work *work)
return; return;
} }
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, bt_mesh_time_scene_client_lock();
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
bt_mesh_client_free_node(&internal->queue, node); if (!k_delayed_work_free(&node->timer)) {
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
bt_mesh_time_scene_client_unlock();
return; return;
} }
@ -299,6 +328,9 @@ static void time_scene_status(struct bt_mesh_model *model,
buf->data = val; buf->data = val;
buf->len = len; buf->len = len;
bt_mesh_time_scene_client_lock();
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) { if (!node) {
BT_DBG("Unexpected time scene status message 0x%x", rsp); BT_DBG("Unexpected time scene status message 0x%x", rsp);
@ -328,11 +360,15 @@ static void time_scene_status(struct bt_mesh_model *model,
break; break;
} }
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len); if (!k_delayed_work_free(&node->timer)) {
// Don't forget to release the node at the end. bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
bt_mesh_client_free_node(&internal->queue, node); // Don't forget to release the node at the end.
bt_mesh_client_free_node(&internal->queue, node);
}
} }
bt_mesh_time_scene_client_unlock();
switch (rsp) { switch (rsp) {
case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: {
struct bt_mesh_scene_register_status *status; struct bt_mesh_scene_register_status *status;
@ -675,6 +711,8 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary)
client->op_pair = time_scene_op_pair; client->op_pair = time_scene_op_pair;
client->internal_data = internal; client->internal_data = internal;
bt_mesh_time_scene_client_mutex_new();
return 0; return 0;
} }

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_GATTS_ENABLE=y CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y

View File

@ -15,7 +15,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_GATTS_ENABLE=y CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_HCI_5_0=y
CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_HCI_5_0=y
CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_GATTS_ENABLE=y CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_GATTS_ENABLE=y CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y

View File

@ -12,7 +12,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_HCI_5_0=y CONFIG_BLE_MESH_HCI_5_0=y
CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y

View File

@ -16,7 +16,7 @@ CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y
CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=n CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_GATTS_ENABLE=y CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BLE_MESH=y CONFIG_BLE_MESH=y