From patchwork Fri Jun 23 06:27:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 779809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wv7mt3sSsz9s7v for ; Fri, 23 Jun 2017 16:28:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="jjmvkkgN"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wv7mt1qLfzDqmt for ; Fri, 23 Jun 2017 16:28:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="jjmvkkgN"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wv7m74CWqzDqjN for ; Fri, 23 Jun 2017 16:27:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="jjmvkkgN"; dkim-atps=neutral Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id 2CF7D1441B2; Fri, 23 Jun 2017 14:27:31 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1498199251; bh=nkq4HizEfu/Mcrl2rrA5z2757vN8tvvvq7WxnNQnJZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjmvkkgN0iRxtvJfFTIunnZa6QN+kBIp9UTSkEntdZ/VPKtN5DPMA8/oprFLMQ/IH v8hSVrKBxID4fovR7bYB9DB6uSodYeWdtHTAGeGyZYlHBiRdfvm9dKtfyIvB0MtY4Z BQ0V/IWrmP29KiNuFfRsy0UHJ07fsL2TzELv886c= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 05/10] lib: Add plugin_option type and protocol Date: Fri, 23 Jun 2017 16:27:04 +1000 Message-Id: <20170623062709.16035-6-sam@mendozajonas.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170623062709.16035-1-sam@mendozajonas.com> References: <20170623062709.16035-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a new struct 'plugin_option' to represent pb-plugins that are installed on the system. This consists of plugin metadata and an array of installed executables. This also adds two new pb-protocol actions to advertise the addition of a new plugin_option, and to remove known plugin_options. Signed-off-by: Samuel Mendoza-Jonas --- lib/pb-protocol/pb-protocol.c | 104 ++++++++++++++++++++++++++++++++++++++++++ lib/pb-protocol/pb-protocol.h | 8 ++++ lib/types/types.h | 15 ++++++ 3 files changed, 127 insertions(+) diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 2385fc5..dbbda40 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -343,6 +343,26 @@ int pb_protocol_url_len(const char *url) return 4 + optional_strlen(url); } + +int pb_protocol_plugin_option_len(const struct plugin_option *opt) +{ + unsigned int i, len = 0; + + len += 4 + optional_strlen(opt->id); + len += 4 + optional_strlen(opt->name); + len += 4 + optional_strlen(opt->vendor); + len += 4 + optional_strlen(opt->vendor_id); + len += 4 + optional_strlen(opt->version); + len += 4 + optional_strlen(opt->date); + len += 4 + optional_strlen(opt->plugin_file); + + len += 4; /* n_executables */ + for (i = 0; i < opt->n_executables; i++) + len += 4 + optional_strlen(opt->executables[i]); + + return len; +} + int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len) { @@ -617,6 +637,32 @@ int pb_protocol_serialise_url(const char *url, char *buf, int buf_len) return 0; } +int pb_protocol_serialise_plugin_option(const struct plugin_option *opt, + char *buf, int buf_len) +{ + char *pos = buf; + unsigned int i; + + pos += pb_protocol_serialise_string(pos, opt->id); + pos += pb_protocol_serialise_string(pos, opt->name); + pos += pb_protocol_serialise_string(pos, opt->vendor); + pos += pb_protocol_serialise_string(pos, opt->vendor_id); + pos += pb_protocol_serialise_string(pos, opt->version); + pos += pb_protocol_serialise_string(pos, opt->date); + pos += pb_protocol_serialise_string(pos, opt->plugin_file); + + *(uint32_t *)pos = __cpu_to_be32(opt->n_executables); + pos += 4; + + for (i = 0; i < opt->n_executables; i++) + pos += pb_protocol_serialise_string(pos, opt->executables[i]); + + assert(pos <= buf + buf_len); + (void)buf_len; + + return 0; +} + int pb_protocol_write_message(int fd, struct pb_protocol_message *message) { int total_len, rc; @@ -1161,3 +1207,61 @@ int pb_protocol_deserialise_config(struct config *config, out: return rc; } + +int pb_protocol_deserialise_plugin_option(struct plugin_option *opt, + const struct pb_protocol_message *message) +{ + unsigned int len, i, tmp; + const char *pos; + int rc = -1; + char *str; + + len = message->payload_len; + pos = message->payload; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->id = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->name = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->vendor = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->vendor_id = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->version = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->date = str; + + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->plugin_file = str; + + if (read_u32(&pos, &len, &tmp)) + goto out; + opt->n_executables = tmp; + + opt->executables = talloc_zero_array(opt, char *, opt->n_executables); + if (!opt->executables) + goto out; + + for (i = 0; i < opt->n_executables; i++) { + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->executables[i] = talloc_strdup(opt, str); + } + + rc = 0; +out: + return rc; +} diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h index a8cd206..ce876d0 100644 --- a/lib/pb-protocol/pb-protocol.h +++ b/lib/pb-protocol/pb-protocol.h @@ -23,6 +23,8 @@ enum pb_protocol_action { PB_PROTOCOL_ACTION_CONFIG = 0x9, PB_PROTOCOL_ACTION_REINIT = 0xa, PB_PROTOCOL_ACTION_ADD_URL = 0xb, + PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD = 0xc, + PB_PROTOCOL_ACTION_PLUGINS_REMOVE = 0xd, }; struct pb_protocol_message { @@ -40,6 +42,7 @@ int pb_protocol_boot_status_len(const struct status *status); int pb_protocol_system_info_len(const struct system_info *sysinfo); int pb_protocol_config_len(const struct config *config); int pb_protocol_url_len(const char *url); +int pb_protocol_plugin_option_len(const struct plugin_option *opt); int pb_protocol_device_cmp(const struct device *a, const struct device *b); int pb_protocol_boot_option_cmp(const struct boot_option *a, @@ -62,6 +65,8 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo, int pb_protocol_serialise_config(const struct config *config, char *buf, int buf_len); int pb_protocol_serialise_url(const char *url, char *buf, int buf_len); +int pb_protocol_serialise_plugin_option(const struct plugin_option *opt, + char *buf, int buf_len); int pb_protocol_write_message(int fd, struct pb_protocol_message *message); @@ -87,4 +92,7 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo, int pb_protocol_deserialise_config(struct config *config, const struct pb_protocol_message *message); + +int pb_protocol_deserialise_plugin_option(struct plugin_option *opt, + const struct pb_protocol_message *message); #endif /* _PB_PROTOCOL_H */ diff --git a/lib/types/types.h b/lib/types/types.h index aa20bc0..9ab2a43 100644 --- a/lib/types/types.h +++ b/lib/types/types.h @@ -65,6 +65,21 @@ struct boot_option { } type; }; +struct plugin_option { + char *id; + char *name; + char *vendor; + char *vendor_id; + char *version; + char *date; + char *plugin_file; + + unsigned int n_executables; + char **executables; + + void *ui_info; +}; + struct boot_command { char *option_id; char *boot_image_file;