From 4a72fc87232a20e17dec7211529a200c30c9cdea Mon Sep 17 00:00:00 2001
From: Bjorn Andersson <bjorn.andersson@linaro.org>
Date: Tue, 28 Nov 2017 20:33:45 -0800
Subject: [PATCH] firehose: Read back max payload size

The max payload size is negotiated through the configure and configure
response messages. Update the max payload size based on the
configuration response value, if present.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 firehose.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/firehose.c b/firehose.c
index 623e99b..72e771e 100644
--- a/firehose.c
+++ b/firehose.c
@@ -229,6 +229,21 @@ static int firehose_nop(int fd)
 
 static size_t max_payload_size = 1048576;
 
+static int firehose_configure_response_parser(xmlNode *node)
+{
+	xmlChar *value;
+
+	value = xmlGetProp(node, (xmlChar*)"value");
+	if (xmlStrcmp(value, (xmlChar*)"ACK"))
+		return -EINVAL;
+
+	value = xmlGetProp(node, (xmlChar*)"MaxPayloadSizeToTargetInBytes");
+	if (value)
+		max_payload_size = strtoul((char*)value, NULL, 10);
+
+	return 0;
+}
+
 static int firehose_configure(int fd)
 {
 	xmlNode *root;
@@ -250,7 +265,7 @@ static int firehose_configure(int fd)
 	if (ret < 0)
 		return ret;
 
-	return firehose_read(fd, -1, firehose_nop_parser);
+	return firehose_read(fd, -1, firehose_configure_response_parser);
 }
 
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
-- 
GitLab