2021-10-26 04:24:54 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2020-03-31 04:49:36 -04:00
|
|
|
#include "btc_ble_mesh_generic_model.h"
|
|
|
|
|
2023-08-25 02:28:44 -04:00
|
|
|
#include "mesh/config.h"
|
|
|
|
#include "mesh/model_opcode.h"
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2020-10-16 04:10:28 -04:00
|
|
|
#if CONFIG_BLE_MESH_GENERIC_CLIENT
|
2023-08-25 02:28:44 -04:00
|
|
|
#include "mesh/generic_client.h"
|
2020-10-16 03:15:18 -04:00
|
|
|
|
2020-07-04 06:35:08 -04:00
|
|
|
/* The followings are the macro definitions of Generic client
|
|
|
|
* model message length, and a message is composed of 3 parts:
|
|
|
|
* Opcode + Payload + MIC
|
2019-01-07 02:16:47 -05:00
|
|
|
*/
|
|
|
|
/* Generic onoff client messages length */
|
|
|
|
#define BLE_MESH_GEN_ONOFF_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_ONOFF_SET_MSG_LEN (2 + 4 + 4)
|
|
|
|
|
|
|
|
/* Generic level client messages length */
|
|
|
|
#define BLE_MESH_GEN_LEVEL_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_LEVEL_SET_MSG_LEN (2 + 5 + 4)
|
|
|
|
#define BLE_MESH_GEN_DELTA_SET_MSG_LEN (2 + 7 + 4)
|
|
|
|
#define BLE_MESH_GEN_MOVE_SET_MSG_LEN (2 + 5 + 4)
|
|
|
|
|
|
|
|
/* Generic default transition time client messages length */
|
|
|
|
#define BLE_MESH_GEN_DEF_TRANS_TIME_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN (2 + 1 + 4)
|
|
|
|
|
|
|
|
/* Generic power onoff client messages length */
|
|
|
|
#define BLE_MESH_GEN_ONPOWERUP_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN (2 + 1 + 4)
|
|
|
|
|
|
|
|
/* Generic power level client messages length */
|
|
|
|
#define BLE_MESH_GEN_POWER_LEVEL_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN (2 + 5 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_LAST_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_DEFAULT_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN (2 + 2 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_RANGE_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN (2 + 4 + 4)
|
|
|
|
|
|
|
|
/* Generic battery client messages length */
|
|
|
|
#define BLE_MESH_GEN_BATTERY_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
|
|
|
|
/* Generic location client messages length */
|
|
|
|
#define BLE_MESH_GEN_LOC_GLOBAL_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN (1 + 10 + 4)
|
|
|
|
#define BLE_MESH_GEN_LOC_LOCAL_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN (2 + 9 + 4)
|
|
|
|
|
|
|
|
/* Generic property client messages length */
|
|
|
|
#define BLE_MESH_GEN_USER_PROPERTIES_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_USER_PROPERTY_GET_MSG_LEN (2 + 2 + 4)
|
|
|
|
#define BLE_MESH_GEN_USER_PROPERTY_SET_MSG_LEN /* variable */
|
|
|
|
#define BLE_MESH_GEN_ADMIN_PROPERTIES_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_ADMIN_PROPERTY_GET_MSG_LEN (2 + 2 + 4)
|
|
|
|
#define BLE_MESH_GEN_ADMIN_PROPERTY_SET_MSG_LEN /* variable */
|
|
|
|
#define BLE_MESH_GEN_MANU_PROPERTIES_GET_MSG_LEN (2 + 0 + 4)
|
|
|
|
#define BLE_MESH_GEN_MANU_PROPERTY_GET_MSG_LEN (2 + 2 + 4)
|
|
|
|
#define BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN (1 + 3 + 4)
|
2023-08-28 04:09:37 -04:00
|
|
|
#define BLE_MESH_GEN_CLIENT_PROPERTIES_GET_MSG_LEN (1 + 2 + 4)
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
#define BLE_MESH_GEN_GET_STATE_MSG_LEN (2 + 2 + 4)
|
|
|
|
|
|
|
|
static const bt_mesh_client_op_pair_t gen_op_pair[] = {
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONOFF_GET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONOFF_SET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_DELTA_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MOVE_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET, BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_BATTERY_GET, BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS },
|
|
|
|
};
|
|
|
|
|
2020-01-19 05:57:13 -05:00
|
|
|
static bt_mesh_mutex_t generic_client_lock;
|
2019-09-16 03:05:14 -04:00
|
|
|
|
2019-01-07 02:16:47 -05:00
|
|
|
static void timeout_handler(struct k_work *work)
|
|
|
|
{
|
2019-09-26 07:38:25 -04:00
|
|
|
struct k_delayed_work *timer = NULL;
|
2019-01-07 02:16:47 -05:00
|
|
|
bt_mesh_client_node_t *node = NULL;
|
2023-08-28 04:09:37 -04:00
|
|
|
struct bt_mesh_model *model = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
struct bt_mesh_msg_ctx ctx = {0};
|
2020-12-07 04:03:11 -05:00
|
|
|
uint32_t opcode = 0U;
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
BT_WARN("Receive generic status message timeout");
|
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
bt_mesh_mutex_lock(&generic_client_lock);
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2019-09-26 07:38:25 -04:00
|
|
|
timer = CONTAINER_OF(work, struct k_delayed_work, work);
|
|
|
|
|
|
|
|
if (timer && !k_delayed_work_free(timer)) {
|
|
|
|
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
|
|
|
|
if (node) {
|
2020-01-19 05:57:13 -05:00
|
|
|
memcpy(&ctx, &node->ctx, sizeof(ctx));
|
|
|
|
opcode = node->opcode;
|
2023-08-28 04:09:37 -04:00
|
|
|
model = node->model;
|
2019-09-26 07:38:25 -04:00
|
|
|
bt_mesh_client_free_node(node);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_generic_client_cb_evt_to_btc(
|
2023-08-28 04:09:37 -04:00
|
|
|
opcode, BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, model, &ctx, NULL, 0);
|
2019-09-26 07:38:25 -04:00
|
|
|
}
|
2019-09-16 03:05:14 -04:00
|
|
|
}
|
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
bt_mesh_mutex_unlock(&generic_client_lock);
|
2019-01-07 02:16:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void generic_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
bt_mesh_client_node_t *node = NULL;
|
2020-12-07 04:03:11 -05:00
|
|
|
uint8_t *val = NULL;
|
|
|
|
uint8_t evt = 0xFF;
|
2020-01-19 05:57:13 -05:00
|
|
|
size_t len = 0U;
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len));
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2019-09-26 07:38:25 -04:00
|
|
|
switch (ctx->recv_op) {
|
2019-01-07 02:16:47 -05:00
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS: {
|
|
|
|
struct bt_mesh_gen_onoff_status *status = NULL;
|
|
|
|
if (buf->len != 1 && buf->len != 3) {
|
|
|
|
BT_ERR("Invalid Generic OnOff Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onoff_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->present_onoff = net_buf_simple_pull_u8(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->target_onoff = net_buf_simple_pull_u8(buf);
|
|
|
|
status->remain_time = net_buf_simple_pull_u8(buf);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_onoff_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS: {
|
|
|
|
struct bt_mesh_gen_level_status *status = NULL;
|
|
|
|
if (buf->len != 2 && buf->len != 5) {
|
|
|
|
BT_ERR("Invalid Generic Level Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_level_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->present_level = net_buf_simple_pull_le16(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->target_level = net_buf_simple_pull_le16(buf);
|
|
|
|
status->remain_time = net_buf_simple_pull_u8(buf);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_level_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS: {
|
|
|
|
struct bt_mesh_gen_def_trans_time_status *status = NULL;
|
|
|
|
if (buf->len != 1) {
|
|
|
|
BT_ERR("Invalid Generic Default Trans Time Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->trans_time = net_buf_simple_pull_u8(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_def_trans_time_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS: {
|
|
|
|
struct bt_mesh_gen_onpowerup_status *status = NULL;
|
|
|
|
if (buf->len != 1) {
|
|
|
|
BT_ERR("Invalid Generic OnPowerUp Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onpowerup_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->onpowerup = net_buf_simple_pull_u8(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_onpowerup_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS: {
|
|
|
|
struct bt_mesh_gen_power_level_status *status = NULL;
|
|
|
|
if (buf->len != 2 && buf->len != 5) {
|
|
|
|
BT_ERR("Invalid Generic Power Level Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_level_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->present_power = net_buf_simple_pull_le16(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->target_power = net_buf_simple_pull_le16(buf);
|
|
|
|
status->remain_time = net_buf_simple_pull_u8(buf);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_power_level_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS: {
|
|
|
|
struct bt_mesh_gen_power_last_status *status = NULL;
|
|
|
|
if (buf->len != 2) {
|
|
|
|
BT_ERR("Invalid Generic Power Last Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_last_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->power = net_buf_simple_pull_le16(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_power_last_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS: {
|
|
|
|
struct bt_mesh_gen_power_default_status *status = NULL;
|
|
|
|
if (buf->len != 2) {
|
|
|
|
BT_ERR("Invalid Generic Power Default Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_default_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->power = net_buf_simple_pull_le16(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_power_default_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS: {
|
|
|
|
struct bt_mesh_gen_power_range_status *status = NULL;
|
|
|
|
if (buf->len != 5) {
|
|
|
|
BT_ERR("Invalid Generic Power Range Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_range_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->status_code = net_buf_simple_pull_u8(buf);
|
|
|
|
status->range_min = net_buf_simple_pull_le16(buf);
|
|
|
|
status->range_max = net_buf_simple_pull_le16(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_power_range_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS: {
|
|
|
|
struct bt_mesh_gen_battery_status *status = NULL;
|
|
|
|
if (buf->len != 8) {
|
|
|
|
BT_ERR("Invalid Generic Battery Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_battery_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
uint32_t value = 0;
|
2019-01-07 02:16:47 -05:00
|
|
|
value = net_buf_simple_pull_le32(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
status->battery_level = (uint8_t)value;
|
2019-01-07 02:16:47 -05:00
|
|
|
status->time_to_discharge = (value >> 8);
|
|
|
|
value = net_buf_simple_pull_le32(buf);
|
|
|
|
status->time_to_charge = (value & 0xffffff);
|
2020-12-07 04:03:11 -05:00
|
|
|
status->flags = (uint8_t)(value >> 24);
|
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_battery_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS: {
|
|
|
|
struct bt_mesh_gen_loc_global_status *status = NULL;
|
|
|
|
if (buf->len != 10) {
|
|
|
|
BT_ERR("Invalid Generic Location Global Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_global_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->global_latitude = net_buf_simple_pull_le32(buf);
|
|
|
|
status->global_longitude = net_buf_simple_pull_le32(buf);
|
|
|
|
status->global_altitude = net_buf_simple_pull_le16(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_loc_global_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS: {
|
|
|
|
struct bt_mesh_gen_loc_local_status *status = NULL;
|
|
|
|
if (buf->len != 9) {
|
|
|
|
BT_ERR("Invalid Generic Location Local Status length %d", buf->len);
|
|
|
|
return;
|
|
|
|
}
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_local_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->local_north = net_buf_simple_pull_le16(buf);
|
|
|
|
status->local_east = net_buf_simple_pull_le16(buf);
|
|
|
|
status->local_altitude = net_buf_simple_pull_le16(buf);
|
|
|
|
status->floor_number = net_buf_simple_pull_u8(buf);
|
|
|
|
status->uncertainty = net_buf_simple_pull_le16(buf);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_loc_local_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_user_properties_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_properties_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->user_property_ids = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->user_property_ids) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->user_property_ids, buf->data, buf->len);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_user_properties_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_user_property_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_property_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->user_property_id = net_buf_simple_pull_le16(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->user_access = net_buf_simple_pull_u8(buf);
|
|
|
|
status->user_property_value = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->user_property_value) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->user_property_value, buf->data, buf->len);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_user_property_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_admin_properties_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_properties_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->admin_property_ids = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->admin_property_ids) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->admin_property_ids, buf->data, buf->len);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_admin_properties_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_admin_property_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_property_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->admin_property_id = net_buf_simple_pull_le16(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->admin_user_access = net_buf_simple_pull_u8(buf);
|
|
|
|
status->admin_property_value = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->admin_property_value) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->admin_property_value, buf->data, buf->len);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_admin_property_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_manu_properties_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_properties_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->manu_property_ids = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->manu_property_ids) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->manu_property_ids, buf->data, buf->len);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_manu_properties_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_manu_property_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_property_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->manu_property_id = net_buf_simple_pull_le16(buf);
|
|
|
|
if (buf->len) {
|
|
|
|
status->op_en = true;
|
|
|
|
status->manu_user_access = net_buf_simple_pull_u8(buf);
|
|
|
|
status->manu_property_value = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->manu_property_value) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->manu_property_value, buf->data, buf->len);
|
|
|
|
}
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_manu_property_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_client_properties_status *status = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_client_properties_status));
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!status) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
status->client_property_ids = bt_mesh_alloc_buf(buf->len);
|
|
|
|
if (!status->client_property_ids) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(status);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
net_buf_simple_add_mem(status->client_property_ids, buf->data, buf->len);
|
2020-12-07 04:03:11 -05:00
|
|
|
val = (uint8_t *)status;
|
2019-01-07 02:16:47 -05:00
|
|
|
len = sizeof(struct bt_mesh_gen_client_properties_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Status opcode 0x%04x", ctx->recv_op);
|
2019-01-07 02:16:47 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf->data = val;
|
|
|
|
buf->len = len;
|
2019-09-16 03:05:14 -04:00
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
bt_mesh_mutex_lock(&generic_client_lock);
|
2019-09-16 03:05:14 -04:00
|
|
|
|
2019-09-02 00:06:20 -04:00
|
|
|
node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true);
|
2019-01-07 02:16:47 -05:00
|
|
|
if (!node) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_DBG("Unexpected Generic Status 0x%04x", ctx->recv_op);
|
2019-01-07 02:16:47 -05:00
|
|
|
} else {
|
|
|
|
switch (node->opcode) {
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_BATTERY_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
2019-09-02 01:01:06 -04:00
|
|
|
evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE;
|
2019-01-07 02:16:47 -05:00
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DELTA_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MOVE_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET:
|
2019-09-02 01:01:06 -04:00
|
|
|
evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE;
|
2019-01-07 02:16:47 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-16 03:05:14 -04:00
|
|
|
if (!k_delayed_work_free(&node->timer)) {
|
2020-12-07 04:03:11 -05:00
|
|
|
uint32_t opcode = node->opcode;
|
2019-09-26 07:38:25 -04:00
|
|
|
bt_mesh_client_free_node(node);
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_generic_client_cb_evt_to_btc(opcode, evt, model, ctx, val, len);
|
2019-09-16 03:05:14 -04:00
|
|
|
}
|
2019-01-07 02:16:47 -05:00
|
|
|
}
|
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
bt_mesh_mutex_unlock(&generic_client_lock);
|
2019-09-16 03:05:14 -04:00
|
|
|
|
2019-09-26 07:38:25 -04:00
|
|
|
switch (ctx->recv_op) {
|
2019-01-07 02:16:47 -05:00
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_user_properties_status *status;
|
|
|
|
status = (struct bt_mesh_gen_user_properties_status *)val;
|
|
|
|
bt_mesh_free_buf(status->user_property_ids);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_user_property_status *status;
|
|
|
|
status = (struct bt_mesh_gen_user_property_status *)val;
|
|
|
|
bt_mesh_free_buf(status->user_property_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_admin_properties_status *status;
|
|
|
|
status = (struct bt_mesh_gen_admin_properties_status *)val;
|
|
|
|
bt_mesh_free_buf(status->admin_property_ids);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_admin_property_status *status;
|
|
|
|
status = (struct bt_mesh_gen_admin_property_status *)val;
|
|
|
|
bt_mesh_free_buf(status->admin_property_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_manu_properties_status *status;
|
|
|
|
status = (struct bt_mesh_gen_manu_properties_status *)val;
|
|
|
|
bt_mesh_free_buf(status->manu_property_ids);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: {
|
|
|
|
struct bt_mesh_gen_manu_property_status *status;
|
|
|
|
status = (struct bt_mesh_gen_manu_property_status *)val;
|
|
|
|
bt_mesh_free_buf(status->manu_property_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: {
|
|
|
|
struct bt_mesh_gen_client_properties_status *status;
|
|
|
|
status = (struct bt_mesh_gen_client_properties_status *)val;
|
|
|
|
bt_mesh_free_buf(status->client_property_ids);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-19 05:57:13 -05:00
|
|
|
bt_mesh_free(val);
|
2019-01-07 02:16:47 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS, 2, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS, 1, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS, 1, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS, 5, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS, 8, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS, 10, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS, 9, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[] = {
|
2019-01-07 02:16:47 -05:00
|
|
|
{ BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS, 2, generic_status },
|
|
|
|
{ BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS, 2, generic_status },
|
|
|
|
BLE_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2019-09-02 00:06:20 -04:00
|
|
|
static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_GEN_GET_STATE_MSG_LEN);
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, common->opcode);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
switch (common->opcode) {
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: {
|
|
|
|
struct bt_mesh_gen_user_property_get *get;
|
|
|
|
get = (struct bt_mesh_gen_user_property_get *)value;
|
|
|
|
net_buf_simple_add_le16(&msg, get->user_property_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: {
|
|
|
|
struct bt_mesh_gen_admin_property_get *get;
|
|
|
|
get = (struct bt_mesh_gen_admin_property_get *)value;
|
|
|
|
net_buf_simple_add_le16(&msg, get->admin_property_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: {
|
|
|
|
struct bt_mesh_gen_manu_property_get *get;
|
|
|
|
get = (struct bt_mesh_gen_manu_property_get *)value;
|
|
|
|
net_buf_simple_add_le16(&msg, get->manu_property_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: {
|
|
|
|
struct bt_mesh_gen_client_properties_get *get;
|
|
|
|
get = (struct bt_mesh_gen_client_properties_get *)value;
|
|
|
|
net_buf_simple_add_le16(&msg, get->client_property_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_DBG("No parameters for Generic Get 0x%04x", common->opcode);
|
2019-01-07 02:16:47 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 21:35:31 -04:00
|
|
|
return bt_mesh_client_send_msg(common, &msg, true, timeout_handler);
|
2019-01-07 02:16:47 -05:00
|
|
|
}
|
|
|
|
|
2019-09-02 00:06:20 -04:00
|
|
|
static int gen_set_state(bt_mesh_client_common_param_t *common,
|
2020-12-07 04:03:11 -05:00
|
|
|
void *value, uint16_t value_len, bool need_ack)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
struct net_buf_simple *msg = NULL;
|
2020-01-19 05:57:13 -05:00
|
|
|
int err = 0;
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
msg = bt_mesh_alloc_buf(value_len);
|
|
|
|
if (!msg) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
2019-01-07 02:16:47 -05:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(msg, common->opcode);
|
|
|
|
|
|
|
|
switch (common->opcode) {
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_onoff_set *set;
|
|
|
|
set = (struct bt_mesh_gen_onoff_set *)value;
|
|
|
|
net_buf_simple_add_u8(msg, set->onoff);
|
|
|
|
net_buf_simple_add_u8(msg, set->tid);
|
|
|
|
if (set->op_en) {
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
net_buf_simple_add_u8(msg, set->delay);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_level_set *set;
|
|
|
|
set = (struct bt_mesh_gen_level_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->level);
|
|
|
|
net_buf_simple_add_u8(msg, set->tid);
|
|
|
|
if (set->op_en) {
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
net_buf_simple_add_u8(msg, set->delay);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DELTA_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_delta_set *set;
|
|
|
|
set = (struct bt_mesh_gen_delta_set *)value;
|
2019-09-02 01:01:06 -04:00
|
|
|
net_buf_simple_add_le32(msg, set->delta_level);
|
|
|
|
net_buf_simple_add_u8(msg, set->tid);
|
2019-01-07 02:16:47 -05:00
|
|
|
if (set->op_en) {
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
net_buf_simple_add_u8(msg, set->delay);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MOVE_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_move_set *set;
|
|
|
|
set = (struct bt_mesh_gen_move_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->delta_level);
|
|
|
|
net_buf_simple_add_u8(msg, set->tid);
|
|
|
|
if (set->op_en) {
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
net_buf_simple_add_u8(msg, set->delay);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_def_trans_time_set *set;
|
|
|
|
set = (struct bt_mesh_gen_def_trans_time_set *)value;
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_onpowerup_set *set;
|
|
|
|
set = (struct bt_mesh_gen_onpowerup_set *)value;
|
|
|
|
net_buf_simple_add_u8(msg, set->onpowerup);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_power_level_set *set;
|
|
|
|
set = (struct bt_mesh_gen_power_level_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->power);
|
|
|
|
net_buf_simple_add_u8(msg, set->tid);
|
|
|
|
if (set->op_en) {
|
|
|
|
net_buf_simple_add_u8(msg, set->trans_time);
|
|
|
|
net_buf_simple_add_u8(msg, set->delay);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_power_default_set *set;
|
|
|
|
set = (struct bt_mesh_gen_power_default_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->power);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_power_range_set *set;
|
|
|
|
set = (struct bt_mesh_gen_power_range_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->range_min);
|
|
|
|
net_buf_simple_add_le16(msg, set->range_max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_loc_global_set *set;
|
|
|
|
set = (struct bt_mesh_gen_loc_global_set *)value;
|
|
|
|
net_buf_simple_add_le32(msg, set->global_latitude);
|
|
|
|
net_buf_simple_add_le32(msg, set->global_longitude);
|
|
|
|
net_buf_simple_add_le16(msg, set->global_altitude);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_loc_local_set *set;
|
|
|
|
set = (struct bt_mesh_gen_loc_local_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->local_north);
|
|
|
|
net_buf_simple_add_le16(msg, set->local_east);
|
|
|
|
net_buf_simple_add_le16(msg, set->local_altitude);
|
|
|
|
net_buf_simple_add_u8(msg, set->floor_number);
|
|
|
|
net_buf_simple_add_le16(msg, set->uncertainty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_user_property_set *set;
|
|
|
|
set = (struct bt_mesh_gen_user_property_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->user_property_id);
|
|
|
|
net_buf_simple_add_mem(msg, set->user_property_value->data, set->user_property_value->len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_admin_property_set *set;
|
|
|
|
set = (struct bt_mesh_gen_admin_property_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->admin_property_id);
|
|
|
|
net_buf_simple_add_u8(msg, set->admin_user_access);
|
|
|
|
net_buf_simple_add_mem(msg, set->admin_property_value->data, set->admin_property_value->len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_manu_property_set *set;
|
|
|
|
set = (struct bt_mesh_gen_manu_property_set *)value;
|
|
|
|
net_buf_simple_add_le16(msg, set->manu_property_id);
|
|
|
|
net_buf_simple_add_u8(msg, set->manu_user_access);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode);
|
2019-01-07 02:16:47 -05:00
|
|
|
err = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2020-06-28 03:28:22 -04:00
|
|
|
err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler);
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
end:
|
|
|
|
bt_mesh_free_buf(msg);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-06-28 04:18:24 -04:00
|
|
|
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
bt_mesh_generic_client_t *client = NULL;
|
|
|
|
|
|
|
|
if (!common || !common->model) {
|
|
|
|
BT_ERR("%s, Invalid parameter", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (bt_mesh_generic_client_t *)common->model->user_data;
|
|
|
|
if (!client || !client->internal_data) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic client data");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (common->opcode) {
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_BATTERY_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET:
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET:
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
|
|
|
if (!get) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic User Property Get");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
|
|
|
if (!get) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Admin Property Get");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET:
|
|
|
|
if (!get) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Manu Property Get");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
|
|
|
if (!get) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Client Properties Get");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Get opcode 0x%04x", common->opcode);
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gen_get_state(common, get);
|
|
|
|
}
|
|
|
|
|
2020-06-28 04:18:24 -04:00
|
|
|
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
bt_mesh_generic_client_t *client = NULL;
|
2020-12-07 04:03:11 -05:00
|
|
|
uint16_t length = 0U;
|
2020-01-19 05:57:13 -05:00
|
|
|
bool need_ack = false;
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
if (!common || !common->model || !set) {
|
|
|
|
BT_ERR("%s, Invalid parameter", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (bt_mesh_generic_client_t *)common->model->user_data;
|
|
|
|
if (!client || !client->internal_data) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic client data");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (common->opcode) {
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_onoff_set *value;
|
|
|
|
value = (struct bt_mesh_gen_onoff_set *)set;
|
|
|
|
if (value->op_en) {
|
|
|
|
if ((value->trans_time & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic OnOff Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_ONOFF_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_level_set *value;
|
|
|
|
value = (struct bt_mesh_gen_level_set *)set;
|
|
|
|
if (value->op_en) {
|
|
|
|
if ((value->trans_time & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Level Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_LEVEL_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DELTA_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_delta_set *value;
|
|
|
|
value = (struct bt_mesh_gen_delta_set *)set;
|
|
|
|
if (value->op_en) {
|
|
|
|
if ((value->trans_time & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Delta Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_DELTA_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MOVE_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_move_set *value;
|
|
|
|
value = (struct bt_mesh_gen_move_set *)set;
|
|
|
|
if (value->op_en) {
|
|
|
|
if ((value->trans_time & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Move Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_MOVE_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: {
|
2020-12-07 04:03:11 -05:00
|
|
|
uint8_t value = *(uint8_t *)set;
|
2019-01-07 02:16:47 -05:00
|
|
|
if ((value & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Default Trans Time Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK:
|
|
|
|
length = BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_power_level_set *value;
|
|
|
|
value = (struct bt_mesh_gen_power_level_set *)set;
|
|
|
|
if (value->op_en) {
|
|
|
|
if ((value->trans_time & 0x3F) > 0x3E) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Power Level Set transition time");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK:
|
|
|
|
length = BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_power_range_set *value;
|
|
|
|
value = (struct bt_mesh_gen_power_range_set *)set;
|
|
|
|
if (value->range_min > value->range_max) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Generic Power Level Set range min is greater than range max");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
length = BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK:
|
|
|
|
length = BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK:
|
|
|
|
length = BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_user_property_set *value;
|
|
|
|
value = (struct bt_mesh_gen_user_property_set *)set;
|
|
|
|
if (!value->user_property_value) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic User Property value");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
length = (1 + 2 + value->user_property_value->len + 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: {
|
|
|
|
struct bt_mesh_gen_admin_property_set *value;
|
|
|
|
value = (struct bt_mesh_gen_admin_property_set *)set;
|
|
|
|
if (!value->admin_property_value) {
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Admin Property value");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
length = (1 + 2 + 1 + value->admin_property_value->len + 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET:
|
|
|
|
need_ack = true;
|
|
|
|
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK:
|
|
|
|
length = BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN;
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-04 06:35:08 -04:00
|
|
|
BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode);
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gen_set_state(common, set, length, need_ack);
|
|
|
|
}
|
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
static int generic_client_init(struct bt_mesh_model *model)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
generic_internal_data_t *internal = NULL;
|
|
|
|
bt_mesh_generic_client_t *client = NULL;
|
|
|
|
|
|
|
|
if (!model) {
|
2020-07-07 06:25:29 -04:00
|
|
|
BT_ERR("Invalid Generic client model");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (bt_mesh_generic_client_t *)model->user_data;
|
|
|
|
if (!client) {
|
2020-07-07 06:25:29 -04:00
|
|
|
BT_ERR("No Generic client context provided");
|
2019-01-07 02:16:47 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
if (client->internal_data) {
|
|
|
|
BT_WARN("%s, Already", __func__);
|
|
|
|
return -EALREADY;
|
|
|
|
}
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
internal = bt_mesh_calloc(sizeof(generic_internal_data_t));
|
|
|
|
if (!internal) {
|
|
|
|
BT_ERR("%s, Out of memory", __func__);
|
|
|
|
return -ENOMEM;
|
2019-12-20 01:08:33 -05:00
|
|
|
}
|
2019-01-07 02:16:47 -05:00
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
sys_slist_init(&internal->queue);
|
|
|
|
|
|
|
|
client->model = model;
|
|
|
|
client->op_pair_size = ARRAY_SIZE(gen_op_pair);
|
|
|
|
client->op_pair = gen_op_pair;
|
|
|
|
client->internal_data = internal;
|
|
|
|
|
|
|
|
bt_mesh_mutex_create(&generic_client_lock);
|
2019-09-16 03:05:14 -04:00
|
|
|
|
2019-01-07 02:16:47 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-15 22:19:31 -04:00
|
|
|
#if CONFIG_BLE_MESH_DEINIT
|
2020-07-07 06:25:29 -04:00
|
|
|
static int generic_client_deinit(struct bt_mesh_model *model)
|
2020-01-19 05:57:13 -05:00
|
|
|
{
|
|
|
|
bt_mesh_generic_client_t *client = NULL;
|
|
|
|
|
|
|
|
if (!model) {
|
2020-07-07 06:25:29 -04:00
|
|
|
BT_ERR("Invalid Generic client model");
|
2020-01-19 05:57:13 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (bt_mesh_generic_client_t *)model->user_data;
|
|
|
|
if (!client) {
|
2020-07-07 06:25:29 -04:00
|
|
|
BT_ERR("No Generic client context provided");
|
2020-01-19 05:57:13 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client->internal_data) {
|
|
|
|
/* Remove items from the list */
|
|
|
|
bt_mesh_client_clear_list(client->internal_data);
|
|
|
|
|
|
|
|
/* Free the allocated internal data */
|
|
|
|
bt_mesh_free(client->internal_data);
|
|
|
|
client->internal_data = NULL;
|
|
|
|
}
|
|
|
|
|
2023-08-28 04:09:37 -04:00
|
|
|
bt_mesh_mutex_free(&generic_client_lock);
|
2020-01-19 05:57:13 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-15 22:19:31 -04:00
|
|
|
#endif /* CONFIG_BLE_MESH_DEINIT */
|
2020-01-19 05:57:13 -05:00
|
|
|
|
2020-07-07 06:25:29 -04:00
|
|
|
const struct bt_mesh_model_cb bt_mesh_generic_client_cb = {
|
|
|
|
.init = generic_client_init,
|
2020-10-15 22:19:31 -04:00
|
|
|
#if CONFIG_BLE_MESH_DEINIT
|
2020-07-07 06:25:29 -04:00
|
|
|
.deinit = generic_client_deinit,
|
2020-10-15 22:19:31 -04:00
|
|
|
#endif /* CONFIG_BLE_MESH_DEINIT */
|
2020-07-07 06:25:29 -04:00
|
|
|
};
|
2020-10-16 03:15:18 -04:00
|
|
|
|
2020-10-16 04:10:28 -04:00
|
|
|
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
|