diff mbox series

[6/6] IPC: extend to set accepted versions

Message ID 20210311114031.71507-6-sbabic@denx.de
State Changes Requested
Headers show
Series [1/6] Introduce an upper check for version to be installed | expand

Commit Message

Stefano Babic March 11, 2021, 11:40 a.m. UTC
Add IPC to set minimum, maximum and if the current version should not be
reinstalled.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/network_thread.c    |  6 ++++++
 core/stream_interface.c  | 20 ++++++++++++++++++++
 include/installer_priv.h |  2 +-
 include/network_ipc.h    | 12 ++++++++++--
 include/util.h           |  5 +++++
 ipc/network_ipc-if.c     | 35 +++++++++++++++++++++++++++++++++++
 6 files changed, 77 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/core/network_thread.c b/core/network_thread.c
index c49dba5..168ae5d 100644
--- a/core/network_thread.c
+++ b/core/network_thread.c
@@ -513,6 +513,12 @@  void *network_thread (void *data)
 #endif
 					msg.type = NACK;
 				break;
+			case SET_VERSIONS_RANGE:
+				msg.type = ACK;
+				set_version_range(msg.data.versions.minimum_version,
+						  msg.data.versions.maximum_version,
+						  msg.data.versions.current_version);
+				break;
 			case SET_UPDATE_STATE:
 				value = *(update_state_t *)msg.data.msg;
 				msg.type = (is_valid_state(value) &&
diff --git a/core/stream_interface.c b/core/stream_interface.c
index a68f557..3b2c03b 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -689,3 +689,23 @@  int get_install_info(sourcetype *source, char *buf, size_t len)
 
 	return len;
 }
+
+void set_version_range(const char *minversion,
+		const char *maxversion, const char *current)
+{
+	if (minversion && strnlen(minversion, SWUPDATE_GENERAL_STRING_SIZE)) {
+		strlcpy(inst.software->minimum_version, minversion,
+			sizeof(inst.software->minimum_version));
+		inst.software->no_downgrading = true;
+	}
+	if (maxversion && strnlen(maxversion, SWUPDATE_GENERAL_STRING_SIZE)) {
+		strlcpy(inst.software->maximum_version, maxversion,
+			sizeof(inst.software->maximum_version));
+		inst.software->check_max_version = true;
+	}
+	if (current && strnlen(current, SWUPDATE_GENERAL_STRING_SIZE)) {
+		strlcpy(inst.software->current_version, current,
+			sizeof(inst.software->current_version));
+		inst.software->no_reinstalling = true;
+	}
+}
diff --git a/include/installer_priv.h b/include/installer_priv.h
index d406f27..fc02255 100644
--- a/include/installer_priv.h
+++ b/include/installer_priv.h
@@ -18,7 +18,7 @@  struct installer {
 	int	last_error;		/* error code if installation failed */
 	char	errormsg[64];		/* error message if installation failed */
 	struct swupdate_request req;
-	struct swupdate_cfg const *software;
+	struct swupdate_cfg *software;
 };
 
 #endif
diff --git a/include/network_ipc.h b/include/network_ipc.h
index 2939cdc..1a3d957 100644
--- a/include/network_ipc.h
+++ b/include/network_ipc.h
@@ -36,7 +36,8 @@  typedef enum {
 	SET_AES_KEY,
 	SET_UPDATE_STATE,	/* set bootloader ustate */
 	GET_UPDATE_STATE,
-	REQ_INSTALL_EXT
+	REQ_INSTALL_EXT,
+	SET_VERSIONS_RANGE
 } msgtype;
 
 /*
@@ -101,6 +102,11 @@  typedef union {
 		char key_ascii[65]; /* Key size in ASCII (256 bit, 32 bytes bin) + termination */
 		char ivt_ascii[33]; /* Key size in ASCII (16 bytes bin) + termination */
 	} aeskeymsg;
+	struct {
+		char minimum_version[256];
+		char maximum_version[256];
+		char current_version[256];
+	} versions;
 } msgdata;
 	
 typedef struct {
@@ -129,7 +135,9 @@  int swupdate_async_start(writedata wr_func, getstatus status_func,
 				terminated end_func,
 				void *priv, ssize_t size);
 int swupdate_set_aes(char *key, char *ivt);
-
+int swupdate_set_version_range(const char *minversion,
+				const char *maxversion,
+				const char *currentversion);
 #ifdef __cplusplus
 }   // extern "C"
 #endif
diff --git a/include/util.h b/include/util.h
index ad2e90c..2987203 100644
--- a/include/util.h
+++ b/include/util.h
@@ -230,6 +230,11 @@  int get_install_info(sourcetype *source, char *buf, size_t len);
 void get_install_swset(char *buf, size_t len);
 void get_install_running_mode(char *buf, size_t len);
 
+/* Setting global information */
+void set_version_range(const char *minversion,
+			const char *maxversion,
+			const char *current);
+
 unsigned long long ustrtoull(const char *cp, unsigned int base);
 
 const char* get_tmpdir(void);
diff --git a/ipc/network_ipc-if.c b/ipc/network_ipc-if.c
index f09c417..20a442e 100644
--- a/ipc/network_ipc-if.c
+++ b/ipc/network_ipc-if.c
@@ -172,6 +172,41 @@  int swupdate_set_aes(char *key, char *ivt)
 	return ipc_send_cmd(&msg);
 }
 
+/*
+ * Set via IPC the range of accepted versions
+ * Versions are string and they can use semver
+ */
+int swupdate_set_version_range(const char *minversion,
+				const char *maxversion,
+				const char *currentversion)
+{
+	ipc_message msg;
+
+	memset(&msg, 0, sizeof(msg));
+	msg.magic = IPC_MAGIC;
+	msg.type = SET_VERSIONS_RANGE;
+
+	if (minversion) {
+		strncpy(msg.data.versions.minimum_version,
+			minversion,
+			sizeof(msg.data.versions.minimum_version));
+	}
+
+	if (maxversion) {
+		strncpy(msg.data.versions.maximum_version,
+			maxversion,
+			sizeof(msg.data.versions.maximum_version));
+	}
+
+	if (currentversion) {
+		strncpy(msg.data.versions.current_version,
+			currentversion,
+			sizeof(msg.data.versions.maximum_version));
+	}
+
+	return ipc_send_cmd(&msg);
+}
+
 void swupdate_prepare_req(struct swupdate_request *req) {
 	if (!req)
 		return;