7 #include <asm/byteorder.h>
9 #include <talloc/talloc.h>
10 #include <list/list.h>
13 #include "pb-protocol.h"
18 * 4-byte action, determines the remaining message content
19 * 4-byte total payload len
20 * - not including action and payload len header
22 * action = 0x1: device add message
27 * 4-byte len, description
28 * 4-byte len, icon_file
34 * 4-byte len, description
35 * 4-byte len, icon_file
36 * 4-byte len, boot_image_file
37 * 4-byte len, initrd_file
38 * 4-byte len, dtb_file
39 * 4-byte len, boot_args
40 * 4-byte len, args_sig_file
42 * action = 0x2: device remove message
48 * 4-byte len, boot option id
49 * 4-byte len, boot_image_file
50 * 4-byte len, initrd_file
51 * 4-byte len, dtb_file
52 * 4-byte len, boot_args
53 * 4-byte len, args_sig_file
57 void pb_protocol_dump_device(const struct device *dev, const char *text,
60 struct boot_option *opt;
62 fprintf(stream, "%snew dev:\n", text);
63 fprintf(stream, "%s\tid: %s\n", text, dev->id);
64 fprintf(stream, "%s\tname: %s\n", text, dev->name);
65 fprintf(stream, "%s\tdesc: %s\n", text, dev->description);
66 fprintf(stream, "%s\ticon: %s\n", text, dev->icon_file);
67 fprintf(stream, "%s\tboot options:\n", text);
68 list_for_each_entry(&dev->boot_options, opt, list) {
69 fprintf(stream, "%s\t\tid: %s\n", text, opt->id);
70 fprintf(stream, "%s\t\tname: %s\n", text, opt->name);
71 fprintf(stream, "%s\t\tdesc: %s\n", text, opt->description);
72 fprintf(stream, "%s\t\ticon: %s\n", text, opt->icon_file);
73 fprintf(stream, "%s\t\tboot: %s\n", text, opt->boot_image_file);
74 fprintf(stream, "%s\t\tinit: %s\n", text, opt->initrd_file);
75 fprintf(stream, "%s\t\tdtb: %s\n", text, opt->dtb_file);
76 fprintf(stream, "%s\t\targs: %s\n", text, opt->boot_args);
77 fprintf(stream, "%s\t\tasig: %s\n", text, opt->args_sig_file);
78 fprintf(stream, "%s\t\ttype: %s\n", text,
79 opt->type == DISCOVER_BOOT_OPTION ? "boot" : "plugin");
83 int pb_protocol_device_cmp(const struct device *a, const struct device *b)
85 return !strcmp(a->id, b->id);
88 int pb_protocol_boot_option_cmp(const struct boot_option *a,
89 const struct boot_option *b)
91 return !strcmp(a->id, b->id);
94 /* Write a string into the buffer, starting at pos.
96 * Returns the total length used for the write, including length header.
98 int pb_protocol_serialise_string(char *pos, const char *str)
105 *(uint32_t *)pos = __cpu_to_be32(len);
106 pos += sizeof(uint32_t);
108 memcpy(pos, str, len);
110 return len + sizeof(uint32_t);
113 /* Read a string from a buffer, allocating the new string as necessary.
115 * @param[in] ctx The talloc context to base the allocation on
116 * @param[in,out] pos Where to start reading
117 * @param[in,out] len The amount of data remaining in the buffer
118 * @param[out] str Pointer to resuling string
119 * @return zero on success, non-zero on failure
121 static int read_string(void *ctx, const char **pos, unsigned int *len,
124 uint32_t str_len, read_len;
126 if (*len < sizeof(uint32_t))
129 str_len = __be32_to_cpu(*(uint32_t *)(*pos));
130 read_len = sizeof(uint32_t);
132 if (read_len + str_len > *len)
138 *str = talloc_strndup(ctx, *pos + read_len, str_len);
142 /* all ok, update the caller's pointers */
149 static int read_u32(const char **pos, unsigned int *len, unsigned int *p)
151 if (*len < sizeof(uint32_t))
154 *p = (unsigned int)__be32_to_cpu(*(uint32_t *)(*pos));
155 *pos += sizeof(uint32_t);
156 *len -= sizeof(uint32_t);
161 char *pb_protocol_deserialise_string(void *ctx,
162 const struct pb_protocol_message *message)
168 len = message->payload_len;
169 buf = message->payload;
171 if (read_string(ctx, &buf, &len, &str))
177 static int optional_strlen(const char *str)
184 int pb_protocol_device_len(const struct device *dev)
186 return 4 + optional_strlen(dev->id) +
188 4 + optional_strlen(dev->name) +
189 4 + optional_strlen(dev->description) +
190 4 + optional_strlen(dev->icon_file);
193 int pb_protocol_boot_option_len(const struct boot_option *opt)
196 return 4 + optional_strlen(opt->device_id) +
197 4 + optional_strlen(opt->id) +
198 4 + optional_strlen(opt->name) +
199 4 + optional_strlen(opt->description) +
200 4 + optional_strlen(opt->icon_file) +
201 4 + optional_strlen(opt->boot_image_file) +
202 4 + optional_strlen(opt->initrd_file) +
203 4 + optional_strlen(opt->dtb_file) +
204 4 + optional_strlen(opt->boot_args) +
205 4 + optional_strlen(opt->args_sig_file) +
206 sizeof(opt->is_default) +
210 int pb_protocol_boot_len(const struct boot_command *boot)
212 return 4 + optional_strlen(boot->option_id) +
213 4 + optional_strlen(boot->boot_image_file) +
214 4 + optional_strlen(boot->initrd_file) +
215 4 + optional_strlen(boot->dtb_file) +
216 4 + optional_strlen(boot->boot_args) +
217 4 + optional_strlen(boot->args_sig_file) +
218 4 + optional_strlen(boot->console);
221 int pb_protocol_boot_status_len(const struct status *status)
223 return 4 + /* type */
224 4 + optional_strlen(status->message) +
229 int pb_protocol_system_info_len(const struct system_info *sysinfo)
233 len = 4 + optional_strlen(sysinfo->type) +
234 4 + optional_strlen(sysinfo->identifier) +
238 for (i = 0; i < sysinfo->n_primary; i++)
239 len += 4 + optional_strlen(sysinfo->platform_primary[i]);
241 for (i = 0; i < sysinfo->n_other; i++)
242 len += 4 + optional_strlen(sysinfo->platform_other[i]);
245 for (i = 0; i < sysinfo->n_bmc_current; i++)
246 len += 4 + optional_strlen(sysinfo->bmc_current[i]);
248 for (i = 0; i < sysinfo->n_bmc_golden; i++)
249 len += 4 + optional_strlen(sysinfo->bmc_golden[i]);
251 for (i = 0; i < sysinfo->n_interfaces; i++) {
252 struct interface_info *if_info = sysinfo->interfaces[i];
253 len += 4 + if_info->hwaddr_size +
254 4 + optional_strlen(if_info->name) +
255 sizeof(if_info->link) +
256 4 + optional_strlen(if_info->address) +
257 4 + optional_strlen(if_info->address_v6);
260 for (i = 0; i < sysinfo->n_blockdevs; i++) {
261 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
262 len += 4 + optional_strlen(bd_info->name) +
263 4 + optional_strlen(bd_info->uuid) +
264 4 + optional_strlen(bd_info->mountpoint);
273 static int pb_protocol_interface_config_len(struct interface_config *conf)
277 len = sizeof(conf->hwaddr) +
278 4 /* conf->ignore */;
283 len += 4 /* conf->method */;
285 if (conf->method == CONFIG_METHOD_STATIC) {
286 len += 4 + optional_strlen(conf->static_config.address);
287 len += 4 + optional_strlen(conf->static_config.gateway);
288 len += 4 + optional_strlen(conf->static_config.url);
291 len += 4 /* conf->override */;
296 int pb_protocol_config_len(const struct config *config)
300 len = 4 /* config->autoboot_enabled */ +
301 4 /* config->autoboot_timeout_sec */ +
302 4 /* config->safe_mode */;
305 for (i = 0; i < config->network.n_interfaces; i++)
306 len += pb_protocol_interface_config_len(
307 config->network.interfaces[i]);
310 for (i = 0; i < config->network.n_dns_servers; i++)
311 len += 4 + optional_strlen(config->network.dns_servers[i]);
313 len += 4 + optional_strlen(config->http_proxy);
314 len += 4 + optional_strlen(config->https_proxy);
317 for (i = 0; i < config->n_autoboot_opts; i++) {
318 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
322 optional_strlen(config->autoboot_opts[i].uuid);
325 len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
327 len += 4; /* allow_writes */
329 len += 4; /* n_consoles */
330 for (i = 0; i < config->n_consoles; i++)
331 len += 4 + optional_strlen(config->consoles[i]);
333 len += 4 + optional_strlen(config->boot_console);
334 len += 4; /* manual_console */
336 len += 4 + optional_strlen(config->lang);
341 int pb_protocol_url_len(const char *url)
343 /* url + length field */
344 return 4 + optional_strlen(url);
348 int pb_protocol_plugin_option_len(const struct plugin_option *opt)
350 unsigned int i, len = 0;
352 len += 4 + optional_strlen(opt->id);
353 len += 4 + optional_strlen(opt->name);
354 len += 4 + optional_strlen(opt->vendor);
355 len += 4 + optional_strlen(opt->vendor_id);
356 len += 4 + optional_strlen(opt->version);
357 len += 4 + optional_strlen(opt->date);
358 len += 4 + optional_strlen(opt->plugin_file);
360 len += 4; /* n_executables */
361 for (i = 0; i < opt->n_executables; i++)
362 len += 4 + optional_strlen(opt->executables[i]);
367 int pb_protocol_temp_autoboot_len(const struct autoboot_option *opt)
369 unsigned int len = 0;
374 if (opt->boot_type == BOOT_DEVICE_TYPE)
377 len += optional_strlen(opt->uuid);
382 int pb_protocol_serialise_device(const struct device *dev,
383 char *buf, int buf_len)
387 pos += pb_protocol_serialise_string(pos, dev->id);
388 *(enum device_type *)pos = dev->type;
389 pos += sizeof(enum device_type);
390 pos += pb_protocol_serialise_string(pos, dev->name);
391 pos += pb_protocol_serialise_string(pos, dev->description);
392 pos += pb_protocol_serialise_string(pos, dev->icon_file);
394 assert(pos <= buf + buf_len);
400 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
401 char *buf, int buf_len)
405 pos += pb_protocol_serialise_string(pos, opt->device_id);
406 pos += pb_protocol_serialise_string(pos, opt->id);
407 pos += pb_protocol_serialise_string(pos, opt->name);
408 pos += pb_protocol_serialise_string(pos, opt->description);
409 pos += pb_protocol_serialise_string(pos, opt->icon_file);
410 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
411 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
412 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
413 pos += pb_protocol_serialise_string(pos, opt->boot_args);
414 pos += pb_protocol_serialise_string(pos, opt->args_sig_file);
416 *(bool *)pos = opt->is_default;
419 *(uint32_t *)pos = __cpu_to_be32(opt->type);
422 assert(pos <= buf + buf_len);
428 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
429 char *buf, int buf_len)
433 pos += pb_protocol_serialise_string(pos, boot->option_id);
434 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
435 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
436 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
437 pos += pb_protocol_serialise_string(pos, boot->boot_args);
438 pos += pb_protocol_serialise_string(pos, boot->args_sig_file);
439 pos += pb_protocol_serialise_string(pos, boot->console);
441 assert(pos <= buf + buf_len);
447 int pb_protocol_serialise_boot_status(const struct status *status,
448 char *buf, int buf_len)
452 *(uint32_t *)pos = __cpu_to_be32(status->type);
453 pos += sizeof(uint32_t);
455 pos += pb_protocol_serialise_string(pos, status->message);
457 *(bool *)pos = __cpu_to_be32(status->backlog);
460 assert(pos <= buf + buf_len);
466 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
467 char *buf, int buf_len)
472 pos += pb_protocol_serialise_string(pos, sysinfo->type);
473 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
475 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
476 pos += sizeof(uint32_t);
477 for (i = 0; i < sysinfo->n_primary; i++)
478 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
480 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
481 pos += sizeof(uint32_t);
482 for (i = 0; i < sysinfo->n_other; i++)
483 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
485 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
486 pos += sizeof(uint32_t);
487 for (i = 0; i < sysinfo->n_bmc_current; i++)
488 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
490 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
491 pos += sizeof(uint32_t);
492 for (i = 0; i < sysinfo->n_bmc_golden; i++)
493 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
495 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
496 pos += sizeof(uint32_t);
498 for (i = 0; i < sysinfo->n_interfaces; i++) {
499 struct interface_info *if_info = sysinfo->interfaces[i];
501 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
502 pos += sizeof(uint32_t);
504 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
505 pos += if_info->hwaddr_size;
507 pos += pb_protocol_serialise_string(pos, if_info->name);
509 *(bool *)pos = if_info->link;
512 pos += pb_protocol_serialise_string(pos, if_info->address);
513 pos += pb_protocol_serialise_string(pos, if_info->address_v6);
516 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
517 pos += sizeof(uint32_t);
519 for (i = 0; i < sysinfo->n_blockdevs; i++) {
520 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
522 pos += pb_protocol_serialise_string(pos, bd_info->name);
523 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
524 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
527 if (sysinfo->bmc_mac)
528 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
530 memset(pos, 0, HWADDR_SIZE);
533 assert(pos <= buf + buf_len);
539 static int pb_protocol_serialise_config_interface(char *buf,
540 struct interface_config *conf)
544 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
545 pos += sizeof(conf->hwaddr);
547 *(uint32_t *)pos = conf->ignore;
553 *(uint32_t *)pos = __cpu_to_be32(conf->method);
556 if (conf->method == CONFIG_METHOD_STATIC) {
557 pos += pb_protocol_serialise_string(pos,
558 conf->static_config.address);
559 pos += pb_protocol_serialise_string(pos,
560 conf->static_config.gateway);
561 pos += pb_protocol_serialise_string(pos,
562 conf->static_config.url);
565 *(uint32_t *)pos = conf->override;
571 int pb_protocol_serialise_config(const struct config *config,
572 char *buf, int buf_len)
577 *(uint32_t *)pos = config->autoboot_enabled;
580 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
583 *(uint32_t *)pos = config->safe_mode;
586 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
588 for (i = 0; i < config->network.n_interfaces; i++) {
589 struct interface_config *iface =
590 config->network.interfaces[i];
591 pos += pb_protocol_serialise_config_interface(pos, iface);
594 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
596 for (i = 0; i < config->network.n_dns_servers; i++) {
597 pos += pb_protocol_serialise_string(pos,
598 config->network.dns_servers[i]);
601 pos += pb_protocol_serialise_string(pos, config->http_proxy);
602 pos += pb_protocol_serialise_string(pos, config->https_proxy);
604 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
606 for (i = 0; i < config->n_autoboot_opts; i++) {
608 __cpu_to_be32(config->autoboot_opts[i].boot_type);
610 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
612 __cpu_to_be32(config->autoboot_opts[i].type);
615 pos += pb_protocol_serialise_string(pos,
616 config->autoboot_opts[i].uuid);
620 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
622 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
625 *(uint32_t *)pos = config->allow_writes;
628 *(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
630 for (i = 0; i < config->n_consoles; i++)
631 pos += pb_protocol_serialise_string(pos, config->consoles[i]);
633 pos += pb_protocol_serialise_string(pos, config->boot_console);
634 *(uint32_t *)pos = config->manual_console;
637 pos += pb_protocol_serialise_string(pos, config->lang);
639 assert(pos <= buf + buf_len);
645 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
649 pos += pb_protocol_serialise_string(pos, url);
651 assert(pos <=buf+buf_len);
657 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
658 char *buf, int buf_len)
663 pos += pb_protocol_serialise_string(pos, opt->id);
664 pos += pb_protocol_serialise_string(pos, opt->name);
665 pos += pb_protocol_serialise_string(pos, opt->vendor);
666 pos += pb_protocol_serialise_string(pos, opt->vendor_id);
667 pos += pb_protocol_serialise_string(pos, opt->version);
668 pos += pb_protocol_serialise_string(pos, opt->date);
669 pos += pb_protocol_serialise_string(pos, opt->plugin_file);
671 *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
674 for (i = 0; i < opt->n_executables; i++)
675 pos += pb_protocol_serialise_string(pos, opt->executables[i]);
677 assert(pos <= buf + buf_len);
683 int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt,
684 char *buf, int buf_len)
688 *(uint32_t *)pos = __cpu_to_be32(opt->boot_type);
691 if (opt->boot_type == BOOT_DEVICE_TYPE) {
692 *(uint32_t *)pos = __cpu_to_be32(opt->type);
695 pos += pb_protocol_serialise_string(pos, opt->uuid);
703 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
708 total_len = sizeof(*message) + message->payload_len;
710 message->payload_len = __cpu_to_be32(message->payload_len);
711 message->action = __cpu_to_be32(message->action);
713 for (pos = (void *)message; total_len;) {
714 rc = write(fd, pos, total_len);
723 talloc_free(message);
728 pb_log_fn("failed: %s\n", strerror(errno));
732 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
733 enum pb_protocol_action action, int payload_len)
735 struct pb_protocol_message *message;
737 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
738 pb_log_fn("payload too big %u/%u\n", payload_len,
739 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
743 message = talloc_size(ctx, sizeof(*message) + payload_len);
745 /* we convert these to big-endian in write_message() */
746 message->action = action;
747 message->payload_len = payload_len;
753 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
755 struct pb_protocol_message *message, m;
759 /* use the stack for the initial 8-byte read */
761 rc = read(fd, &m, sizeof(m));
765 m.payload_len = __be32_to_cpu(m.payload_len);
766 m.action = __be32_to_cpu(m.action);
768 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
769 pb_log_fn("payload too big %u/%u\n", m.payload_len,
770 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
774 message = talloc_size(ctx, sizeof(m) + m.payload_len);
775 memcpy(message, &m, sizeof(m));
777 for (len = 0; len < m.payload_len;) {
778 rc = read(fd, message->payload + len, m.payload_len - len);
781 talloc_free(message);
782 pb_log_fn("failed (%u): %s\n", len,
794 int pb_protocol_deserialise_device(struct device *dev,
795 const struct pb_protocol_message *message)
801 len = message->payload_len;
802 pos = message->payload;
804 if (read_string(dev, &pos, &len, &dev->id))
807 if (len < sizeof(enum device_type))
809 dev->type = *(enum device_type *)(pos);
810 pos += sizeof(enum device_type);
811 len -= sizeof(enum device_type);
813 if (read_string(dev, &pos, &len, &dev->name))
816 if (read_string(dev, &pos, &len, &dev->description))
819 if (read_string(dev, &pos, &len, &dev->icon_file))
828 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
829 const struct pb_protocol_message *message)
835 len = message->payload_len;
836 pos = message->payload;
838 if (read_string(opt, &pos, &len, &opt->device_id))
841 if (read_string(opt, &pos, &len, &opt->id))
844 if (read_string(opt, &pos, &len, &opt->name))
847 if (read_string(opt, &pos, &len, &opt->description))
850 if (read_string(opt, &pos, &len, &opt->icon_file))
853 if (read_string(opt, &pos, &len, &opt->boot_image_file))
856 if (read_string(opt, &pos, &len, &opt->initrd_file))
859 if (read_string(opt, &pos, &len, &opt->dtb_file))
862 if (read_string(opt, &pos, &len, &opt->boot_args))
865 if (read_string(opt, &pos, &len, &opt->args_sig_file))
868 if (len < sizeof(bool))
870 opt->is_default = *(bool *)(pos);
874 if (read_u32(&pos, &len, &opt->type))
883 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
884 const struct pb_protocol_message *message)
890 len = message->payload_len;
891 pos = message->payload;
893 if (read_string(cmd, &pos, &len, &cmd->option_id))
896 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
899 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
902 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
905 if (read_string(cmd, &pos, &len, &cmd->boot_args))
908 if (read_string(cmd, &pos, &len, &cmd->args_sig_file))
911 if (read_string(cmd, &pos, &len, &cmd->console))
920 int pb_protocol_deserialise_boot_status(struct status *status,
921 const struct pb_protocol_message *message)
927 len = message->payload_len;
928 pos = message->payload;
930 /* first up, the type enum... */
931 if (len < sizeof(uint32_t))
934 status->type = __be32_to_cpu(*(uint32_t *)(pos));
936 switch (status->type) {
944 pos += sizeof(uint32_t);
945 len -= sizeof(uint32_t);
948 if (read_string(status, &pos, &len, &status->message))
952 status->backlog = *(bool *)pos;
953 pos += sizeof(status->backlog);
961 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
962 const struct pb_protocol_message *message)
969 len = message->payload_len;
970 pos = message->payload;
972 /* type and identifier strings */
973 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
976 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
979 /* Platform version strings for openpower platforms */
980 if (read_u32(&pos, &len, &sysinfo->n_primary))
982 sysinfo->platform_primary = talloc_array(sysinfo, char *,
984 for (i = 0; i < sysinfo->n_primary; i++) {
985 if (read_string(sysinfo, &pos, &len, &tmp))
987 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
990 if (read_u32(&pos, &len, &sysinfo->n_other))
992 sysinfo->platform_other = talloc_array(sysinfo, char *,
994 for (i = 0; i < sysinfo->n_other; i++) {
995 if (read_string(sysinfo, &pos, &len, &tmp))
997 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
1000 /* BMC version strings for openpower platforms */
1001 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
1003 sysinfo->bmc_current = talloc_array(sysinfo, char *,
1004 sysinfo->n_bmc_current);
1005 for (i = 0; i < sysinfo->n_bmc_current; i++) {
1006 if (read_string(sysinfo, &pos, &len, &tmp))
1008 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
1011 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
1013 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
1014 sysinfo->n_bmc_golden);
1015 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
1016 if (read_string(sysinfo, &pos, &len, &tmp))
1018 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
1021 /* number of interfaces */
1022 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
1025 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
1026 sysinfo->n_interfaces);
1028 for (i = 0; i < sysinfo->n_interfaces; i++) {
1029 struct interface_info *if_info = talloc(sysinfo,
1030 struct interface_info);
1032 if (read_u32(&pos, &len, &if_info->hwaddr_size))
1035 if (len < if_info->hwaddr_size)
1038 if_info->hwaddr = talloc_memdup(if_info, pos,
1039 if_info->hwaddr_size);
1040 pos += if_info->hwaddr_size;
1041 len -= if_info->hwaddr_size;
1043 if (read_string(if_info, &pos, &len, &if_info->name))
1046 if_info->link = *(bool *)pos;
1047 pos += sizeof(if_info->link);
1049 if (read_string(if_info, &pos, &len, &if_info->address))
1051 if (read_string(if_info, &pos, &len, &if_info->address_v6))
1054 sysinfo->interfaces[i] = if_info;
1057 /* number of interfaces */
1058 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
1061 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
1062 sysinfo->n_blockdevs);
1064 for (i = 0; i < sysinfo->n_blockdevs; i++) {
1065 struct blockdev_info *bd_info = talloc(sysinfo,
1066 struct blockdev_info);
1068 if (read_string(bd_info, &pos, &len, &bd_info->name))
1071 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
1074 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
1077 sysinfo->blockdevs[i] = bd_info;
1080 for (i = 0; i < HWADDR_SIZE; i++) {
1082 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
1095 static int pb_protocol_deserialise_config_interface(const char **buf,
1096 unsigned int *len, struct interface_config *iface)
1100 if (*len < sizeof(iface->hwaddr))
1103 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
1104 *buf += sizeof(iface->hwaddr);
1105 *len -= sizeof(iface->hwaddr);
1107 if (read_u32(buf, len, &tmp))
1109 iface->ignore = !!tmp;
1114 if (read_u32(buf, len, &iface->method))
1117 if (iface->method == CONFIG_METHOD_STATIC) {
1118 if (read_string(iface, buf, len, &iface->static_config.address))
1121 if (read_string(iface, buf, len, &iface->static_config.gateway))
1124 if (read_string(iface, buf, len, &iface->static_config.url))
1128 if (read_u32(buf, len, &tmp))
1130 iface->override = !!tmp;
1135 int pb_protocol_deserialise_config(struct config *config,
1136 const struct pb_protocol_message *message)
1138 unsigned int len, i, tmp;
1143 len = message->payload_len;
1144 pos = message->payload;
1146 if (read_u32(&pos, &len, &tmp))
1148 config->autoboot_enabled = !!tmp;
1150 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1153 if (read_u32(&pos, &len, &tmp))
1155 config->safe_mode = !!tmp;
1157 if (read_u32(&pos, &len, &config->network.n_interfaces))
1160 config->network.interfaces = talloc_array(config,
1161 struct interface_config *, config->network.n_interfaces);
1163 for (i = 0; i < config->network.n_interfaces; i++) {
1164 struct interface_config *iface = talloc_zero(
1165 config->network.interfaces,
1166 struct interface_config);
1167 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1169 config->network.interfaces[i] = iface;
1172 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1174 config->network.dns_servers = talloc_array(config, const char *,
1175 config->network.n_dns_servers);
1177 for (i = 0; i < config->network.n_dns_servers; i++) {
1178 if (read_string(config->network.dns_servers, &pos, &len, &str))
1180 config->network.dns_servers[i] = str;
1183 if (read_string(config, &pos, &len, &str))
1185 config->http_proxy = str;
1186 if (read_string(config, &pos, &len, &str))
1188 config->https_proxy = str;
1190 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1192 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1193 config->n_autoboot_opts);
1195 for (i = 0; i < config->n_autoboot_opts; i++) {
1196 if (read_u32(&pos, &len, &tmp))
1198 config->autoboot_opts[i].boot_type = (int)tmp;
1199 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1200 if (read_u32(&pos, &len, &tmp))
1202 config->autoboot_opts[i].type = tmp;
1204 if (read_string(config, &pos, &len, &str))
1206 config->autoboot_opts[i].uuid = str;
1210 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1212 if (read_u32(&pos, &len, &tmp))
1214 config->ipmi_bootdev_persistent = !!tmp;
1216 if (read_u32(&pos, &len, &tmp))
1218 config->allow_writes = !!tmp;
1220 if (read_u32(&pos, &len, &config->n_consoles))
1223 config->consoles = talloc_array(config, char *, config->n_consoles);
1224 for (i = 0; i < config->n_consoles; i++) {
1225 if (read_string(config->consoles, &pos, &len, &str))
1227 config->consoles[i] = str;
1230 if (read_string(config, &pos, &len, &str))
1233 config->boot_console = str;
1235 if (read_u32(&pos, &len, &tmp))
1237 config->manual_console = !!tmp;
1239 if (read_string(config, &pos, &len, &str))
1250 int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
1251 const struct pb_protocol_message *message)
1253 unsigned int len, i, tmp;
1258 len = message->payload_len;
1259 pos = message->payload;
1261 if (read_string(opt, &pos, &len, &str))
1265 if (read_string(opt, &pos, &len, &str))
1269 if (read_string(opt, &pos, &len, &str))
1273 if (read_string(opt, &pos, &len, &str))
1275 opt->vendor_id = str;
1277 if (read_string(opt, &pos, &len, &str))
1281 if (read_string(opt, &pos, &len, &str))
1285 if (read_string(opt, &pos, &len, &str))
1287 opt->plugin_file = str;
1289 if (read_u32(&pos, &len, &tmp))
1291 opt->n_executables = tmp;
1293 opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
1294 if (!opt->executables)
1297 for (i = 0; i < opt->n_executables; i++) {
1298 if (read_string(opt, &pos, &len, &str))
1300 opt->executables[i] = talloc_strdup(opt, str);
1308 int pb_protocol_deserialise_temp_autoboot(struct autoboot_option *opt,
1309 const struct pb_protocol_message *message)
1311 unsigned int len, tmp;
1316 len = message->payload_len;
1317 pos = message->payload;
1319 if (read_u32(&pos, &len, &tmp))
1322 opt->boot_type = tmp;
1323 if (opt->boot_type == BOOT_DEVICE_TYPE) {
1324 if (read_u32(&pos, &len, &tmp))
1328 } else if (opt->boot_type == BOOT_DEVICE_UUID) {
1329 if (read_string(opt, &pos, &len, &str))