ble_mesh: Friend SeqAuth cleanup [Zephyr]

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.
This commit is contained in:
lly 2020-03-26 18:08:18 +08:00
parent de648753b0
commit 362e8e0a1f
5 changed files with 35 additions and 35 deletions

View file

@ -285,7 +285,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, BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_CLEAR);
@ -813,7 +813,7 @@ static void send_friend_clear(struct bt_mesh_friend *frnd)
}
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)
@ -1283,7 +1283,7 @@ int bt_mesh_friend_deinit(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 = {0};
bool found = false;
@ -1319,8 +1319,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 = NULL, *prev = NULL;
@ -1347,7 +1347,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 = {0};
@ -1397,7 +1397,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 = {0};
@ -1484,7 +1484,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 = 0U;
int i;
@ -1515,7 +1515,7 @@ static bool friend_queue_has_space(struct bt_mesh_friend *frnd, u16_t addr,
}
bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst,
u64_t *seq_auth, u8_t seg_count)
const u64_t *seq_auth, u8_t seg_count)
{
bool someone_has_space = false, friend_match = false;
int i;
@ -1550,7 +1550,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 = false;
u8_t avail_space = 0U;
@ -1587,7 +1587,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;
@ -1622,7 +1622,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;
@ -1658,7 +1658,7 @@ bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx,
}
void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src,
u16_t dst, u64_t *seq_auth)
u16_t dst, const u64_t *seq_auth)
{
int i;

View file

@ -27,19 +27,19 @@ struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr,
bool valid, bool established);
bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst,
u64_t *seq_auth, u8_t seg_count);
const u64_t *seq_auth, u8_t seg_count);
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,
u16_t dst, u64_t *seq_auth);
u16_t dst, const u64_t *seq_auth);
void bt_mesh_friend_sec_update(u16_t net_idx);

View file

@ -201,7 +201,7 @@ static int send_friend_clear(void)
BT_DBG("%s", __func__);
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)
@ -328,7 +328,7 @@ static int send_friend_req(struct bt_mesh_lpn *lpn)
BT_DBG("%s", __func__);
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)
@ -403,7 +403,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;
@ -718,7 +718,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;

View file

@ -1079,8 +1079,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 = NULL;
@ -1098,7 +1098,7 @@ static int ctl_send_unseg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
seq_auth, 1, &buf->b) &&
NULL, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
@ -1111,9 +1111,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)
{
struct seg_tx *tx_seg = NULL;
u16_t unsent = data_len;
@ -1197,18 +1197,18 @@ 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,
const struct bt_mesh_send_cb *cb, void *cb_data)
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,
tx->ctx->addr, tx->ctx->send_ttl, ctl_op);
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);
}
}
@ -1250,7 +1250,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)
@ -1898,7 +1898,7 @@ void bt_mesh_heartbeat_send(void)
BT_INFO("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,

View file

@ -100,8 +100,8 @@ void bt_mesh_rx_reset_single(u16_t src);
void bt_mesh_tx_reset_single(u16_t dst);
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);