Commit 9b2a6d48 authored by Johan Hedberg's avatar Johan Hedberg Committed by Johan Hedberg
Browse files

Bluetooth: Mesh: Fix friendship credential usage for segmented messages



The friend_cred hint needs to be set already at the point of
segmenting, i.e. doing it in bt_mesh_net_send() is too late. Move the
setting to bt_mesh_trans_send() and bt_mesh_ctl_send().

Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent ada5771d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,16 @@ static inline bool bt_mesh_lpn_established(void)
#endif
}

static inline bool bt_mesh_lpn_match(u16_t addr)
{
#if defined(CONFIG_BT_MESH_LOW_POWER)
	if (bt_mesh_lpn_established()) {
		return (addr == bt_mesh.lpn.frnd);
	}
#endif
	return false;
}

static inline bool bt_mesh_lpn_waiting_update(void)
{
#if defined(CONFIG_BT_MESH_LOW_POWER)
+2 −11
Original line number Diff line number Diff line
@@ -675,7 +675,8 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
	const u8_t *enc, *priv;
	int err;

	BT_DBG("net_idx 0x%04x, len %u", sub->net_idx, buf->len);
	BT_DBG("net_idx 0x%04x new_key %u friend_cred %u len %u",
	       sub->net_idx, new_key, friend_cred, buf->len);

	if (friend_cred) {
		err = bt_mesh_friend_cred_get(sub->net_idx,
@@ -826,16 +827,6 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
	BT_DBG("Payload len %u: %s", buf->len, bt_hex(buf->data, buf->len));
	BT_DBG("Seq 0x%06x", bt_mesh.seq);

#if defined(CONFIG_BT_MESH_LOW_POWER)
	/* Communication between LPN & Friend should always be using
	 * the Friendship Credentials. Any other destination should
	 * use the Master Credentials.
	 */
	if (bt_mesh_lpn_established()) {
		tx->ctx->friend_cred = (tx->ctx->addr == bt_mesh.lpn.frnd);
	}
#endif

	if (tx->ctx->send_ttl == BT_MESH_TTL_DEFAULT) {
		tx->ctx->send_ttl = bt_mesh_default_ttl_get();
	}
+16 −0
Original line number Diff line number Diff line
@@ -444,6 +444,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
		return err;
	}

	/* Communication between LPN & Friend should always be using
	 * the Friendship Credentials. Any other destination should
	 * use the Master Credentials.
	 */
	if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
		tx->ctx->friend_cred = bt_mesh_lpn_match(tx->ctx->addr);
	}

	if (seg) {
		return send_seg(tx, aid, mic_len, msg, cb, cb_data);
	}
@@ -856,6 +864,14 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
		}
	}

	/* Communication between LPN & Friend should always be using
	 * the Friendship Credentials. Any other destination should
	 * use the Master Credentials.
	 */
	if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
		tx->ctx->friend_cred = bt_mesh_lpn_match(tx->ctx->addr);
	}

	return bt_mesh_net_send(tx, buf, cb);
}