From ca2f5c3f91fba3a6ea21ecd0d8dd2e416d0bfd78 Mon Sep 17 00:00:00 2001 From: Trond Einar Snekvik Date: Fri, 6 Mar 2020 13:07:22 +0100 Subject: [PATCH] Bluetooth: Mesh: Friend SeqAuth cleanup The Friend queue uses the message SeqAuth to determine whether the message is already in the queue. To facilitate this, the SeqAuth is passed around as a pointer throughout the transport modules. In the bt_mesh_ctl_send functions, this parameter is also exposed in the API, but the internal usage is inconsistent and buggy. Also, no one actually uses this parameter. - Removes seq_auth param from bt_mesh_ctl_send, instead passing NULL directly to the friend module, to enforce its addition to the queue. - Makes the seq_auth pointer const throughout the friend module. Signed-off-by: Trond Einar Snekvik --- subsys/bluetooth/mesh/friend.c | 22 +++++++++++----------- subsys/bluetooth/mesh/friend.h | 4 ++-- subsys/bluetooth/mesh/lpn.c | 8 ++++---- subsys/bluetooth/mesh/transport.c | 22 +++++++++++----------- subsys/bluetooth/mesh/transport.h | 4 ++-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 7355d038aee..76acf8e1bb6 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -258,7 +258,7 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) cfm.lpn_counter = msg->lpn_counter; bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_CLEAR_CFM, &cfm, - sizeof(cfm), NULL, NULL, NULL); + sizeof(cfm), NULL, NULL); friend_clear(frnd); @@ -761,7 +761,7 @@ static void send_friend_clear(struct bt_mesh_friend *frnd) BT_DBG(""); bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_CLEAR, &req, - sizeof(req), NULL, &clear_sent_cb, frnd); + sizeof(req), &clear_sent_cb, frnd); } static void clear_timeout(struct k_work *work) @@ -1229,7 +1229,7 @@ int bt_mesh_friend_init(void) return 0; } -static bool is_segack(struct net_buf *buf, u64_t *seqauth, u16_t src) +static bool is_segack(struct net_buf *buf, const u64_t *seqauth, u16_t src) { struct net_buf_simple_state state; bool found = false; @@ -1265,8 +1265,8 @@ end: return found; } -static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth, - u16_t src) +static void friend_purge_old_ack(struct bt_mesh_friend *frnd, + const u64_t *seq_auth, u16_t src) { sys_snode_t *cur, *prev = NULL; @@ -1293,7 +1293,7 @@ static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth, static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd, struct bt_mesh_net_rx *rx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf) { struct friend_pdu_info info; @@ -1343,7 +1343,7 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd, static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd, struct bt_mesh_net_tx *tx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf) { struct friend_pdu_info info; @@ -1430,7 +1430,7 @@ bool bt_mesh_friend_match(u16_t net_idx, u16_t addr) } static bool friend_queue_has_space(struct bt_mesh_friend *frnd, u16_t addr, - u64_t *seq_auth, u8_t seg_count) + const u64_t *seq_auth, u8_t seg_count) { u32_t total = 0; int i; @@ -1496,7 +1496,7 @@ bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst, } static bool friend_queue_prepare_space(struct bt_mesh_friend *frnd, u16_t addr, - u64_t *seq_auth, u8_t seg_count) + const u64_t *seq_auth, u8_t seg_count) { bool pending_segments; u8_t avail_space; @@ -1533,7 +1533,7 @@ static bool friend_queue_prepare_space(struct bt_mesh_friend *frnd, u16_t addr, void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf) { int i; @@ -1568,7 +1568,7 @@ void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx, bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf) { bool matched = false; diff --git a/subsys/bluetooth/mesh/friend.h b/subsys/bluetooth/mesh/friend.h index 7832dfa1035..4439ef27bb6 100644 --- a/subsys/bluetooth/mesh/friend.h +++ b/subsys/bluetooth/mesh/friend.h @@ -22,11 +22,11 @@ bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst, void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf); bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx, enum bt_mesh_friend_pdu_type type, - u64_t *seq_auth, u8_t seg_count, + const u64_t *seq_auth, u8_t seg_count, struct net_buf_simple *sbuf); void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src, diff --git a/subsys/bluetooth/mesh/lpn.c b/subsys/bluetooth/mesh/lpn.c index 6a901e412b8..d50a79bb75d 100644 --- a/subsys/bluetooth/mesh/lpn.c +++ b/subsys/bluetooth/mesh/lpn.c @@ -194,7 +194,7 @@ static int send_friend_clear(void) BT_DBG(""); return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_CLEAR, &req, - sizeof(req), NULL, &clear_sent_cb, NULL); + sizeof(req), &clear_sent_cb, NULL); } static void clear_friendship(bool force, bool disable) @@ -312,7 +312,7 @@ static int send_friend_req(struct bt_mesh_lpn *lpn) BT_DBG(""); return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_REQ, &req, - sizeof(req), NULL, &friend_req_sent_cb, NULL); + sizeof(req), &friend_req_sent_cb, NULL); } static void req_sent(u16_t duration, int err, void *user_data) @@ -382,7 +382,7 @@ static int send_friend_poll(void) } err = bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_POLL, &fsn, 1, - NULL, &req_sent_cb, NULL); + &req_sent_cb, NULL); if (err == 0) { lpn->pending_poll = 0U; lpn->sent_req = TRANS_CTL_OP_FRIEND_POLL; @@ -693,7 +693,7 @@ static bool sub_update(u8_t op) req.xact = lpn->xact_next++; - if (bt_mesh_ctl_send(&tx, op, &req, 1 + g * 2, NULL, + if (bt_mesh_ctl_send(&tx, op, &req, 1 + g * 2, &req_sent_cb, NULL) < 0) { group_zero(lpn->pending); return false; diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 2d692fa17ab..97db5277c05 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -1017,8 +1017,8 @@ static inline s32_t ack_timeout(struct seg_rx *rx) } static int ctl_send_unseg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, - size_t data_len, u64_t *seq_auth, - const struct bt_mesh_send_cb *cb, void *cb_data) + size_t data_len, const struct bt_mesh_send_cb *cb, + void *cb_data) { struct net_buf *buf; @@ -1035,7 +1035,7 @@ static int ctl_send_unseg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, net_buf_add_mem(buf, data, data_len); if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, - seq_auth, 1, &buf->b) && + NULL, 1, &buf->b) && BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. @@ -1048,9 +1048,9 @@ static int ctl_send_unseg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, return bt_mesh_net_send(tx, buf, cb, cb_data); } -static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, - void *data, size_t data_len, u64_t *seq_auth, - const struct bt_mesh_send_cb *cb, void *cb_data) +static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, + size_t data_len, const struct bt_mesh_send_cb *cb, + void *cb_data) { u8_t seg_o = 0; u16_t seq_zero; @@ -1129,7 +1129,7 @@ static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, } 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, + size_t data_len, const struct bt_mesh_send_cb *cb, void *cb_data) { BT_DBG("src 0x%04x dst 0x%04x ttl 0x%02x ctl 0x%02x", tx->src, @@ -1137,10 +1137,10 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, BT_DBG("len %zu: %s", data_len, bt_hex(data, data_len)); if (data_len <= 11) { - return ctl_send_unseg(tx, ctl_op, data, data_len, seq_auth, + return ctl_send_unseg(tx, ctl_op, data, data_len, cb, cb_data); } else { - return ctl_send_seg(tx, ctl_op, data, data_len, seq_auth, + return ctl_send_seg(tx, ctl_op, data, data_len, cb, cb_data); } } @@ -1182,7 +1182,7 @@ static int send_ack(struct bt_mesh_subnet *sub, u16_t src, u16_t dst, sys_put_be32(block, &buf[2]); return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_ACK, buf, sizeof(buf), - NULL, NULL, NULL); + NULL, NULL); } static void seg_rx_reset(struct seg_rx *rx, bool full_reset) @@ -1745,7 +1745,7 @@ 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); + NULL, NULL); } int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx, diff --git a/subsys/bluetooth/mesh/transport.h b/subsys/bluetooth/mesh/transport.h index f21cc8f39be..4a433d00fe9 100644 --- a/subsys/bluetooth/mesh/transport.h +++ b/subsys/bluetooth/mesh/transport.h @@ -84,8 +84,8 @@ void bt_mesh_rx_reset(void); void bt_mesh_tx_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_send_cb *cb, void *cb_data); + size_t data_len, 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, const struct bt_mesh_send_cb *cb, void *cb_data);