Commit 9af051e3 authored by Pavel Vasilyev's avatar Pavel Vasilyev Committed by Henrik Brix Andersen
Browse files

Bluetooth: Mesh: Call bt_mesh_send_cb.end cb by the end of adv



Before this change, the bt_mesh_send_cb.end callback was called when all
references to the adv were removed. If an implementation kept more
references to the adv buffer after calling `bt_mesh_adv_send`, the end
callback would not be called when the advertiser finished advertising
this adv.

With this change, the end callback is always called by the advertiser
when the advertisement is finished regardless of the number of
references. This allows an implementation to keep the adv buffer for the
future use. As an example, pb_adv.c keeps advs for retransmission.

Signed-off-by: default avatarPavel Vasilyev <pavel.vasilyev@nordicsemi.no>
parent 6cb98162
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv_ctx *
	}
}

static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx)
void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx)
{
	if (ctx->started && ctx->cb && ctx->cb->end) {
		ctx->cb->end(err, ctx->cb_data);
@@ -136,7 +136,6 @@ void bt_mesh_adv_unref(struct bt_mesh_adv *adv)
	}

	struct k_mem_slab *slab = &local_adv_pool;
	struct bt_mesh_adv_ctx ctx = adv->ctx;

#if defined(CONFIG_BT_MESH_RELAY)
	if (adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) {
@@ -151,7 +150,6 @@ void bt_mesh_adv_unref(struct bt_mesh_adv *adv)
#endif

	k_mem_slab_free(slab, (void *)adv);
	bt_mesh_adv_send_end(0, &ctx);
}

struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type,
+1 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type,

void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb,
		      void *cb_data);
void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx);

struct bt_mesh_adv *bt_mesh_adv_get(k_timeout_t timeout);

+5 −0
Original line number Diff line number Diff line
@@ -259,7 +259,12 @@ static void send_pending_adv(struct k_work *work)
		atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);

		if (ext_adv->adv) {
			struct bt_mesh_adv_ctx ctx = ext_adv->adv->ctx;

			ext_adv->adv->ctx.started = 0;
			bt_mesh_adv_unref(ext_adv->adv);
			bt_mesh_adv_send_end(0, &ctx);

			ext_adv->adv = NULL;
		}

+4 −0
Original line number Diff line number Diff line
@@ -182,7 +182,11 @@ static void adv_thread(void *p1, void *p2, void *p3)
			adv_send(adv);
		}

		struct bt_mesh_adv_ctx ctx = adv->ctx;

		adv->ctx.started = 0;
		bt_mesh_adv_unref(adv);
		bt_mesh_adv_send_end(0, &ctx);

		/* Give other threads a chance to run */
		k_yield();