Skip to content

Commit 3c6876e

Browse files
committed
Bluetooth: Mesh: Blob Server considers friendship
Fix Max Chunk reporting during Block_Information_Get: If friendship is established, then max possible chunk size for transfer is reported according to friend's queue size. ChunkSize = (FndQ sz * Bytes per seg (12)) - Opcode(1) - Chunk_Num (2)- 8 byte MIC (max) = (FndQ sz * 12) - 11 This allows all segments of Chunk_Transfer messages to fit in a friend queue. If this is not done, friend queue keeps overflowing systematically causing unstable PULL_MODE transfers. Fix Chunk requests: Adapt number of requested chunks according to current friend queue size. If friend queue is too small, at least 1 chunk is requested. Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
1 parent 366d45f commit 3c6876e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

subsys/bluetooth/mesh/blob_srv.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ static int pull_req_max(const struct bt_mesh_blob_srv *srv)
151151
BLOB_CHUNK_SDU_LEN(srv->state.xfer.chunk_size),
152152
BT_MESH_APP_SEG_SDU_MAX);
153153

154-
count = MIN(CONFIG_BT_MESH_BLOB_SRV_PULL_REQ_COUNT,
155-
bt_mesh.lpn.queue_size / segments_per_chunk);
154+
/* It is possible that the friend node cannot hold all segments per chunk. In this
155+
* case, we should request at least 1 chunk. As requesting `0` would be invalid.
156+
*/
157+
count = MAX(1, MIN(CONFIG_BT_MESH_BLOB_SRV_PULL_REQ_COUNT,
158+
bt_mesh.lpn.queue_size / segments_per_chunk));
159+
156160
}
157161
#endif
158162

@@ -821,7 +825,27 @@ static int handle_info_get(const struct bt_mesh_model *mod, struct bt_mesh_msg_c
821825
net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MIN);
822826
net_buf_simple_add_u8(&rsp, BLOB_BLOCK_SIZE_LOG_MAX);
823827
net_buf_simple_add_le16(&rsp, CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX);
828+
829+
#if defined(CONFIG_BT_MESH_LOW_POWER)
830+
/* If friendship is established, then chunk size is according to friend's queue size.
831+
* Chunk size = (Queue size * Segment size) - (Opcode (1) - Chunk Number (2)
832+
* - 8 byte MIC (max))
833+
*/
834+
if (bt_mesh.lpn.established && bt_mesh.lpn.queue_size > 0) {
835+
uint16_t chunk_size = (bt_mesh.lpn.queue_size * 12) - 11;
836+
837+
chunk_size = MIN(chunk_size, BLOB_RX_CHUNK_SIZE);
838+
net_buf_simple_add_le16(&rsp, chunk_size);
839+
if (bt_mesh.lpn.queue_size <= 2) {
840+
LOG_WRN("FndQ too small %u", bt_mesh.lpn.queue_size);
841+
}
842+
} else {
843+
net_buf_simple_add_le16(&rsp, BLOB_RX_CHUNK_SIZE);
844+
}
845+
#else
824846
net_buf_simple_add_le16(&rsp, BLOB_RX_CHUNK_SIZE);
847+
#endif
848+
825849
net_buf_simple_add_le32(&rsp, CONFIG_BT_MESH_BLOB_SIZE_MAX);
826850
net_buf_simple_add_le16(&rsp, MTU_SIZE_MAX);
827851
net_buf_simple_add_u8(&rsp, BT_MESH_BLOB_XFER_MODE_ALL);

0 commit comments

Comments
 (0)