From 431e4fe9fa3977b2da030d0d54a7d58d1f1e642d Mon Sep 17 00:00:00 2001
From: Mattias Nilsson <mattias.nilsson@rt-labs.com>
Date: Thu, 20 Apr 2023 13:12:40 +0200
Subject: [PATCH 1/2] Correct the accounting of outgoing RPC fragment sizes

For outgoing fragmented RPC messages, the header size was accounted for
an extra time for each fragment except the first one. This change
corrects that.
---
 src/device/pf_cmrpc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/device/pf_cmrpc.c b/src/device/pf_cmrpc.c
index d5400f42..937d249c 100644
--- a/src/device/pf_cmrpc.c
+++ b/src/device/pf_cmrpc.c
@@ -4740,6 +4740,13 @@ static int pf_cmrpc_dce_packet (
 
             /* Update how much the controller has received (ack'ed) */
             p_sess->out_buf_sent_pos += p_sess->out_buf_send_len;
+            if (p_sess->out_fragment_nbr > 0)
+            {
+               /* For all but the first fragment, we have accounted for
+                * the header size an additional time. Correct that here.
+                */
+               p_sess->out_buf_sent_pos -= PF_CMRPC_PDU_HEADER_SIZE;
+            }
             p_sess->out_fragment_nbr++;
 
             /* The fragment acknowledgment is valid (expected) */

From 4ec58f32fd38c0ec65ee2b97e84840f46788c0c1 Mon Sep 17 00:00:00 2001
From: Mattias Nilsson <mattias.nilsson@rt-labs.com>
Date: Fri, 28 Apr 2023 12:01:01 +0200
Subject: [PATCH 2/2] Clarify error message about RPC buffer size.

Change an error message to be slightly more helpful.
---
 src/device/pf_cmrpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/device/pf_cmrpc.c b/src/device/pf_cmrpc.c
index 937d249c..92acdaf0 100644
--- a/src/device/pf_cmrpc.c
+++ b/src/device/pf_cmrpc.c
@@ -4422,7 +4422,8 @@ static int pf_cmrpc_dce_packet (
          {
             LOG_ERROR (
                PF_RPC_LOG,
-               "CMRPC(%d): Incoming fragments exceed max buffer\n",
+               "CMRPC(%d): Incoming RPC message exceeds buffer size."
+               " If possible, increase PNET_MAX_SESSION_BUFFER_SIZE.\n",
                __LINE__);
             pf_set_error (
                &p_sess->rpc_result,