return;
}
+ bt_mesh_client_model_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false);
if (node == NULL) {
msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_MODEL;
- if (msg.act != ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) {
- // Don't forget to release the node at the end.
- bt_mesh_client_free_node(&data->queue, node);
+ if (msg.act == ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT) {
+ ret = btc_transfer_context(&msg, &mesh_param,
+ 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) {
LOG_ERROR("%s, btc_transfer_context failed", __func__);
return;
}
- mesh_param.client_send_timeout.opcode = node->opcode;
- 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;
+ bt_mesh_client_model_lock();
- msg.sig = BTC_SIG_API_CB;
- 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 (!k_delayed_work_free(&node->timer)) {
+ mesh_param.client_send_timeout.opcode = node->opcode;
+ 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;
- if (ret != BT_STATUS_SUCCESS) {
- LOG_ERROR("%s btc_transfer_context failed", __func__);
+ msg.sig = BTC_SIG_API_CB;
+ 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;
}
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
{ 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)
{
config_internal_data_t *internal = NULL;
return;
}
- bt_mesh_config_client_cb_evt_to_btc(node->opcode,
- BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
+ bt_mesh_cfg_client_lock();
- 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;
}
/* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status;
buf.len = (u16_t)len;
+
+ bt_mesh_cfg_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
BT_DBG("Unexpected config status message 0x%x", ctx->recv_op);
break;
}
- bt_mesh_config_client_cb_evt_to_btc(
- node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
- // Don't forget to release the node at the end.
- bt_mesh_client_free_node(&data->queue, node);
+ if (!k_delayed_work_free(&node->timer)) {
+ bt_mesh_config_client_cb_evt_to_btc(
+ node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
+ // 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) {
case OP_DEV_COMP_DATA_STATUS: {
struct bt_mesh_cfg_comp_data_status *val;
/* Configuration Model security is device-key based */
model->keys[0] = BLE_MESH_KEY_DEV;
+ bt_mesh_cfg_client_mutex_new();
+
return 0;
}
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
{ 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)
{
health_internal_data_t *internal = NULL;
return;
}
- bt_mesh_health_client_cb_evt_to_btc(node->opcode,
- BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
+ bt_mesh_health_client_lock();
- 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;
}
/* If it is a publish message, sent to the user directly. */
buf.data = (u8_t *)status;
buf.len = (u16_t)len;
+
+ bt_mesh_health_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
BT_DBG("Unexpected health status message 0x%x", ctx->recv_op);
break;
}
- bt_mesh_health_client_cb_evt_to_btc(
- node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
- // Don't forget to release the node at the end.
- bt_mesh_client_free_node(&data->queue, node);
+ if (!k_delayed_work_free(&node->timer)) {
+ bt_mesh_health_client_cb_evt_to_btc(
+ node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
+ // 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) {
case OP_HEALTH_FAULT_STATUS: {
struct bt_mesh_health_fault_status *val;
client->op_pair = health_op_pair;
client->internal_data = internal;
+ bt_mesh_health_client_mutex_new();
+
/* Set the default health client pointer */
if (!health_cli) {
health_cli = client;
int64_t deadline_us;
} 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)
{
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
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) {
BT_ERR("%s, Unable to create alarm", __func__);
return;
#include <errno.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "mesh_access.h"
#include "mesh_buf.h"
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)
{
bt_mesh_client_internal_data_t *data = NULL;
cli->model = model;
cli->internal_data = data;
+ bt_mesh_client_model_mutex_new();
+
return 0;
}
int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node)
{
if (!queue || !node) {
+ BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
- // Free the node timer
- k_delayed_work_free(&node->timer);
// Release the client node from the queue
sys_slist_find_and_remove(queue, &node->client_node);
// Free the node
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
{ 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)
{
generic_internal_data_t *internal = NULL;
return;
}
- bt_mesh_generic_client_cb_evt_to_btc(node->opcode,
- BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
+ bt_mesh_generic_client_lock();
- 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;
}
buf->data = val;
buf->len = len;
+
+ bt_mesh_generic_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected generic status message 0x%x", rsp);
break;
}
- bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
- // Don't forget to release the node at the end.
- 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, evt, model, ctx, val, len);
+ // 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) {
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
struct bt_mesh_gen_user_properties_status *status;
client->op_pair = gen_op_pair;
client->internal_data = internal;
+ bt_mesh_generic_client_mutex_new();
+
return 0;
}
void *cb_data; /* User defined callback value */
} 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);
/**
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
{ 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)
{
light_internal_data_t *internal = NULL;
return;
}
- bt_mesh_lighting_client_cb_evt_to_btc(node->opcode,
- BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
+ bt_mesh_light_client_lock();
- 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;
}
buf->data = val;
buf->len = len;
+
+ bt_mesh_light_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected light status message 0x%x", rsp);
break;
}
- bt_mesh_lighting_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
- // Don't forget to release the node at the end.
- 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, evt, model, ctx, val, len);
+ // 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) {
case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: {
struct bt_mesh_light_lc_property_status *status;
client->op_pair = light_op_pair;
client->internal_data = internal;
+ bt_mesh_light_client_mutex_new();
+
return 0;
}
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
{ 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)
{
sensor_internal_data_t *internal = NULL;
return;
}
- bt_mesh_sensor_client_cb_evt_to_btc(node->opcode,
- BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
+ bt_mesh_sensor_client_lock();
- 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;
}
buf->data = val;
buf->len = len;
+
+ bt_mesh_sensor_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected sensor status message 0x%x", rsp);
break;
}
- bt_mesh_sensor_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
- // Don't forget to release the node at the end.
- 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, evt, model, ctx, val, len);
+ // 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) {
case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: {
struct bt_mesh_sensor_descriptor_status *status;
client->op_pair = sensor_op_pair;
client->internal_data = internal;
+ bt_mesh_sensor_client_mutex_new();
+
return 0;
}
\ No newline at end of file
#include <stdbool.h>
#include "osi/allocator.h"
+#include "osi/mutex.h"
#include "sdkconfig.h"
#include "mesh_types.h"
{ 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)
{
time_scene_internal_data_t *internal = NULL;
return;
}
- 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);
+ bt_mesh_time_scene_client_lock();
- 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;
}
buf->data = val;
buf->len = len;
+
+ bt_mesh_time_scene_client_lock();
+
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
if (!node) {
BT_DBG("Unexpected time scene status message 0x%x", rsp);
break;
}
- bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
- // Don't forget to release the node at the end.
- 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, evt, model, ctx, val, len);
+ // 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) {
case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: {
struct bt_mesh_scene_register_status *status;
client->op_pair = time_scene_op_pair;
client->internal_data = internal;
+ bt_mesh_time_scene_client_mutex_new();
+
return 0;
}