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);
259 for (i = 0; i < sysinfo->n_blockdevs; i++) {
260 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
261 len += 4 + optional_strlen(bd_info->name) +
262 4 + optional_strlen(bd_info->uuid) +
263 4 + optional_strlen(bd_info->mountpoint);
272 static int pb_protocol_interface_config_len(struct interface_config *conf)
276 len = sizeof(conf->hwaddr) +
277 4 /* conf->ignore */;
282 len += 4 /* conf->method */;
284 if (conf->method == CONFIG_METHOD_STATIC) {
285 len += 4 + optional_strlen(conf->static_config.address);
286 len += 4 + optional_strlen(conf->static_config.gateway);
287 len += 4 + optional_strlen(conf->static_config.url);
290 len += 4 /* conf->override */;
295 int pb_protocol_config_len(const struct config *config)
299 len = 4 /* config->autoboot_enabled */ +
300 4 /* config->autoboot_timeout_sec */ +
301 4 /* config->safe_mode */;
304 for (i = 0; i < config->network.n_interfaces; i++)
305 len += pb_protocol_interface_config_len(
306 config->network.interfaces[i]);
309 for (i = 0; i < config->network.n_dns_servers; i++)
310 len += 4 + optional_strlen(config->network.dns_servers[i]);
312 len += 4 + optional_strlen(config->http_proxy);
313 len += 4 + optional_strlen(config->https_proxy);
316 for (i = 0; i < config->n_autoboot_opts; i++) {
317 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
321 optional_strlen(config->autoboot_opts[i].uuid);
324 len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
326 len += 4; /* allow_writes */
328 len += 4; /* n_consoles */
329 for (i = 0; i < config->n_consoles; i++)
330 len += 4 + optional_strlen(config->consoles[i]);
332 len += 4 + optional_strlen(config->boot_console);
333 len += 4; /* manual_console */
335 len += 4 + optional_strlen(config->lang);
340 int pb_protocol_url_len(const char *url)
342 /* url + length field */
343 return 4 + optional_strlen(url);
347 int pb_protocol_plugin_option_len(const struct plugin_option *opt)
349 unsigned int i, len = 0;
351 len += 4 + optional_strlen(opt->id);
352 len += 4 + optional_strlen(opt->name);
353 len += 4 + optional_strlen(opt->vendor);
354 len += 4 + optional_strlen(opt->vendor_id);
355 len += 4 + optional_strlen(opt->version);
356 len += 4 + optional_strlen(opt->date);
357 len += 4 + optional_strlen(opt->plugin_file);
359 len += 4; /* n_executables */
360 for (i = 0; i < opt->n_executables; i++)
361 len += 4 + optional_strlen(opt->executables[i]);
366 int pb_protocol_serialise_device(const struct device *dev,
367 char *buf, int buf_len)
371 pos += pb_protocol_serialise_string(pos, dev->id);
372 *(enum device_type *)pos = dev->type;
373 pos += sizeof(enum device_type);
374 pos += pb_protocol_serialise_string(pos, dev->name);
375 pos += pb_protocol_serialise_string(pos, dev->description);
376 pos += pb_protocol_serialise_string(pos, dev->icon_file);
378 assert(pos <= buf + buf_len);
384 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
385 char *buf, int buf_len)
389 pos += pb_protocol_serialise_string(pos, opt->device_id);
390 pos += pb_protocol_serialise_string(pos, opt->id);
391 pos += pb_protocol_serialise_string(pos, opt->name);
392 pos += pb_protocol_serialise_string(pos, opt->description);
393 pos += pb_protocol_serialise_string(pos, opt->icon_file);
394 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
395 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
396 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
397 pos += pb_protocol_serialise_string(pos, opt->boot_args);
398 pos += pb_protocol_serialise_string(pos, opt->args_sig_file);
400 *(bool *)pos = opt->is_default;
403 *(uint32_t *)pos = __cpu_to_be32(opt->type);
406 assert(pos <= buf + buf_len);
412 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
413 char *buf, int buf_len)
417 pos += pb_protocol_serialise_string(pos, boot->option_id);
418 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
419 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
420 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
421 pos += pb_protocol_serialise_string(pos, boot->boot_args);
422 pos += pb_protocol_serialise_string(pos, boot->args_sig_file);
423 pos += pb_protocol_serialise_string(pos, boot->console);
425 assert(pos <= buf + buf_len);
431 int pb_protocol_serialise_boot_status(const struct status *status,
432 char *buf, int buf_len)
436 *(uint32_t *)pos = __cpu_to_be32(status->type);
437 pos += sizeof(uint32_t);
439 pos += pb_protocol_serialise_string(pos, status->message);
441 *(bool *)pos = __cpu_to_be32(status->backlog);
444 assert(pos <= buf + buf_len);
450 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
451 char *buf, int buf_len)
456 pos += pb_protocol_serialise_string(pos, sysinfo->type);
457 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
459 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
460 pos += sizeof(uint32_t);
461 for (i = 0; i < sysinfo->n_primary; i++)
462 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
464 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
465 pos += sizeof(uint32_t);
466 for (i = 0; i < sysinfo->n_other; i++)
467 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
469 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
470 pos += sizeof(uint32_t);
471 for (i = 0; i < sysinfo->n_bmc_current; i++)
472 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
474 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
475 pos += sizeof(uint32_t);
476 for (i = 0; i < sysinfo->n_bmc_golden; i++)
477 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
479 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
480 pos += sizeof(uint32_t);
482 for (i = 0; i < sysinfo->n_interfaces; i++) {
483 struct interface_info *if_info = sysinfo->interfaces[i];
485 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
486 pos += sizeof(uint32_t);
488 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
489 pos += if_info->hwaddr_size;
491 pos += pb_protocol_serialise_string(pos, if_info->name);
493 *(bool *)pos = if_info->link;
496 pos += pb_protocol_serialise_string(pos, if_info->address);
499 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
500 pos += sizeof(uint32_t);
502 for (i = 0; i < sysinfo->n_blockdevs; i++) {
503 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
505 pos += pb_protocol_serialise_string(pos, bd_info->name);
506 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
507 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
510 if (sysinfo->bmc_mac)
511 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
513 memset(pos, 0, HWADDR_SIZE);
516 assert(pos <= buf + buf_len);
522 static int pb_protocol_serialise_config_interface(char *buf,
523 struct interface_config *conf)
527 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
528 pos += sizeof(conf->hwaddr);
530 *(uint32_t *)pos = conf->ignore;
536 *(uint32_t *)pos = __cpu_to_be32(conf->method);
539 if (conf->method == CONFIG_METHOD_STATIC) {
540 pos += pb_protocol_serialise_string(pos,
541 conf->static_config.address);
542 pos += pb_protocol_serialise_string(pos,
543 conf->static_config.gateway);
544 pos += pb_protocol_serialise_string(pos,
545 conf->static_config.url);
548 *(uint32_t *)pos = conf->override;
554 int pb_protocol_serialise_config(const struct config *config,
555 char *buf, int buf_len)
560 *(uint32_t *)pos = config->autoboot_enabled;
563 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
566 *(uint32_t *)pos = config->safe_mode;
569 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
571 for (i = 0; i < config->network.n_interfaces; i++) {
572 struct interface_config *iface =
573 config->network.interfaces[i];
574 pos += pb_protocol_serialise_config_interface(pos, iface);
577 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
579 for (i = 0; i < config->network.n_dns_servers; i++) {
580 pos += pb_protocol_serialise_string(pos,
581 config->network.dns_servers[i]);
584 pos += pb_protocol_serialise_string(pos, config->http_proxy);
585 pos += pb_protocol_serialise_string(pos, config->https_proxy);
587 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
589 for (i = 0; i < config->n_autoboot_opts; i++) {
591 __cpu_to_be32(config->autoboot_opts[i].boot_type);
593 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
595 __cpu_to_be32(config->autoboot_opts[i].type);
598 pos += pb_protocol_serialise_string(pos,
599 config->autoboot_opts[i].uuid);
603 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
605 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
608 *(uint32_t *)pos = config->allow_writes;
611 *(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
613 for (i = 0; i < config->n_consoles; i++)
614 pos += pb_protocol_serialise_string(pos, config->consoles[i]);
616 pos += pb_protocol_serialise_string(pos, config->boot_console);
617 *(uint32_t *)pos = config->manual_console;
620 pos += pb_protocol_serialise_string(pos, config->lang);
622 assert(pos <= buf + buf_len);
628 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
632 pos += pb_protocol_serialise_string(pos, url);
634 assert(pos <=buf+buf_len);
640 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
641 char *buf, int buf_len)
646 pos += pb_protocol_serialise_string(pos, opt->id);
647 pos += pb_protocol_serialise_string(pos, opt->name);
648 pos += pb_protocol_serialise_string(pos, opt->vendor);
649 pos += pb_protocol_serialise_string(pos, opt->vendor_id);
650 pos += pb_protocol_serialise_string(pos, opt->version);
651 pos += pb_protocol_serialise_string(pos, opt->date);
652 pos += pb_protocol_serialise_string(pos, opt->plugin_file);
654 *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
657 for (i = 0; i < opt->n_executables; i++)
658 pos += pb_protocol_serialise_string(pos, opt->executables[i]);
660 assert(pos <= buf + buf_len);
666 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
671 total_len = sizeof(*message) + message->payload_len;
673 message->payload_len = __cpu_to_be32(message->payload_len);
674 message->action = __cpu_to_be32(message->action);
676 for (pos = (void *)message; total_len;) {
677 rc = write(fd, pos, total_len);
686 talloc_free(message);
691 pb_log("%s: failed: %s\n", __func__, strerror(errno));
695 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
696 enum pb_protocol_action action, int payload_len)
698 struct pb_protocol_message *message;
700 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
701 pb_log("%s: payload too big %u/%u\n", __func__, payload_len,
702 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
706 message = talloc_size(ctx, sizeof(*message) + payload_len);
708 /* we convert these to big-endian in write_message() */
709 message->action = action;
710 message->payload_len = payload_len;
716 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
718 struct pb_protocol_message *message, m;
722 /* use the stack for the initial 8-byte read */
724 rc = read(fd, &m, sizeof(m));
728 m.payload_len = __be32_to_cpu(m.payload_len);
729 m.action = __be32_to_cpu(m.action);
731 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
732 pb_log("%s: payload too big %u/%u\n", __func__, m.payload_len,
733 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
737 message = talloc_size(ctx, sizeof(m) + m.payload_len);
738 memcpy(message, &m, sizeof(m));
740 for (len = 0; len < m.payload_len;) {
741 rc = read(fd, message->payload + len, m.payload_len - len);
744 talloc_free(message);
745 pb_log("%s: failed (%u): %s\n", __func__, len,
757 int pb_protocol_deserialise_device(struct device *dev,
758 const struct pb_protocol_message *message)
764 len = message->payload_len;
765 pos = message->payload;
767 if (read_string(dev, &pos, &len, &dev->id))
770 if (len < sizeof(enum device_type))
772 dev->type = *(enum device_type *)(pos);
773 pos += sizeof(enum device_type);
774 len -= sizeof(enum device_type);
776 if (read_string(dev, &pos, &len, &dev->name))
779 if (read_string(dev, &pos, &len, &dev->description))
782 if (read_string(dev, &pos, &len, &dev->icon_file))
791 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
792 const struct pb_protocol_message *message)
798 len = message->payload_len;
799 pos = message->payload;
801 if (read_string(opt, &pos, &len, &opt->device_id))
804 if (read_string(opt, &pos, &len, &opt->id))
807 if (read_string(opt, &pos, &len, &opt->name))
810 if (read_string(opt, &pos, &len, &opt->description))
813 if (read_string(opt, &pos, &len, &opt->icon_file))
816 if (read_string(opt, &pos, &len, &opt->boot_image_file))
819 if (read_string(opt, &pos, &len, &opt->initrd_file))
822 if (read_string(opt, &pos, &len, &opt->dtb_file))
825 if (read_string(opt, &pos, &len, &opt->boot_args))
828 if (read_string(opt, &pos, &len, &opt->args_sig_file))
831 if (len < sizeof(bool))
833 opt->is_default = *(bool *)(pos);
837 if (read_u32(&pos, &len, &opt->type))
846 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
847 const struct pb_protocol_message *message)
853 len = message->payload_len;
854 pos = message->payload;
856 if (read_string(cmd, &pos, &len, &cmd->option_id))
859 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
862 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
865 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
868 if (read_string(cmd, &pos, &len, &cmd->boot_args))
871 if (read_string(cmd, &pos, &len, &cmd->args_sig_file))
874 if (read_string(cmd, &pos, &len, &cmd->console))
883 int pb_protocol_deserialise_boot_status(struct status *status,
884 const struct pb_protocol_message *message)
890 len = message->payload_len;
891 pos = message->payload;
893 /* first up, the type enum... */
894 if (len < sizeof(uint32_t))
897 status->type = __be32_to_cpu(*(uint32_t *)(pos));
899 switch (status->type) {
907 pos += sizeof(uint32_t);
908 len -= sizeof(uint32_t);
911 if (read_string(status, &pos, &len, &status->message))
915 status->backlog = *(bool *)pos;
916 pos += sizeof(status->backlog);
924 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
925 const struct pb_protocol_message *message)
932 len = message->payload_len;
933 pos = message->payload;
935 /* type and identifier strings */
936 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
939 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
942 /* Platform version strings for openpower platforms */
943 if (read_u32(&pos, &len, &sysinfo->n_primary))
945 sysinfo->platform_primary = talloc_array(sysinfo, char *,
947 for (i = 0; i < sysinfo->n_primary; i++) {
948 if (read_string(sysinfo, &pos, &len, &tmp))
950 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
953 if (read_u32(&pos, &len, &sysinfo->n_other))
955 sysinfo->platform_other = talloc_array(sysinfo, char *,
957 for (i = 0; i < sysinfo->n_other; i++) {
958 if (read_string(sysinfo, &pos, &len, &tmp))
960 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
963 /* BMC version strings for openpower platforms */
964 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
966 sysinfo->bmc_current = talloc_array(sysinfo, char *,
967 sysinfo->n_bmc_current);
968 for (i = 0; i < sysinfo->n_bmc_current; i++) {
969 if (read_string(sysinfo, &pos, &len, &tmp))
971 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
974 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
976 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
977 sysinfo->n_bmc_golden);
978 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
979 if (read_string(sysinfo, &pos, &len, &tmp))
981 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
984 /* number of interfaces */
985 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
988 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
989 sysinfo->n_interfaces);
991 for (i = 0; i < sysinfo->n_interfaces; i++) {
992 struct interface_info *if_info = talloc(sysinfo,
993 struct interface_info);
995 if (read_u32(&pos, &len, &if_info->hwaddr_size))
998 if (len < if_info->hwaddr_size)
1001 if_info->hwaddr = talloc_memdup(if_info, pos,
1002 if_info->hwaddr_size);
1003 pos += if_info->hwaddr_size;
1004 len -= if_info->hwaddr_size;
1006 if (read_string(if_info, &pos, &len, &if_info->name))
1009 if_info->link = *(bool *)pos;
1010 pos += sizeof(if_info->link);
1012 if (read_string(if_info, &pos, &len, &if_info->address))
1015 sysinfo->interfaces[i] = if_info;
1018 /* number of interfaces */
1019 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
1022 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
1023 sysinfo->n_blockdevs);
1025 for (i = 0; i < sysinfo->n_blockdevs; i++) {
1026 struct blockdev_info *bd_info = talloc(sysinfo,
1027 struct blockdev_info);
1029 if (read_string(bd_info, &pos, &len, &bd_info->name))
1032 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
1035 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
1038 sysinfo->blockdevs[i] = bd_info;
1041 for (i = 0; i < HWADDR_SIZE; i++) {
1043 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
1056 static int pb_protocol_deserialise_config_interface(const char **buf,
1057 unsigned int *len, struct interface_config *iface)
1061 if (*len < sizeof(iface->hwaddr))
1064 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
1065 *buf += sizeof(iface->hwaddr);
1066 *len -= sizeof(iface->hwaddr);
1068 if (read_u32(buf, len, &tmp))
1070 iface->ignore = !!tmp;
1075 if (read_u32(buf, len, &iface->method))
1078 if (iface->method == CONFIG_METHOD_STATIC) {
1079 if (read_string(iface, buf, len, &iface->static_config.address))
1082 if (read_string(iface, buf, len, &iface->static_config.gateway))
1085 if (read_string(iface, buf, len, &iface->static_config.url))
1089 if (read_u32(buf, len, &tmp))
1091 iface->override = !!tmp;
1096 int pb_protocol_deserialise_config(struct config *config,
1097 const struct pb_protocol_message *message)
1099 unsigned int len, i, tmp;
1104 len = message->payload_len;
1105 pos = message->payload;
1107 if (read_u32(&pos, &len, &tmp))
1109 config->autoboot_enabled = !!tmp;
1111 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1114 if (read_u32(&pos, &len, &tmp))
1116 config->safe_mode = !!tmp;
1118 if (read_u32(&pos, &len, &config->network.n_interfaces))
1121 config->network.interfaces = talloc_array(config,
1122 struct interface_config *, config->network.n_interfaces);
1124 for (i = 0; i < config->network.n_interfaces; i++) {
1125 struct interface_config *iface = talloc_zero(
1126 config->network.interfaces,
1127 struct interface_config);
1128 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1130 config->network.interfaces[i] = iface;
1133 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1135 config->network.dns_servers = talloc_array(config, const char *,
1136 config->network.n_dns_servers);
1138 for (i = 0; i < config->network.n_dns_servers; i++) {
1139 if (read_string(config->network.dns_servers, &pos, &len, &str))
1141 config->network.dns_servers[i] = str;
1144 if (read_string(config, &pos, &len, &str))
1146 config->http_proxy = str;
1147 if (read_string(config, &pos, &len, &str))
1149 config->https_proxy = str;
1151 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1153 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1154 config->n_autoboot_opts);
1156 for (i = 0; i < config->n_autoboot_opts; i++) {
1157 if (read_u32(&pos, &len, &tmp))
1159 config->autoboot_opts[i].boot_type = (int)tmp;
1160 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1161 if (read_u32(&pos, &len, &tmp))
1163 config->autoboot_opts[i].type = tmp;
1165 if (read_string(config, &pos, &len, &str))
1167 config->autoboot_opts[i].uuid = str;
1171 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1173 if (read_u32(&pos, &len, &tmp))
1175 config->ipmi_bootdev_persistent = !!tmp;
1177 if (read_u32(&pos, &len, &tmp))
1179 config->allow_writes = !!tmp;
1181 if (read_u32(&pos, &len, &config->n_consoles))
1184 config->consoles = talloc_array(config, char *, config->n_consoles);
1185 for (i = 0; i < config->n_consoles; i++) {
1186 if (read_string(config->consoles, &pos, &len, &str))
1188 config->consoles[i] = str;
1191 if (read_string(config, &pos, &len, &str))
1194 config->boot_console = str;
1196 if (read_u32(&pos, &len, &tmp))
1198 config->manual_console = !!tmp;
1200 if (read_string(config, &pos, &len, &str))
1211 int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
1212 const struct pb_protocol_message *message)
1214 unsigned int len, i, tmp;
1219 len = message->payload_len;
1220 pos = message->payload;
1222 if (read_string(opt, &pos, &len, &str))
1226 if (read_string(opt, &pos, &len, &str))
1230 if (read_string(opt, &pos, &len, &str))
1234 if (read_string(opt, &pos, &len, &str))
1236 opt->vendor_id = str;
1238 if (read_string(opt, &pos, &len, &str))
1242 if (read_string(opt, &pos, &len, &str))
1246 if (read_string(opt, &pos, &len, &str))
1248 opt->plugin_file = str;
1250 if (read_u32(&pos, &len, &tmp))
1252 opt->n_executables = tmp;
1254 opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
1255 if (!opt->executables)
1258 for (i = 0; i < opt->n_executables; i++) {
1259 if (read_string(opt, &pos, &len, &str))
1261 opt->executables[i] = talloc_strdup(opt, str);