mesh: Set LPN credentials on friend_req
Explicitly sets the LPN credentials when sending a friend request.
This is port of
@@ -284,13 +284,11 @@ static int send_friend_req(struct bt_mesh_lpn *lpn)
{
const struct bt_mesh_comp *comp = bt_mesh_comp_get();
struct bt_mesh_msg_ctx ctx = {
- .net_idx = lpn->sub->net_idx,
.app_idx = BT_MESH_KEY_UNUSED,
.addr = BT_MESH_ADDR_FRIENDS,
.send_ttl = 0,
};
struct bt_mesh_net_tx tx = {
- .sub = bt_mesh.lpn.sub,
.ctx = &ctx,
.src = bt_mesh_primary_addr(),
.xmit = POLL_XMIT,
@@ -306,6 +304,15 @@ static int send_friend_req(struct bt_mesh_lpn *lpn)
BT_DBG("");
+ lpn->sub = bt_mesh_subnet_next(NULL);
+ if (!lpn->sub) {
+ BT_ERR("No subnets, can't start LPN mode");
+ return -ENOENT;
+ }
+
+ ctx.net_idx = lpn->sub->net_idx;
+ tx.sub = lpn->sub;
+
return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_REQ, &req,
sizeof(req), &friend_req_sent_cb, NULL);
}
@@ -516,6 +523,7 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
msg->recv_win, msg->queue_size, msg->sub_list_size, msg->rssi,
frnd_counter);
+ lpn->frnd_counter = frnd_counter;
lpn->frnd = rx->ctx.addr;
/* Create friend credentials for each of the valid keys in the
