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
41 * action = 0x2: device remove message
47 * 4-byte len, boot option id
48 * 4-byte len, boot_image_file
49 * 4-byte len, initrd_file
50 * 4-byte len, dtb_file
51 * 4-byte len, boot_args
55 void pb_protocol_dump_device(const struct device *dev, const char *text,
58 struct boot_option *opt;
60 fprintf(stream, "%snew dev:\n", text);
61 fprintf(stream, "%s\tid: %s\n", text, dev->id);
62 fprintf(stream, "%s\tname: %s\n", text, dev->name);
63 fprintf(stream, "%s\tdesc: %s\n", text, dev->description);
64 fprintf(stream, "%s\ticon: %s\n", text, dev->icon_file);
65 fprintf(stream, "%s\tboot options:\n", text);
66 list_for_each_entry(&dev->boot_options, opt, list) {
67 fprintf(stream, "%s\t\tid: %s\n", text, opt->id);
68 fprintf(stream, "%s\t\tname: %s\n", text, opt->name);
69 fprintf(stream, "%s\t\tdesc: %s\n", text, opt->description);
70 fprintf(stream, "%s\t\ticon: %s\n", text, opt->icon_file);
71 fprintf(stream, "%s\t\tboot: %s\n", text, opt->boot_image_file);
72 fprintf(stream, "%s\t\tinit: %s\n", text, opt->initrd_file);
73 fprintf(stream, "%s\t\tdtb: %s\n", text, opt->dtb_file);
74 fprintf(stream, "%s\t\targs: %s\n", text, opt->boot_args);
78 int pb_protocol_device_cmp(const struct device *a, const struct device *b)
80 return !strcmp(a->id, b->id);
83 int pb_protocol_boot_option_cmp(const struct boot_option *a,
84 const struct boot_option *b)
86 return !strcmp(a->id, b->id);
89 /* Write a string into the buffer, starting at pos.
91 * Returns the total length used for the write, including length header.
93 int pb_protocol_serialise_string(char *pos, const char *str)
100 *(uint32_t *)pos = __cpu_to_be32(len);
101 pos += sizeof(uint32_t);
103 memcpy(pos, str, len);
105 return len + sizeof(uint32_t);
108 /* Read a string from a buffer, allocating the new string as necessary.
110 * @param[in] ctx The talloc context to base the allocation on
111 * @param[in,out] pos Where to start reading
112 * @param[in,out] len The amount of data remaining in the buffer
113 * @param[out] str Pointer to resuling string
114 * @return zero on success, non-zero on failure
116 static int read_string(void *ctx, const char **pos, unsigned int *len,
119 uint32_t str_len, read_len;
121 if (*len < sizeof(uint32_t))
124 str_len = __be32_to_cpu(*(uint32_t *)(*pos));
125 read_len = sizeof(uint32_t);
127 if (read_len + str_len > *len)
133 *str = talloc_strndup(ctx, *pos + read_len, str_len);
137 /* all ok, update the caller's pointers */
144 static int read_u32(const char **pos, unsigned int *len, unsigned int *p)
146 if (*len < sizeof(uint32_t))
149 *p = (unsigned int)__be32_to_cpu(*(uint32_t *)(*pos));
150 *pos += sizeof(uint32_t);
151 *len -= sizeof(uint32_t);
156 char *pb_protocol_deserialise_string(void *ctx,
157 const struct pb_protocol_message *message)
163 len = message->payload_len;
164 buf = message->payload;
166 if (read_string(ctx, &buf, &len, &str))
172 static int optional_strlen(const char *str)
179 int pb_protocol_device_len(const struct device *dev)
181 return 4 + optional_strlen(dev->id) +
183 4 + optional_strlen(dev->name) +
184 4 + optional_strlen(dev->description) +
185 4 + optional_strlen(dev->icon_file);
188 int pb_protocol_boot_option_len(const struct boot_option *opt)
191 return 4 + optional_strlen(opt->device_id) +
192 4 + optional_strlen(opt->id) +
193 4 + optional_strlen(opt->name) +
194 4 + optional_strlen(opt->description) +
195 4 + optional_strlen(opt->icon_file) +
196 4 + optional_strlen(opt->boot_image_file) +
197 4 + optional_strlen(opt->initrd_file) +
198 4 + optional_strlen(opt->dtb_file) +
199 4 + optional_strlen(opt->boot_args) +
200 sizeof(opt->is_default);
203 int pb_protocol_boot_len(const struct boot_command *boot)
205 return 4 + optional_strlen(boot->option_id) +
206 4 + optional_strlen(boot->boot_image_file) +
207 4 + optional_strlen(boot->initrd_file) +
208 4 + optional_strlen(boot->dtb_file) +
209 4 + optional_strlen(boot->boot_args) +
210 4 + optional_strlen(boot->tty);
213 int pb_protocol_boot_status_len(const struct boot_status *status)
216 4 + optional_strlen(status->message) +
217 4 + optional_strlen(status->detail) +
221 int pb_protocol_system_info_len(const struct system_info *sysinfo)
225 len = 4 + optional_strlen(sysinfo->type) +
226 4 + optional_strlen(sysinfo->identifier) +
230 for (i = 0; i < sysinfo->n_primary; i++)
231 len += 4 + optional_strlen(sysinfo->platform_primary[i]);
233 for (i = 0; i < sysinfo->n_other; i++)
234 len += 4 + optional_strlen(sysinfo->platform_other[i]);
237 for (i = 0; i < sysinfo->n_bmc_current; i++)
238 len += 4 + optional_strlen(sysinfo->bmc_current[i]);
240 for (i = 0; i < sysinfo->n_bmc_golden; i++)
241 len += 4 + optional_strlen(sysinfo->bmc_golden[i]);
243 for (i = 0; i < sysinfo->n_interfaces; i++) {
244 struct interface_info *if_info = sysinfo->interfaces[i];
245 len += 4 + if_info->hwaddr_size +
246 4 + optional_strlen(if_info->name) +
247 sizeof(if_info->link);
250 for (i = 0; i < sysinfo->n_blockdevs; i++) {
251 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
252 len += 4 + optional_strlen(bd_info->name) +
253 4 + optional_strlen(bd_info->uuid) +
254 4 + optional_strlen(bd_info->mountpoint);
263 static int pb_protocol_interface_config_len(struct interface_config *conf)
267 len = sizeof(conf->hwaddr) +
268 4 /* conf->ignore */;
273 len += 4 /* conf->method */;
275 if (conf->method == CONFIG_METHOD_STATIC) {
276 len += 4 + optional_strlen(conf->static_config.address);
277 len += 4 + optional_strlen(conf->static_config.gateway);
278 len += 4 + optional_strlen(conf->static_config.url);
284 int pb_protocol_config_len(const struct config *config)
288 len = 4 /* config->autoboot_enabled */ +
289 4 /* config->autoboot_timeout_sec */ +
290 4 /* config->safe_mode */;
293 for (i = 0; i < config->network.n_interfaces; i++)
294 len += pb_protocol_interface_config_len(
295 config->network.interfaces[i]);
298 for (i = 0; i < config->network.n_dns_servers; i++)
299 len += 4 + optional_strlen(config->network.dns_servers[i]);
302 for (i = 0; i < config->n_autoboot_opts; i++) {
303 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE)
307 optional_strlen(config->autoboot_opts[i].uuid);
310 len += 4 + 4; /* ipmi_bootdev, ipmi_bootdev_persistent */
312 len += 4; /* allow_writes */
314 len += 4; /* n_tty */
315 for (i = 0; i < config->n_tty; i++)
316 len += 4 + optional_strlen(config->tty_list[i]);
318 len += 4 + optional_strlen(config->boot_tty);
320 len += 4 + optional_strlen(config->lang);
325 int pb_protocol_url_len(const char *url)
327 /* url + length field */
328 return 4 + optional_strlen(url);
331 int pb_protocol_serialise_device(const struct device *dev,
332 char *buf, int buf_len)
336 pos += pb_protocol_serialise_string(pos, dev->id);
337 *(enum device_type *)pos = dev->type;
338 pos += sizeof(enum device_type);
339 pos += pb_protocol_serialise_string(pos, dev->name);
340 pos += pb_protocol_serialise_string(pos, dev->description);
341 pos += pb_protocol_serialise_string(pos, dev->icon_file);
343 assert(pos <= buf + buf_len);
349 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
350 char *buf, int buf_len)
354 pos += pb_protocol_serialise_string(pos, opt->device_id);
355 pos += pb_protocol_serialise_string(pos, opt->id);
356 pos += pb_protocol_serialise_string(pos, opt->name);
357 pos += pb_protocol_serialise_string(pos, opt->description);
358 pos += pb_protocol_serialise_string(pos, opt->icon_file);
359 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
360 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
361 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
362 pos += pb_protocol_serialise_string(pos, opt->boot_args);
364 *(bool *)pos = opt->is_default;
367 assert(pos <= buf + buf_len);
373 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
374 char *buf, int buf_len)
378 pos += pb_protocol_serialise_string(pos, boot->option_id);
379 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
380 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
381 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
382 pos += pb_protocol_serialise_string(pos, boot->boot_args);
383 pos += pb_protocol_serialise_string(pos, boot->tty);
385 assert(pos <= buf + buf_len);
391 int pb_protocol_serialise_boot_status(const struct boot_status *status,
392 char *buf, int buf_len)
396 *(uint32_t *)pos = __cpu_to_be32(status->type);
397 pos += sizeof(uint32_t);
399 pos += pb_protocol_serialise_string(pos, status->message);
400 pos += pb_protocol_serialise_string(pos, status->detail);
402 *(uint32_t *)pos = __cpu_to_be32(status->type);
403 pos += sizeof(uint32_t);
405 assert(pos <= buf + buf_len);
411 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
412 char *buf, int buf_len)
417 pos += pb_protocol_serialise_string(pos, sysinfo->type);
418 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
420 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
421 pos += sizeof(uint32_t);
422 for (i = 0; i < sysinfo->n_primary; i++)
423 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
425 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
426 pos += sizeof(uint32_t);
427 for (i = 0; i < sysinfo->n_other; i++)
428 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
430 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
431 pos += sizeof(uint32_t);
432 for (i = 0; i < sysinfo->n_bmc_current; i++)
433 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
435 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
436 pos += sizeof(uint32_t);
437 for (i = 0; i < sysinfo->n_bmc_golden; i++)
438 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
440 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
441 pos += sizeof(uint32_t);
443 for (i = 0; i < sysinfo->n_interfaces; i++) {
444 struct interface_info *if_info = sysinfo->interfaces[i];
446 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
447 pos += sizeof(uint32_t);
449 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
450 pos += if_info->hwaddr_size;
452 pos += pb_protocol_serialise_string(pos, if_info->name);
454 *(bool *)pos = if_info->link;
458 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
459 pos += sizeof(uint32_t);
461 for (i = 0; i < sysinfo->n_blockdevs; i++) {
462 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
464 pos += pb_protocol_serialise_string(pos, bd_info->name);
465 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
466 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
469 if (sysinfo->bmc_mac)
470 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
472 memset(pos, 0, HWADDR_SIZE);
475 assert(pos <= buf + buf_len);
481 static int pb_protocol_serialise_config_interface(char *buf,
482 struct interface_config *conf)
486 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
487 pos += sizeof(conf->hwaddr);
489 *(uint32_t *)pos = conf->ignore;
495 *(uint32_t *)pos = __cpu_to_be32(conf->method);
498 if (conf->method == CONFIG_METHOD_STATIC) {
499 pos += pb_protocol_serialise_string(pos,
500 conf->static_config.address);
501 pos += pb_protocol_serialise_string(pos,
502 conf->static_config.gateway);
503 pos += pb_protocol_serialise_string(pos,
504 conf->static_config.url);
510 int pb_protocol_serialise_config(const struct config *config,
511 char *buf, int buf_len)
516 *(uint32_t *)pos = config->autoboot_enabled;
519 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
522 *(uint32_t *)pos = config->safe_mode;
525 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
527 for (i = 0; i < config->network.n_interfaces; i++) {
528 struct interface_config *iface =
529 config->network.interfaces[i];
530 pos += pb_protocol_serialise_config_interface(pos, iface);
533 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
535 for (i = 0; i < config->network.n_dns_servers; i++) {
536 pos += pb_protocol_serialise_string(pos,
537 config->network.dns_servers[i]);
540 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
542 for (i = 0; i < config->n_autoboot_opts; i++) {
544 __cpu_to_be32(config->autoboot_opts[i].boot_type);
546 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
548 __cpu_to_be32(config->autoboot_opts[i].type);
551 pos += pb_protocol_serialise_string(pos,
552 config->autoboot_opts[i].uuid);
556 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
558 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
561 *(uint32_t *)pos = config->allow_writes;
564 *(uint32_t *)pos = __cpu_to_be32(config->n_tty);
566 for (i = 0; i < config->n_tty; i++)
567 pos += pb_protocol_serialise_string(pos, config->tty_list[i]);
569 pos += pb_protocol_serialise_string(pos, config->boot_tty);
571 pos += pb_protocol_serialise_string(pos, config->lang);
573 assert(pos <= buf + buf_len);
579 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
583 pos += pb_protocol_serialise_string(pos, url);
585 assert(pos <=buf+buf_len);
591 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
596 total_len = sizeof(*message) + message->payload_len;
598 message->payload_len = __cpu_to_be32(message->payload_len);
599 message->action = __cpu_to_be32(message->action);
601 for (pos = (void *)message; total_len;) {
602 rc = write(fd, pos, total_len);
611 talloc_free(message);
616 pb_log("%s: failed: %s\n", __func__, strerror(errno));
620 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
621 enum pb_protocol_action action, int payload_len)
623 struct pb_protocol_message *message;
625 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
626 pb_log("%s: payload too big %u/%u\n", __func__, payload_len,
627 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
631 message = talloc_size(ctx, sizeof(*message) + payload_len);
633 /* we convert these to big-endian in write_message() */
634 message->action = action;
635 message->payload_len = payload_len;
641 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
643 struct pb_protocol_message *message, m;
647 /* use the stack for the initial 8-byte read */
649 rc = read(fd, &m, sizeof(m));
653 m.payload_len = __be32_to_cpu(m.payload_len);
654 m.action = __be32_to_cpu(m.action);
656 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
657 pb_log("%s: payload too big %u/%u\n", __func__, m.payload_len,
658 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
662 message = talloc_size(ctx, sizeof(m) + m.payload_len);
663 memcpy(message, &m, sizeof(m));
665 for (len = 0; len < m.payload_len;) {
666 rc = read(fd, message->payload + len, m.payload_len - len);
669 talloc_free(message);
670 pb_log("%s: failed (%u): %s\n", __func__, len,
682 int pb_protocol_deserialise_device(struct device *dev,
683 const struct pb_protocol_message *message)
689 len = message->payload_len;
690 pos = message->payload;
692 if (read_string(dev, &pos, &len, &dev->id))
695 if (len < sizeof(enum device_type))
697 dev->type = *(enum device_type *)(pos);
698 pos += sizeof(enum device_type);
699 len -= sizeof(enum device_type);
701 if (read_string(dev, &pos, &len, &dev->name))
704 if (read_string(dev, &pos, &len, &dev->description))
707 if (read_string(dev, &pos, &len, &dev->icon_file))
716 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
717 const struct pb_protocol_message *message)
723 len = message->payload_len;
724 pos = message->payload;
726 if (read_string(opt, &pos, &len, &opt->device_id))
729 if (read_string(opt, &pos, &len, &opt->id))
732 if (read_string(opt, &pos, &len, &opt->name))
735 if (read_string(opt, &pos, &len, &opt->description))
738 if (read_string(opt, &pos, &len, &opt->icon_file))
741 if (read_string(opt, &pos, &len, &opt->boot_image_file))
744 if (read_string(opt, &pos, &len, &opt->initrd_file))
747 if (read_string(opt, &pos, &len, &opt->dtb_file))
750 if (read_string(opt, &pos, &len, &opt->boot_args))
753 if (len < sizeof(bool))
755 opt->is_default = *(bool *)(pos);
763 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
764 const struct pb_protocol_message *message)
770 len = message->payload_len;
771 pos = message->payload;
773 if (read_string(cmd, &pos, &len, &cmd->option_id))
776 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
779 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
782 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
785 if (read_string(cmd, &pos, &len, &cmd->boot_args))
788 if (read_string(cmd, &pos, &len, &cmd->tty))
797 int pb_protocol_deserialise_boot_status(struct boot_status *status,
798 const struct pb_protocol_message *message)
804 len = message->payload_len;
805 pos = message->payload;
807 /* first up, the type enum... */
808 if (len < sizeof(uint32_t))
811 status->type = __be32_to_cpu(*(uint32_t *)(pos));
813 switch (status->type) {
814 case BOOT_STATUS_ERROR:
815 case BOOT_STATUS_INFO:
821 pos += sizeof(uint32_t);
822 len -= sizeof(uint32_t);
824 /* message and detail strings */
825 if (read_string(status, &pos, &len, &status->message))
828 if (read_string(status, &pos, &len, &status->detail))
831 /* and finally, progress */
832 if (len < sizeof(uint32_t))
835 status->progress = __be32_to_cpu(*(uint32_t *)(pos));
838 if (status->progress > 100)
839 status->progress = 100;
847 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
848 const struct pb_protocol_message *message)
855 len = message->payload_len;
856 pos = message->payload;
858 /* type and identifier strings */
859 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
862 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
865 /* Platform version strings for openpower platforms */
866 if (read_u32(&pos, &len, &sysinfo->n_primary))
868 sysinfo->platform_primary = talloc_array(sysinfo, char *,
870 for (i = 0; i < sysinfo->n_primary; i++) {
871 if (read_string(sysinfo, &pos, &len, &tmp))
873 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
876 if (read_u32(&pos, &len, &sysinfo->n_other))
878 sysinfo->platform_other = talloc_array(sysinfo, char *,
880 for (i = 0; i < sysinfo->n_other; i++) {
881 if (read_string(sysinfo, &pos, &len, &tmp))
883 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
886 /* BMC version strings for openpower platforms */
887 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
889 sysinfo->bmc_current = talloc_array(sysinfo, char *,
890 sysinfo->n_bmc_current);
891 for (i = 0; i < sysinfo->n_bmc_current; i++) {
892 if (read_string(sysinfo, &pos, &len, &tmp))
894 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
897 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
899 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
900 sysinfo->n_bmc_golden);
901 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
902 if (read_string(sysinfo, &pos, &len, &tmp))
904 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
907 /* number of interfaces */
908 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
911 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
912 sysinfo->n_interfaces);
914 for (i = 0; i < sysinfo->n_interfaces; i++) {
915 struct interface_info *if_info = talloc(sysinfo,
916 struct interface_info);
918 if (read_u32(&pos, &len, &if_info->hwaddr_size))
921 if (len < if_info->hwaddr_size)
924 if_info->hwaddr = talloc_memdup(if_info, pos,
925 if_info->hwaddr_size);
926 pos += if_info->hwaddr_size;
927 len -= if_info->hwaddr_size;
929 if (read_string(if_info, &pos, &len, &if_info->name))
932 if_info->link = *(bool *)pos;
933 pos += sizeof(if_info->link);
935 sysinfo->interfaces[i] = if_info;
938 /* number of interfaces */
939 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
942 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
943 sysinfo->n_blockdevs);
945 for (i = 0; i < sysinfo->n_blockdevs; i++) {
946 struct blockdev_info *bd_info = talloc(sysinfo,
947 struct blockdev_info);
949 if (read_string(bd_info, &pos, &len, &bd_info->name))
952 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
955 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
958 sysinfo->blockdevs[i] = bd_info;
961 for (i = 0; i < HWADDR_SIZE; i++) {
963 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
976 static int pb_protocol_deserialise_config_interface(const char **buf,
977 unsigned int *len, struct interface_config *iface)
981 if (*len < sizeof(iface->hwaddr))
984 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
985 *buf += sizeof(iface->hwaddr);
986 *len -= sizeof(iface->hwaddr);
988 if (read_u32(buf, len, &tmp))
990 iface->ignore = !!tmp;
995 if (read_u32(buf, len, &iface->method))
998 if (iface->method == CONFIG_METHOD_STATIC) {
999 if (read_string(iface, buf, len, &iface->static_config.address))
1002 if (read_string(iface, buf, len, &iface->static_config.gateway))
1005 if (read_string(iface, buf, len, &iface->static_config.url))
1012 int pb_protocol_deserialise_config(struct config *config,
1013 const struct pb_protocol_message *message)
1015 unsigned int len, i, tmp;
1020 len = message->payload_len;
1021 pos = message->payload;
1023 if (read_u32(&pos, &len, &tmp))
1025 config->autoboot_enabled = !!tmp;
1027 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1030 if (read_u32(&pos, &len, &tmp))
1032 config->safe_mode = !!tmp;
1034 if (read_u32(&pos, &len, &config->network.n_interfaces))
1037 config->network.interfaces = talloc_array(config,
1038 struct interface_config *, config->network.n_interfaces);
1040 for (i = 0; i < config->network.n_interfaces; i++) {
1041 struct interface_config *iface = talloc_zero(
1042 config->network.interfaces,
1043 struct interface_config);
1044 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1046 config->network.interfaces[i] = iface;
1049 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1051 config->network.dns_servers = talloc_array(config, const char *,
1052 config->network.n_dns_servers);
1054 for (i = 0; i < config->network.n_dns_servers; i++) {
1055 if (read_string(config->network.dns_servers, &pos, &len, &str))
1057 config->network.dns_servers[i] = str;
1060 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1062 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1063 config->n_autoboot_opts);
1065 for (i = 0; i < config->n_autoboot_opts; i++) {
1066 if (read_u32(&pos, &len, &tmp))
1068 config->autoboot_opts[i].boot_type = (int)tmp;
1069 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1070 if (read_u32(&pos, &len, &tmp))
1072 config->autoboot_opts[i].type = tmp;
1074 if (read_string(config, &pos, &len, &str))
1076 config->autoboot_opts[i].uuid = str;
1080 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1082 if (read_u32(&pos, &len, &tmp))
1084 config->ipmi_bootdev_persistent = !!tmp;
1086 if (read_u32(&pos, &len, &tmp))
1088 config->allow_writes = !!tmp;
1090 if (read_u32(&pos, &len, &config->n_tty))
1093 config->tty_list = talloc_array(config, char *, config->n_tty);
1094 for (i = 0; i < config->n_tty; i++) {
1095 if (read_string(config->tty_list, &pos, &len, &str))
1097 config->tty_list[i] = str;
1100 if (read_string(config, &pos, &len, &str))
1103 config->boot_tty = str;
1105 if (read_string(config, &pos, &len, &str))