+int pb_protocol_serialise_boot_status(const struct boot_status *status,
+ char *buf, int buf_len)
+{
+ char *pos = buf;
+
+ *(uint32_t *)pos = __cpu_to_be32(status->type);
+ pos += sizeof(uint32_t);
+
+ pos += pb_protocol_serialise_string(pos, status->message);
+ pos += pb_protocol_serialise_string(pos, status->detail);
+
+ *(uint32_t *)pos = __cpu_to_be32(status->type);
+ pos += sizeof(uint32_t);
+
+ assert(pos <= buf + buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+
+int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
+ char *buf, int buf_len)
+{
+ char *pos = buf;
+ unsigned int i;
+
+ pos += pb_protocol_serialise_string(pos, sysinfo->type);
+ pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
+
+ *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
+ pos += sizeof(uint32_t);
+
+ for (i = 0; i < sysinfo->n_interfaces; i++) {
+ struct interface_info *if_info = sysinfo->interfaces[i];
+
+ *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
+ pos += sizeof(uint32_t);
+
+ memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
+ pos += if_info->hwaddr_size;
+
+ pos += pb_protocol_serialise_string(pos, if_info->name);
+
+ *(bool *)pos = if_info->link;
+ pos += sizeof(bool);
+ }
+
+ *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
+ pos += sizeof(uint32_t);
+
+ for (i = 0; i < sysinfo->n_blockdevs; i++) {
+ struct blockdev_info *bd_info = sysinfo->blockdevs[i];
+
+ pos += pb_protocol_serialise_string(pos, bd_info->name);
+ pos += pb_protocol_serialise_string(pos, bd_info->uuid);
+ pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
+ }
+
+ memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
+ pos += HWADDR_SIZE;
+
+ assert(pos <= buf + buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+
+static int pb_protocol_serialise_config_interface(char *buf,
+ struct interface_config *conf)
+{
+ char *pos = buf;
+
+ memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
+ pos += sizeof(conf->hwaddr);
+
+ *(uint32_t *)pos = conf->ignore;
+ pos += 4;
+
+ if (conf->ignore)
+ return pos - buf;
+
+ *(uint32_t *)pos = __cpu_to_be32(conf->method);
+ pos += 4;
+
+ if (conf->method == CONFIG_METHOD_STATIC) {
+ pos += pb_protocol_serialise_string(pos,
+ conf->static_config.address);
+ pos += pb_protocol_serialise_string(pos,
+ conf->static_config.gateway);
+ }
+
+ return pos - buf;
+}
+
+int pb_protocol_serialise_config(const struct config *config,
+ char *buf, int buf_len)
+{
+ char *pos = buf;
+ unsigned int i;
+
+ *(uint32_t *)pos = config->autoboot_enabled;
+ pos += 4;
+
+ *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
+ pos += 4;
+
+ *(uint32_t *)pos = config->safe_mode;
+ pos += 4;
+
+ *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
+ pos += 4;
+ for (i = 0; i < config->network.n_interfaces; i++) {
+ struct interface_config *iface =
+ config->network.interfaces[i];
+ pos += pb_protocol_serialise_config_interface(pos, iface);
+ }
+
+ *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
+ pos += 4;
+ for (i = 0; i < config->network.n_dns_servers; i++) {
+ pos += pb_protocol_serialise_string(pos,
+ config->network.dns_servers[i]);
+ }
+
+ *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
+ pos += 4;
+ for (i = 0; i < config->n_autoboot_opts; i++) {
+ *(uint32_t *)pos =
+ __cpu_to_be32(config->autoboot_opts[i].boot_type);
+ pos += 4;
+ if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
+ *(uint32_t *)pos =
+ __cpu_to_be32(config->autoboot_opts[i].type);
+ pos += 4;
+ } else {
+ pos += pb_protocol_serialise_string(pos,
+ config->autoboot_opts[i].uuid);
+ }
+ }
+
+ *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
+ pos += 4;
+ *(uint32_t *)pos = config->ipmi_bootdev_persistent;
+ pos += 4;
+
+ *(uint32_t *)pos = config->allow_writes;
+ pos += 4;
+
+ pos += pb_protocol_serialise_string(pos, config->lang);
+
+ assert(pos <= buf + buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+
+int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
+{
+ char *pos = buf;
+
+ pos += pb_protocol_serialise_string(pos, url);
+
+ assert(pos <=buf+buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+