Bluetooth: Mesh: Use a unified send callback also for public API
There's no need for callback exposed in the public API to be something different than what's used internally. In fact this would just complicate things. This patch exposes the internal callback under a bt_mesh_adv_cb name and uses it throughout the mesh stack. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
224506c78c
commit
4bf045e282
12 changed files with 63 additions and 63 deletions
|
@ -267,7 +267,10 @@ struct bt_mesh_model {
|
|||
void *user_data;
|
||||
};
|
||||
|
||||
typedef void (*bt_mesh_cb_t)(int err, void *cb_data);
|
||||
struct bt_mesh_send_cb {
|
||||
void (*start)(u16_t duration, int err, void *cb_data);
|
||||
void (*end)(int err, void *cb_data);
|
||||
};
|
||||
|
||||
void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode);
|
||||
|
||||
|
@ -290,7 +293,8 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode);
|
|||
*/
|
||||
int bt_mesh_model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *msg, bt_mesh_cb_t cb,
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
/**
|
||||
|
|
|
@ -448,7 +448,7 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode)
|
|||
static int model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
int flags, struct net_buf_simple *msg,
|
||||
bt_mesh_cb_t cb, void *cb_data)
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.sub = bt_mesh_subnet_get(ctx->net_idx),
|
||||
|
@ -487,8 +487,8 @@ static int model_send(struct bt_mesh_model *model,
|
|||
|
||||
int bt_mesh_model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *msg, bt_mesh_cb_t cb,
|
||||
void *cb_data)
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
return model_send(model, ctx, 0, msg, cb, cb_data);
|
||||
}
|
||||
|
|
|
@ -71,19 +71,19 @@ static struct bt_mesh_adv *adv_alloc(int id)
|
|||
}
|
||||
|
||||
static inline void adv_send_start(u16_t duration, int err,
|
||||
const struct bt_mesh_adv_cb *cb,
|
||||
const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
if (cb && cb->send_start) {
|
||||
cb->send_start(duration, err, cb_data);
|
||||
if (cb && cb->start) {
|
||||
cb->start(duration, err, cb_data);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void adv_send_end(int err, const struct bt_mesh_adv_cb *cb,
|
||||
static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
if (cb && cb->send_end) {
|
||||
cb->send_end(err, cb_data);
|
||||
if (cb && cb->end) {
|
||||
cb->end(err, cb_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ static inline void adv_send(struct net_buf *buf)
|
|||
{
|
||||
const s32_t adv_int_min = ((bt_dev.hci_version >= BT_HCI_VERSION_5_0) ?
|
||||
ADV_INT_FAST : ADV_INT_DEFAULT);
|
||||
const struct bt_mesh_adv_cb *cb = BT_MESH_ADV(buf)->cb;
|
||||
const struct bt_mesh_send_cb *cb = BT_MESH_ADV(buf)->cb;
|
||||
void *cb_data = BT_MESH_ADV(buf)->cb_data;
|
||||
struct bt_le_adv_param param;
|
||||
u16_t duration, adv_int;
|
||||
|
@ -217,7 +217,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit_count,
|
|||
xmit_count, xmit_int, timeout);
|
||||
}
|
||||
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_adv_cb *cb,
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
BT_DBG("type 0x%02x len %u: %s", BT_MESH_ADV(buf)->type, buf->len,
|
||||
|
|
|
@ -23,13 +23,8 @@ enum bt_mesh_adv_type {
|
|||
typedef void (*bt_mesh_adv_func_t)(struct net_buf *buf, u16_t duration,
|
||||
int err, void *user_data);
|
||||
|
||||
struct bt_mesh_adv_cb {
|
||||
void (*send_start)(u16_t duration, int err, void *user_data);
|
||||
void (*send_end)(int err, void *user_data);
|
||||
};
|
||||
|
||||
struct bt_mesh_adv {
|
||||
const struct bt_mesh_adv_cb *cb;
|
||||
const struct bt_mesh_send_cb *cb;
|
||||
void *cb_data;
|
||||
|
||||
u8_t type:2,
|
||||
|
@ -59,7 +54,7 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
|||
u8_t xmit_count, u8_t xmit_int,
|
||||
s32_t timeout);
|
||||
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_adv_cb *cb,
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
void bt_mesh_adv_update(void);
|
||||
|
|
|
@ -118,8 +118,8 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
|
|||
|
||||
static int secure_beacon_send(void)
|
||||
{
|
||||
static const struct bt_mesh_adv_cb send_cb = {
|
||||
.send_end = beacon_complete,
|
||||
static const struct bt_mesh_send_cb send_cb = {
|
||||
.end = beacon_complete,
|
||||
};
|
||||
u32_t now = k_uptime_get_32();
|
||||
int i;
|
||||
|
|
|
@ -613,8 +613,8 @@ static void friend_clear_sent(int err, void *user_data)
|
|||
frnd->clear.repeat_sec *= 2;
|
||||
}
|
||||
|
||||
static const struct bt_mesh_adv_cb clear_sent_cb = {
|
||||
.send_end = friend_clear_sent,
|
||||
static const struct bt_mesh_send_cb clear_sent_cb = {
|
||||
.end = friend_clear_sent,
|
||||
};
|
||||
|
||||
static void send_friend_clear(struct bt_mesh_friend *frnd)
|
||||
|
@ -981,9 +981,9 @@ static void friend_timeout(struct k_work *work)
|
|||
{
|
||||
struct bt_mesh_friend *frnd = CONTAINER_OF(work, struct bt_mesh_friend,
|
||||
timer.work);
|
||||
static const struct bt_mesh_adv_cb buf_sent_cb = {
|
||||
.send_start = buf_send_start,
|
||||
.send_end = buf_send_end,
|
||||
static const struct bt_mesh_send_cb buf_sent_cb = {
|
||||
.start = buf_send_start,
|
||||
.end = buf_send_end,
|
||||
};
|
||||
|
||||
__ASSERT_NO_MSG(frnd->pending_buf == 0);
|
||||
|
|
|
@ -125,8 +125,8 @@ static void friend_clear_sent(int err, void *user_data)
|
|||
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_TIMEOUT);
|
||||
}
|
||||
|
||||
static const struct bt_mesh_adv_cb clear_sent_cb = {
|
||||
.send_end = friend_clear_sent,
|
||||
static const struct bt_mesh_send_cb clear_sent_cb = {
|
||||
.end = friend_clear_sent,
|
||||
};
|
||||
|
||||
static int send_friend_clear(void)
|
||||
|
@ -223,8 +223,8 @@ static void friend_req_sent(u16_t duration, int err, void *user_data)
|
|||
}
|
||||
}
|
||||
|
||||
static const struct bt_mesh_adv_cb friend_req_sent_cb = {
|
||||
.send_start = friend_req_sent,
|
||||
static const struct bt_mesh_send_cb friend_req_sent_cb = {
|
||||
.start = friend_req_sent,
|
||||
};
|
||||
|
||||
static int send_friend_req(struct bt_mesh_lpn *lpn)
|
||||
|
@ -329,8 +329,8 @@ static void req_sent(u16_t duration, int err, void *user_data)
|
|||
}
|
||||
}
|
||||
|
||||
static const struct bt_mesh_adv_cb req_sent_cb = {
|
||||
.send_start = req_sent,
|
||||
static const struct bt_mesh_send_cb req_sent_cb = {
|
||||
.start = req_sent,
|
||||
};
|
||||
|
||||
static int send_friend_poll(void)
|
||||
|
|
|
@ -670,7 +670,7 @@ do_update:
|
|||
}
|
||||
|
||||
int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
bool new_key, const struct bt_mesh_adv_cb *cb,
|
||||
bool new_key, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
const u8_t *enc, *priv;
|
||||
|
@ -800,7 +800,7 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
|
|||
}
|
||||
|
||||
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
const struct bt_mesh_adv_cb *cb, void *cb_data)
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -827,12 +827,12 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
|||
* through the Mesh Proxy.
|
||||
*/
|
||||
if (cb) {
|
||||
if (cb->send_start) {
|
||||
cb->send_start(0, 0, cb_data);
|
||||
if (cb->start) {
|
||||
cb->start(0, 0, cb_data);
|
||||
}
|
||||
|
||||
if (cb->send_end) {
|
||||
cb->send_end(0, cb_data);
|
||||
if (cb->end) {
|
||||
cb->end(0, cb_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,12 +844,12 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
|||
/* Deliver to local network interface if necessary */
|
||||
if (bt_mesh_fixed_group_match(tx->ctx->addr) ||
|
||||
bt_mesh_elem_find(tx->ctx->addr)) {
|
||||
if (cb && cb->send_start) {
|
||||
cb->send_start(0, 0, cb_data);
|
||||
if (cb && cb->start) {
|
||||
cb->start(0, 0, cb_data);
|
||||
}
|
||||
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
|
||||
if (cb && cb->send_end) {
|
||||
cb->send_end(0, cb_data);
|
||||
if (cb && cb->end) {
|
||||
cb->end(0, cb_data);
|
||||
}
|
||||
k_work_submit(&bt_mesh.local_work);
|
||||
} else {
|
||||
|
|
|
@ -310,10 +310,10 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
|
|||
bool proxy);
|
||||
|
||||
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
const struct bt_mesh_adv_cb *cb, void *cb_data);
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data);
|
||||
|
||||
int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
bool new_key, const struct bt_mesh_adv_cb *cb,
|
||||
bool new_key, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
|
|
|
@ -197,8 +197,8 @@ static void buf_sent(int err, void *user_data)
|
|||
k_delayed_work_submit(&link.tx.retransmit, RETRANSMIT_TIMEOUT);
|
||||
}
|
||||
|
||||
static struct bt_mesh_adv_cb buf_sent_cb = {
|
||||
.send_end = buf_sent,
|
||||
static struct bt_mesh_send_cb buf_sent_cb = {
|
||||
.end = buf_sent,
|
||||
};
|
||||
|
||||
static void free_segments(void)
|
||||
|
@ -282,10 +282,10 @@ static void ack_complete(u16_t duration, int err, void *user_data)
|
|||
|
||||
static void gen_prov_ack_send(u8_t xact_id)
|
||||
{
|
||||
static const struct bt_mesh_adv_cb cb = {
|
||||
.send_start = ack_complete,
|
||||
static const struct bt_mesh_send_cb cb = {
|
||||
.start = ack_complete,
|
||||
};
|
||||
const struct bt_mesh_adv_cb *complete;
|
||||
const struct bt_mesh_send_cb *complete;
|
||||
struct net_buf *buf;
|
||||
|
||||
BT_DBG("xact_id %u", xact_id);
|
||||
|
|
|
@ -64,7 +64,7 @@ static struct seg_tx {
|
|||
u8_t seg_n:5, /* Last segment index */
|
||||
new_key:1; /* New/old key */
|
||||
u8_t nack_count; /* Number of unacked segs */
|
||||
bt_mesh_cb_t cb;
|
||||
const struct bt_mesh_send_cb *cb;
|
||||
void *cb_data;
|
||||
struct k_delayed_work retransmit; /* Retransmit timer */
|
||||
} seg_tx[CONFIG_BT_MESH_TX_SEG_MSG_COUNT];
|
||||
|
@ -99,7 +99,8 @@ void bt_mesh_set_hb_sub_dst(u16_t addr)
|
|||
}
|
||||
|
||||
static int send_unseg(struct bt_mesh_net_tx *tx, u8_t aid,
|
||||
struct net_buf_simple *sdu)
|
||||
struct net_buf_simple *sdu,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
|
||||
|
@ -136,7 +137,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, u8_t aid,
|
|||
}
|
||||
}
|
||||
|
||||
return bt_mesh_net_send(tx, buf, NULL, NULL);
|
||||
return bt_mesh_net_send(tx, buf, cb, cb_data);
|
||||
}
|
||||
|
||||
bool bt_mesh_tx_in_progress(void)
|
||||
|
@ -191,8 +192,8 @@ static void seg_tx_reset(struct seg_tx *tx)
|
|||
|
||||
static inline void seg_tx_complete(struct seg_tx *tx, int err)
|
||||
{
|
||||
if (tx->cb) {
|
||||
tx->cb(err, tx->cb_data);
|
||||
if (tx->cb && tx->cb->end) {
|
||||
tx->cb->end(err, tx->cb_data);
|
||||
}
|
||||
|
||||
seg_tx_reset(tx);
|
||||
|
@ -205,8 +206,8 @@ static void seg_sent(int err, void *user_data)
|
|||
k_delayed_work_submit(&tx->retransmit, SEG_RETRANSMIT_TIMEOUT);
|
||||
}
|
||||
|
||||
static const struct bt_mesh_adv_cb seg_sent_cb = {
|
||||
.send_end = seg_sent,
|
||||
static const struct bt_mesh_send_cb seg_sent_cb = {
|
||||
.end = seg_sent,
|
||||
};
|
||||
|
||||
static void seg_tx_send_unacked(struct seg_tx *tx)
|
||||
|
@ -252,7 +253,7 @@ static void seg_retransmit(struct k_work *work)
|
|||
|
||||
static int send_seg(struct bt_mesh_net_tx *net_tx, u8_t aid,
|
||||
u8_t mic_len, struct net_buf_simple *sdu,
|
||||
bt_mesh_cb_t cb, void *cb_data)
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
u8_t seg_hdr, seg_o;
|
||||
u16_t seq_zero;
|
||||
|
@ -391,7 +392,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx)
|
|||
}
|
||||
|
||||
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||
bt_mesh_cb_t cb, void *cb_data)
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
bool seg = (msg->len > 11 || cb);
|
||||
const u8_t *key;
|
||||
|
@ -450,7 +451,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
|||
return send_seg(tx, aid, mic_len, msg, cb, cb_data);
|
||||
}
|
||||
|
||||
return send_unseg(tx, aid, msg);
|
||||
return send_unseg(tx, aid, msg, cb, cb_data);
|
||||
}
|
||||
|
||||
static bool is_replay(struct bt_mesh_net_rx *rx)
|
||||
|
@ -826,7 +827,7 @@ static inline s32_t ack_timeout(struct seg_rx *rx)
|
|||
|
||||
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
|
||||
size_t data_len, u64_t *seq_auth,
|
||||
const struct bt_mesh_adv_cb *cb, void *cb_data)
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
|
||||
|
|
|
@ -84,10 +84,10 @@ void bt_mesh_rx_reset(void);
|
|||
|
||||
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
|
||||
size_t data_len, u64_t *seq_auth,
|
||||
const struct bt_mesh_adv_cb *cb, void *cb_data);
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data);
|
||||
|
||||
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||
bt_mesh_cb_t cb, void *cb_data);
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data);
|
||||
|
||||
int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue