2017-06-16 12:30:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2017-06-16 12:30:54 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <zephyr/types.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/sys/byteorder.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/mesh.h>
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "access.h"
|
|
|
|
#include "foundation.h"
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(bt_mesh_health_srv);
|
|
|
|
|
2017-06-16 12:30:54 +03:00
|
|
|
#define HEALTH_TEST_STANDARD 0x00
|
|
|
|
|
|
|
|
/* Health Server context of the primary element */
|
2017-11-13 21:38:52 +02:00
|
|
|
struct bt_mesh_health_srv *health_srv;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static void health_get_registered(const struct bt_mesh_model *mod,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id,
|
2017-06-16 12:30:54 +03:00
|
|
|
struct net_buf_simple *msg)
|
|
|
|
{
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = mod->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *test_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("Company ID 0x%04x", company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
bt_mesh_model_msg_init(msg, OP_HEALTH_FAULT_STATUS);
|
|
|
|
|
|
|
|
test_id = net_buf_simple_add(msg, 1);
|
|
|
|
net_buf_simple_add_le16(msg, company_id);
|
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_get_reg) {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t fault_count = net_buf_simple_tailroom(msg) - 4;
|
2017-11-26 17:09:20 +02:00
|
|
|
int err;
|
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
err = srv->cb->fault_get_reg(mod, company_id, test_id,
|
|
|
|
net_buf_simple_tail(msg),
|
|
|
|
&fault_count);
|
2017-06-16 12:30:54 +03:00
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to get faults (err %d)", err);
|
2017-06-16 12:30:54 +03:00
|
|
|
*test_id = HEALTH_TEST_STANDARD;
|
|
|
|
} else {
|
|
|
|
net_buf_simple_add(msg, fault_count);
|
|
|
|
}
|
|
|
|
} else {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_WRN("No callback for getting faults");
|
2017-06-16 12:30:54 +03:00
|
|
|
*test_id = HEALTH_TEST_STANDARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static size_t health_get_current(const struct bt_mesh_model *mod,
|
2017-06-16 12:30:54 +03:00
|
|
|
struct net_buf_simple *msg)
|
|
|
|
{
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = mod->rt->user_data;
|
2017-09-27 10:02:04 +03:00
|
|
|
const struct bt_mesh_comp *comp;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *test_id, *company_ptr;
|
|
|
|
uint16_t company_id;
|
|
|
|
uint8_t fault_count;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
bt_mesh_model_msg_init(msg, OP_HEALTH_CURRENT_STATUS);
|
|
|
|
|
2017-08-03 13:16:07 +03:00
|
|
|
test_id = net_buf_simple_add(msg, 1);
|
2017-06-16 12:30:54 +03:00
|
|
|
company_ptr = net_buf_simple_add(msg, sizeof(company_id));
|
2017-09-27 10:02:04 +03:00
|
|
|
comp = bt_mesh_comp_get();
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_get_cur) {
|
2017-11-26 16:48:59 +02:00
|
|
|
fault_count = net_buf_simple_tailroom(msg);
|
2021-04-14 13:17:59 +02:00
|
|
|
int err;
|
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
err = srv->cb->fault_get_cur(mod, test_id, &company_id,
|
|
|
|
net_buf_simple_tail(msg),
|
|
|
|
&fault_count);
|
2017-06-16 12:30:54 +03:00
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to get faults (err %d)", err);
|
2017-09-27 10:02:04 +03:00
|
|
|
sys_put_le16(comp->cid, company_ptr);
|
2017-06-16 12:30:54 +03:00
|
|
|
*test_id = HEALTH_TEST_STANDARD;
|
2018-11-29 11:23:03 -08:00
|
|
|
fault_count = 0U;
|
2017-06-16 12:30:54 +03:00
|
|
|
} else {
|
|
|
|
sys_put_le16(company_id, company_ptr);
|
2017-09-28 16:56:49 +03:00
|
|
|
net_buf_simple_add(msg, fault_count);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
} else {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_WRN("No callback for getting faults");
|
2017-09-27 10:02:04 +03:00
|
|
|
sys_put_le16(comp->cid, company_ptr);
|
2017-09-27 09:55:40 +03:00
|
|
|
*test_id = HEALTH_TEST_STANDARD;
|
2018-11-29 11:23:03 -08:00
|
|
|
fault_count = 0U;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return fault_count;
|
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_fault_get(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
company_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("company_id 0x%04x", company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
health_get_registered(model, company_id, &sdu);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to send Health Current Status response");
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_fault_clear_unrel(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
company_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("company_id 0x%04x", company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_clear) {
|
2021-04-14 13:17:59 +02:00
|
|
|
return srv->cb->fault_clear(model, company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_fault_clear(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
company_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("company_id 0x%04x", company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_clear) {
|
2021-04-14 13:17:59 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = srv->cb->fault_clear(model, company_id);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
health_get_registered(model, company_id, &sdu);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to send Health Current Status response");
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_fault_test_unrel(const struct bt_mesh_model *model,
|
2017-06-16 12:30:54 +03:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id;
|
|
|
|
uint8_t test_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
test_id = net_buf_simple_pull_u8(buf);
|
|
|
|
company_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("test 0x%02x company 0x%04x", test_id, company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_test) {
|
2021-04-14 13:17:59 +02:00
|
|
|
return srv->cb->fault_test(model, test_id, company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_fault_test(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_TX_SDU_MAX);
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t company_id;
|
|
|
|
uint8_t test_id;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
test_id = net_buf_simple_pull_u8(buf);
|
|
|
|
company_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("test 0x%02x company 0x%04x", test_id, company_id);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->fault_test) {
|
2017-09-28 23:21:53 +03:00
|
|
|
int err;
|
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
err = srv->cb->fault_test(model, test_id, company_id);
|
2017-09-28 23:21:53 +03:00
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_WRN("Running fault test failed with err %d", err);
|
2021-04-14 13:17:59 +02:00
|
|
|
return err;
|
2017-09-28 23:21:53 +03:00
|
|
|
}
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
health_get_registered(model, company_id, &sdu);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to send Health Current Status response");
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int send_attention_status(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
|
|
|
/* Needed size: opcode (2 bytes) + msg + MIC */
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_STATUS, 1);
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t time;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-03-08 12:44:37 -06:00
|
|
|
time = k_ticks_to_ms_floor32(
|
|
|
|
k_work_delayable_remaining_get(&srv->attn_timer)) / 1000U;
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("%u second%s", time, (time == 1U) ? "" : "s");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_ATTENTION_STATUS);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_u8(&msg, time);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to send Attention Status");
|
2017-11-21 21:22:46 +02:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int attention_get(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return send_attention_status(model, ctx);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int attention_set_unrel(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t time;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
time = net_buf_simple_pull_u8(buf);
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("%u second%s", time, (time == 1U) ? "" : "s");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
bt_mesh_attention(model, time);
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int attention_set(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2021-04-27 15:59:54 +02:00
|
|
|
int err;
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
err = attention_set_unrel(model, ctx, buf);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return send_attention_status(model, ctx);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int send_health_period_status(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
|
|
|
/* Needed size: opcode (2 bytes) + msg + MIC */
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_STATUS, 1);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_STATUS);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_u8(&msg, model->pub->period_div);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to send Health Period Status");
|
2017-11-21 21:22:46 +02:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_period_get(const struct bt_mesh_model *model,
|
2017-06-16 12:30:54 +03:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return send_health_period_status(model, ctx);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_period_set_unrel(const struct bt_mesh_model *model,
|
2017-06-16 12:30:54 +03:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t period;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
period = net_buf_simple_pull_u8(buf);
|
|
|
|
if (period > 15) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_WRN("Prohibited period value %u", period);
|
2021-04-14 13:17:59 +02:00
|
|
|
return -EINVAL;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("period %u", period);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2017-09-28 23:05:13 +03:00
|
|
|
model->pub->period_div = period;
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_period_set(const struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2021-04-27 15:59:54 +02:00
|
|
|
int err;
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
err = health_period_set_unrel(model, ctx, buf);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-06-16 12:30:54 +03:00
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return send_health_period_status(model, ctx);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2017-11-13 21:38:52 +02:00
|
|
|
const struct bt_mesh_model_op bt_mesh_health_srv_op[] = {
|
2021-04-27 15:59:54 +02:00
|
|
|
{ OP_HEALTH_FAULT_GET, BT_MESH_LEN_EXACT(2), health_fault_get },
|
|
|
|
{ OP_HEALTH_FAULT_CLEAR, BT_MESH_LEN_EXACT(2), health_fault_clear },
|
|
|
|
{ OP_HEALTH_FAULT_CLEAR_UNREL, BT_MESH_LEN_EXACT(2), health_fault_clear_unrel },
|
|
|
|
{ OP_HEALTH_FAULT_TEST, BT_MESH_LEN_EXACT(3), health_fault_test },
|
|
|
|
{ OP_HEALTH_FAULT_TEST_UNREL, BT_MESH_LEN_EXACT(3), health_fault_test_unrel },
|
|
|
|
{ OP_HEALTH_PERIOD_GET, BT_MESH_LEN_EXACT(0), health_period_get },
|
|
|
|
{ OP_HEALTH_PERIOD_SET, BT_MESH_LEN_EXACT(1), health_period_set },
|
|
|
|
{ OP_HEALTH_PERIOD_SET_UNREL, BT_MESH_LEN_EXACT(1), health_period_set_unrel },
|
|
|
|
{ OP_ATTENTION_GET, BT_MESH_LEN_EXACT(0), attention_get },
|
|
|
|
{ OP_ATTENTION_SET, BT_MESH_LEN_EXACT(1), attention_set },
|
|
|
|
{ OP_ATTENTION_SET_UNREL, BT_MESH_LEN_EXACT(1), attention_set_unrel },
|
2017-06-16 12:30:54 +03:00
|
|
|
BT_MESH_MODEL_OP_END,
|
|
|
|
};
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_pub_update(const struct bt_mesh_model *mod)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
struct bt_mesh_model_pub *pub = mod->pub;
|
2017-06-16 12:30:54 +03:00
|
|
|
size_t count;
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
count = health_get_current(mod, pub->msg);
|
2019-04-11 17:38:30 +03:00
|
|
|
if (count) {
|
|
|
|
pub->fast_period = 1U;
|
|
|
|
} else {
|
|
|
|
pub->fast_period = 0U;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2017-11-20 17:13:44 +02:00
|
|
|
return 0;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2023-11-17 09:36:34 +08:00
|
|
|
int bt_mesh_health_srv_fault_update(const struct bt_mesh_elem *elem)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2023-11-14 12:00:30 +08:00
|
|
|
const struct bt_mesh_model *mod;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
mod = bt_mesh_model_find(elem, BT_MESH_MODEL_ID_HEALTH_SRV);
|
|
|
|
if (!mod) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-04-11 17:38:30 +03:00
|
|
|
/* Let periodic publishing, if enabled, take care of sending the
|
|
|
|
* Health Current Status.
|
|
|
|
*/
|
2020-04-06 13:56:14 +02:00
|
|
|
if (bt_mesh_model_pub_period_get(mod) > 0) {
|
2019-04-11 17:38:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-09 19:20:25 +03:00
|
|
|
health_pub_update(mod);
|
|
|
|
|
2017-11-26 16:48:59 +02:00
|
|
|
return bt_mesh_model_publish(mod);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void attention_off(struct k_work *work)
|
|
|
|
{
|
2021-03-08 12:44:37 -06:00
|
|
|
struct k_work_delayable *dwork = k_work_delayable_from_work(work);
|
|
|
|
struct bt_mesh_health_srv *srv = CONTAINER_OF(dwork,
|
2017-11-13 21:38:52 +02:00
|
|
|
struct bt_mesh_health_srv,
|
2021-03-08 12:44:37 -06:00
|
|
|
attn_timer);
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2017-06-16 12:30:54 +03:00
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (srv->cb && srv->cb->attn_off) {
|
|
|
|
srv->cb->attn_off(srv->model);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
static int health_srv_init(const struct bt_mesh_model *model)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2023-11-15 18:03:40 +08:00
|
|
|
struct bt_mesh_health_srv *srv = model->rt->user_data;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
if (!srv) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("No Health Server context provided");
|
2017-06-16 12:30:54 +03:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
if (!model->pub) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Health Server has no publication support");
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-09-05 13:38:19 +08:00
|
|
|
model->pub->update = health_pub_update;
|
Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:
- The Publish Retransmit State was not taken into account at all
- Health Server used a single publish state for all elements
To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.
Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.
To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.
The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.
The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-18 10:24:18 +02:00
|
|
|
|
2021-03-08 12:44:37 -06:00
|
|
|
k_work_init_delayable(&srv->attn_timer, attention_off);
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
srv->model = model;
|
|
|
|
|
2019-08-19 10:05:36 +02:00
|
|
|
if (bt_mesh_model_in_primary(model)) {
|
2017-06-16 12:30:54 +03:00
|
|
|
health_srv = srv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-19 10:05:36 +02:00
|
|
|
const struct bt_mesh_model_cb bt_mesh_health_srv_cb = {
|
|
|
|
.init = health_srv_init,
|
|
|
|
};
|
|
|
|
|
2023-11-14 12:00:30 +08:00
|
|
|
void bt_mesh_attention(const struct bt_mesh_model *model, uint8_t time)
|
2017-06-16 12:30:54 +03:00
|
|
|
{
|
2017-11-13 21:38:52 +02:00
|
|
|
struct bt_mesh_health_srv *srv;
|
2017-06-16 12:30:54 +03:00
|
|
|
|
|
|
|
if (!model) {
|
|
|
|
srv = health_srv;
|
|
|
|
if (!srv) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_WRN("No Health Server available");
|
2017-06-16 12:30:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
model = srv->model;
|
|
|
|
} else {
|
2023-11-15 18:03:40 +08:00
|
|
|
srv = model->rt->user_data;
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
|
|
|
|
2021-03-08 12:44:37 -06:00
|
|
|
if ((time > 0) && srv->cb && srv->cb->attn_on) {
|
|
|
|
srv->cb->attn_on(model);
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|
2021-03-08 12:44:37 -06:00
|
|
|
|
|
|
|
k_work_reschedule(&srv->attn_timer, K_SECONDS(time));
|
2017-06-16 12:30:54 +03:00
|
|
|
}
|