Bluetooth: Mesh: Move heartbeat sending to transport layer
The heartbeat is a transport layer feature, so move it to transport.c. This also opens the way to properly fix Friendship-established/lost triggering for LPN role. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
c7d6c310c6
commit
ed71fc9a9e
3 changed files with 55 additions and 55 deletions
|
@ -47,56 +47,6 @@ static struct label {
|
|||
u8_t uuid[16];
|
||||
} labels[CONFIG_BT_MESH_LABEL_COUNT];
|
||||
|
||||
static void hb_send(struct bt_mesh_model *model)
|
||||
{
|
||||
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t feat = 0U;
|
||||
struct __packed {
|
||||
u8_t init_ttl;
|
||||
u16_t feat;
|
||||
} hb;
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
.net_idx = cfg->hb_pub.net_idx,
|
||||
.app_idx = BT_MESH_KEY_UNUSED,
|
||||
.addr = cfg->hb_pub.dst,
|
||||
.send_ttl = cfg->hb_pub.ttl,
|
||||
};
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx),
|
||||
.ctx = &ctx,
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
|
||||
hb.init_ttl = cfg->hb_pub.ttl;
|
||||
|
||||
if (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED) {
|
||||
feat |= BT_MESH_FEAT_RELAY;
|
||||
}
|
||||
|
||||
if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) {
|
||||
feat |= BT_MESH_FEAT_PROXY;
|
||||
}
|
||||
|
||||
if (bt_mesh_friend_get() == BT_MESH_FRIEND_ENABLED) {
|
||||
feat |= BT_MESH_FEAT_FRIEND;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_MESH_LOW_POWER)
|
||||
if (bt_mesh.lpn.state != BT_MESH_LPN_DISABLED) {
|
||||
feat |= BT_MESH_FEAT_LOW_POWER;
|
||||
}
|
||||
#endif
|
||||
|
||||
hb.feat = sys_cpu_to_be16(feat);
|
||||
|
||||
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
|
||||
|
||||
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
|
||||
bool primary)
|
||||
{
|
||||
|
@ -872,7 +822,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
|||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BT_MESH_FEAT_PROXY) && sub) {
|
||||
hb_send(model);
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
|
||||
send_status:
|
||||
|
@ -990,7 +940,7 @@ static void relay_set(struct bt_mesh_model *model,
|
|||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && sub && change) {
|
||||
hb_send(model);
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
} else {
|
||||
BT_WARN("Invalid Relay value 0x%02x", buf->data[0]);
|
||||
|
@ -2746,7 +2696,7 @@ static void friend_set(struct bt_mesh_model *model,
|
|||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BT_MESH_FEAT_FRIEND) && sub) {
|
||||
hb_send(model);
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
|
||||
send_status:
|
||||
|
@ -3243,7 +3193,6 @@ static void hb_publish(struct k_work *work)
|
|||
struct bt_mesh_cfg_srv *cfg = CONTAINER_OF(work,
|
||||
struct bt_mesh_cfg_srv,
|
||||
hb_pub.timer.work);
|
||||
struct bt_mesh_model *model = cfg->model;
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t period_ms;
|
||||
|
||||
|
@ -3266,7 +3215,7 @@ static void hb_publish(struct k_work *work)
|
|||
k_delayed_work_submit(&cfg->hb_pub.timer, period_ms);
|
||||
}
|
||||
|
||||
hb_send(model);
|
||||
bt_mesh_heartbeat_send();
|
||||
|
||||
if (cfg->hb_pub.count != 0xffff) {
|
||||
cfg->hb_pub.count--;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue