diff --git a/nimble/host/mesh/src/cfg_srv.c b/nimble/host/mesh/src/cfg_srv.c index 5cac1ad29..c1bb6319a 100644 --- a/nimble/host/mesh/src/cfg_srv.c +++ b/nimble/host/mesh/src/cfg_srv.c @@ -808,7 +808,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model, bt_mesh_adv_update(); if (cfg->hb_pub.feat & BT_MESH_FEAT_PROXY) { - bt_mesh_heartbeat_send(); + (void)bt_mesh_heartbeat_send(NULL, NULL); } send_status: @@ -928,7 +928,7 @@ static void relay_set(struct bt_mesh_model *model, BT_MESH_TRANSMIT_INT(cfg->relay_retransmit)); if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && change) { - bt_mesh_heartbeat_send(); + (void)bt_mesh_heartbeat_send(NULL, NULL); } } else { BT_WARN("Invalid Relay value 0x%02x", buf->om_data[0]); @@ -2782,7 +2782,7 @@ static void friend_set(struct bt_mesh_model *model, } if (cfg->hb_pub.feat & BT_MESH_FEAT_FRIEND) { - bt_mesh_heartbeat_send(); + (void)bt_mesh_heartbeat_send(NULL, NULL); } send_status: @@ -3283,11 +3283,38 @@ const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = { BT_MESH_MODEL_OP_END, }; +static void hb_publish_end_cb(int err, void *cb_data) +{ + struct bt_mesh_cfg_srv *cfg = cb_data; + uint16_t period_ms; + + period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000U; + if (period_ms && cfg->hb_pub.count > 1) { + k_delayed_work_submit(&cfg->hb_pub.timer, K_MSEC(period_ms)); + } + + if (cfg->hb_pub.count != 0xffff) { + cfg->hb_pub.count--; + } +} + +static void hb_publish_start_cb(uint16_t duration, int err, void *cb_data) +{ + if (err) { + hb_publish_end_cb(err, cb_data); + } +} + static void hb_publish(struct ble_npl_event *work) { + static const struct bt_mesh_send_cb publish_cb = { + .start = hb_publish_start_cb, + .end = hb_publish_end_cb, + }; + struct bt_mesh_cfg_srv *cfg = ble_npl_event_get_arg(work); struct bt_mesh_subnet *sub; - u16_t period_ms; + int err; BT_DBG("hb_pub.count: %u", cfg->hb_pub.count); @@ -3303,15 +3330,9 @@ static void hb_publish(struct ble_npl_event *work) return; } - period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000; - if (period_ms && cfg->hb_pub.count > 1) { - k_delayed_work_submit(&cfg->hb_pub.timer, period_ms); - } - - bt_mesh_heartbeat_send(); - - if (cfg->hb_pub.count != 0xffff) { - cfg->hb_pub.count--; + err = bt_mesh_heartbeat_send(&publish_cb, cfg); + if (err) { + hb_publish_end_cb(err, cfg); } } diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c index ec012a5f0..0bfc00a17 100644 --- a/nimble/host/mesh/src/lpn.c +++ b/nimble/host/mesh/src/lpn.c @@ -243,7 +243,7 @@ static void clear_friendship(bool force, bool disable) lpn->groups_changed = 1; if (cfg->hb_pub.feat & BT_MESH_FEAT_LOW_POWER) { - bt_mesh_heartbeat_send(); + (void)bt_mesh_heartbeat_send(NULL, NULL); } if (disable) { @@ -961,7 +961,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, BT_INFO("Friendship established with 0x%04x", lpn->frnd); if (cfg->hb_pub.feat & BT_MESH_FEAT_LOW_POWER) { - bt_mesh_heartbeat_send(); + (void)bt_mesh_heartbeat_send(NULL, NULL); } if (lpn_cb) { diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c index caf1b4f12..e771867cd 100644 --- a/nimble/host/mesh/src/transport.c +++ b/nimble/host/mesh/src/transport.c @@ -1569,7 +1569,7 @@ void bt_mesh_rpl_clear(void) memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); } -void bt_mesh_heartbeat_send(void) +int bt_mesh_heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data) { struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); u16_t feat = 0U; @@ -1592,7 +1592,7 @@ void bt_mesh_heartbeat_send(void) /* Do nothing if heartbeat publication is not enabled */ if (cfg->hb_pub.dst == BT_MESH_ADDR_UNASSIGNED) { - return; + return 0; } hb.init_ttl = cfg->hb_pub.ttl; @@ -1617,8 +1617,8 @@ void bt_mesh_heartbeat_send(void) 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); + return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb), + NULL, cb, cb_data); } int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx, diff --git a/nimble/host/mesh/src/transport.h b/nimble/host/mesh/src/transport.h index eff768e9f..8bcbff071 100644 --- a/nimble/host/mesh/src/transport.h +++ b/nimble/host/mesh/src/transport.h @@ -99,7 +99,7 @@ void bt_mesh_trans_init(void); void bt_mesh_rpl_clear(void); -void bt_mesh_heartbeat_send(void); +int bt_mesh_heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data); int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx, u16_t addr, const u8_t **key, u8_t *aid);