Bluetooth: Mesh: Fix calling send start for multi-segmented messages

Using the start callback, especially with multi-segment messages, may
not be super useful for applications, but we should support if if they
do provide it. One application could e.g. be to calculate the duration
it takes for a multi-segment message to be completely received by the
remote end.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-18 13:10:42 +02:00 committed by Johan Hedberg
commit ec9aaaed23

View file

@ -198,6 +198,15 @@ static inline void seg_tx_complete(struct seg_tx *tx, int err)
seg_tx_reset(tx);
}
static void seg_send_start(u16_t duration, int err, void *user_data)
{
struct seg_tx *tx = user_data;
if (tx->cb && tx->cb->start) {
tx->cb->start(duration, err, tx->cb_data);
}
}
static void seg_sent(int err, void *user_data)
{
struct seg_tx *tx = user_data;
@ -205,6 +214,11 @@ static void seg_sent(int err, void *user_data)
k_delayed_work_submit(&tx->retransmit, SEG_RETRANSMIT_TIMEOUT);
}
static const struct bt_mesh_send_cb first_sent_cb = {
.start = seg_send_start,
.end = seg_sent,
};
static const struct bt_mesh_send_cb seg_sent_cb = {
.end = seg_sent,
};
@ -358,7 +372,9 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
BT_DBG("Sending %u/%u", seg_o, tx->seg_n);
err = bt_mesh_net_send(net_tx, seg, &seg_sent_cb, tx);
err = bt_mesh_net_send(net_tx, seg,
seg_o ? &seg_sent_cb : &first_sent_cb,
tx);
if (err) {
BT_ERR("Sending segment failed");
seg_tx_reset(tx);