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_authenticate_len(struct auth_message *msg)
385 case AUTH_MSG_REQUEST:
386 /* enum + password + length */
387 return 4 + 4 + optional_strlen(msg->password);
388 case AUTH_MSG_RESPONSE:
392 /* enum + password + password */
393 return 4 + 4 + optional_strlen(msg->set_password.password) +
394 4 + optional_strlen(msg->set_password.new_password);
396 pb_log("%s: invalid input\n", __func__);
401 int pb_protocol_serialise_device(const struct device *dev,
402 char *buf, int buf_len)
406 pos += pb_protocol_serialise_string(pos, dev->id);
407 *(enum device_type *)pos = dev->type;
408 pos += sizeof(enum device_type);
409 pos += pb_protocol_serialise_string(pos, dev->name);
410 pos += pb_protocol_serialise_string(pos, dev->description);
411 pos += pb_protocol_serialise_string(pos, dev->icon_file);
413 assert(pos <= buf + buf_len);
419 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
420 char *buf, int buf_len)
424 pos += pb_protocol_serialise_string(pos, opt->device_id);
425 pos += pb_protocol_serialise_string(pos, opt->id);
426 pos += pb_protocol_serialise_string(pos, opt->name);
427 pos += pb_protocol_serialise_string(pos, opt->description);
428 pos += pb_protocol_serialise_string(pos, opt->icon_file);
429 pos += pb_protocol_serialise_string(pos, opt->boot_image_file);
430 pos += pb_protocol_serialise_string(pos, opt->initrd_file);
431 pos += pb_protocol_serialise_string(pos, opt->dtb_file);
432 pos += pb_protocol_serialise_string(pos, opt->boot_args);
433 pos += pb_protocol_serialise_string(pos, opt->args_sig_file);
435 *(bool *)pos = opt->is_default;
438 *(uint32_t *)pos = __cpu_to_be32(opt->type);
441 assert(pos <= buf + buf_len);
447 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
448 char *buf, int buf_len)
452 pos += pb_protocol_serialise_string(pos, boot->option_id);
453 pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
454 pos += pb_protocol_serialise_string(pos, boot->initrd_file);
455 pos += pb_protocol_serialise_string(pos, boot->dtb_file);
456 pos += pb_protocol_serialise_string(pos, boot->boot_args);
457 pos += pb_protocol_serialise_string(pos, boot->args_sig_file);
458 pos += pb_protocol_serialise_string(pos, boot->console);
460 assert(pos <= buf + buf_len);
466 int pb_protocol_serialise_boot_status(const struct status *status,
467 char *buf, int buf_len)
471 *(uint32_t *)pos = __cpu_to_be32(status->type);
472 pos += sizeof(uint32_t);
474 pos += pb_protocol_serialise_string(pos, status->message);
476 *(bool *)pos = __cpu_to_be32(status->backlog);
479 *(bool *)pos = __cpu_to_be32(status->boot_active);
482 assert(pos <= buf + buf_len);
488 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
489 char *buf, int buf_len)
494 pos += pb_protocol_serialise_string(pos, sysinfo->type);
495 pos += pb_protocol_serialise_string(pos, sysinfo->identifier);
497 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_primary);
498 pos += sizeof(uint32_t);
499 for (i = 0; i < sysinfo->n_primary; i++)
500 pos += pb_protocol_serialise_string(pos, sysinfo->platform_primary[i]);
502 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_other);
503 pos += sizeof(uint32_t);
504 for (i = 0; i < sysinfo->n_other; i++)
505 pos += pb_protocol_serialise_string(pos, sysinfo->platform_other[i]);
507 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_current);
508 pos += sizeof(uint32_t);
509 for (i = 0; i < sysinfo->n_bmc_current; i++)
510 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_current[i]);
512 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_bmc_golden);
513 pos += sizeof(uint32_t);
514 for (i = 0; i < sysinfo->n_bmc_golden; i++)
515 pos += pb_protocol_serialise_string(pos, sysinfo->bmc_golden[i]);
517 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_interfaces);
518 pos += sizeof(uint32_t);
520 for (i = 0; i < sysinfo->n_interfaces; i++) {
521 struct interface_info *if_info = sysinfo->interfaces[i];
523 *(uint32_t *)pos = __cpu_to_be32(if_info->hwaddr_size);
524 pos += sizeof(uint32_t);
526 memcpy(pos, if_info->hwaddr, if_info->hwaddr_size);
527 pos += if_info->hwaddr_size;
529 pos += pb_protocol_serialise_string(pos, if_info->name);
531 *(bool *)pos = if_info->link;
534 pos += pb_protocol_serialise_string(pos, if_info->address);
535 pos += pb_protocol_serialise_string(pos, if_info->address_v6);
538 *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
539 pos += sizeof(uint32_t);
541 for (i = 0; i < sysinfo->n_blockdevs; i++) {
542 struct blockdev_info *bd_info = sysinfo->blockdevs[i];
544 pos += pb_protocol_serialise_string(pos, bd_info->name);
545 pos += pb_protocol_serialise_string(pos, bd_info->uuid);
546 pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
549 if (sysinfo->bmc_mac)
550 memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
552 memset(pos, 0, HWADDR_SIZE);
555 assert(pos <= buf + buf_len);
561 static int pb_protocol_serialise_config_interface(char *buf,
562 struct interface_config *conf)
566 memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
567 pos += sizeof(conf->hwaddr);
569 *(uint32_t *)pos = conf->ignore;
575 *(uint32_t *)pos = __cpu_to_be32(conf->method);
578 if (conf->method == CONFIG_METHOD_STATIC) {
579 pos += pb_protocol_serialise_string(pos,
580 conf->static_config.address);
581 pos += pb_protocol_serialise_string(pos,
582 conf->static_config.gateway);
583 pos += pb_protocol_serialise_string(pos,
584 conf->static_config.url);
587 *(uint32_t *)pos = conf->override;
593 int pb_protocol_serialise_config(const struct config *config,
594 char *buf, int buf_len)
599 *(uint32_t *)pos = config->autoboot_enabled;
602 *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
605 *(uint32_t *)pos = config->safe_mode;
608 *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
610 for (i = 0; i < config->network.n_interfaces; i++) {
611 struct interface_config *iface =
612 config->network.interfaces[i];
613 pos += pb_protocol_serialise_config_interface(pos, iface);
616 *(uint32_t *)pos = __cpu_to_be32(config->network.n_dns_servers);
618 for (i = 0; i < config->network.n_dns_servers; i++) {
619 pos += pb_protocol_serialise_string(pos,
620 config->network.dns_servers[i]);
623 pos += pb_protocol_serialise_string(pos, config->http_proxy);
624 pos += pb_protocol_serialise_string(pos, config->https_proxy);
626 *(uint32_t *)pos = __cpu_to_be32(config->n_autoboot_opts);
628 for (i = 0; i < config->n_autoboot_opts; i++) {
630 __cpu_to_be32(config->autoboot_opts[i].boot_type);
632 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
634 __cpu_to_be32(config->autoboot_opts[i].type);
637 pos += pb_protocol_serialise_string(pos,
638 config->autoboot_opts[i].uuid);
642 *(uint32_t *)pos = __cpu_to_be32(config->ipmi_bootdev);
644 *(uint32_t *)pos = config->ipmi_bootdev_persistent;
647 *(uint32_t *)pos = config->allow_writes;
650 *(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
652 for (i = 0; i < config->n_consoles; i++)
653 pos += pb_protocol_serialise_string(pos, config->consoles[i]);
655 pos += pb_protocol_serialise_string(pos, config->boot_console);
656 *(uint32_t *)pos = config->manual_console;
659 pos += pb_protocol_serialise_string(pos, config->lang);
661 assert(pos <= buf + buf_len);
667 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
671 pos += pb_protocol_serialise_string(pos, url);
673 assert(pos <=buf+buf_len);
679 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
680 char *buf, int buf_len)
685 pos += pb_protocol_serialise_string(pos, opt->id);
686 pos += pb_protocol_serialise_string(pos, opt->name);
687 pos += pb_protocol_serialise_string(pos, opt->vendor);
688 pos += pb_protocol_serialise_string(pos, opt->vendor_id);
689 pos += pb_protocol_serialise_string(pos, opt->version);
690 pos += pb_protocol_serialise_string(pos, opt->date);
691 pos += pb_protocol_serialise_string(pos, opt->plugin_file);
693 *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
696 for (i = 0; i < opt->n_executables; i++)
697 pos += pb_protocol_serialise_string(pos, opt->executables[i]);
699 assert(pos <= buf + buf_len);
705 int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt,
706 char *buf, int buf_len)
710 *(uint32_t *)pos = __cpu_to_be32(opt->boot_type);
713 if (opt->boot_type == BOOT_DEVICE_TYPE) {
714 *(uint32_t *)pos = __cpu_to_be32(opt->type);
717 pos += pb_protocol_serialise_string(pos, opt->uuid);
725 int pb_protocol_serialise_authenticate(struct auth_message *msg,
726 char *buf, int buf_len)
730 *(enum auth_msg_type *)pos = msg->op;
731 pos += sizeof(enum auth_msg_type);
734 case AUTH_MSG_REQUEST:
735 pos += pb_protocol_serialise_string(pos, msg->password);
737 case AUTH_MSG_RESPONSE:
738 *(bool *)pos = msg->authenticated;
742 pos += pb_protocol_serialise_string(pos,
743 msg->set_password.password);
744 pos += pb_protocol_serialise_string(pos,
745 msg->set_password.new_password);
748 pb_log("%s: invalid msg\n", __func__);
752 assert(pos <= buf + buf_len);
758 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
763 total_len = sizeof(*message) + message->payload_len;
765 message->payload_len = __cpu_to_be32(message->payload_len);
766 message->action = __cpu_to_be32(message->action);
768 for (pos = (void *)message; total_len;) {
769 rc = write(fd, pos, total_len);
778 talloc_free(message);
783 pb_log_fn("failed: %s\n", strerror(errno));
787 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
788 enum pb_protocol_action action, int payload_len)
790 struct pb_protocol_message *message;
792 if (payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
793 pb_log_fn("payload too big %u/%u\n", payload_len,
794 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
798 message = talloc_size(ctx, sizeof(*message) + payload_len);
800 /* we convert these to big-endian in write_message() */
801 message->action = action;
802 message->payload_len = payload_len;
808 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd)
810 struct pb_protocol_message *message, m;
814 /* use the stack for the initial 8-byte read */
816 rc = read(fd, &m, sizeof(m));
820 m.payload_len = __be32_to_cpu(m.payload_len);
821 m.action = __be32_to_cpu(m.action);
823 if (m.payload_len > PB_PROTOCOL_MAX_PAYLOAD_SIZE) {
824 pb_log_fn("payload too big %u/%u\n", m.payload_len,
825 PB_PROTOCOL_MAX_PAYLOAD_SIZE);
829 message = talloc_size(ctx, sizeof(m) + m.payload_len);
830 memcpy(message, &m, sizeof(m));
832 for (len = 0; len < m.payload_len;) {
833 rc = read(fd, message->payload + len, m.payload_len - len);
836 talloc_free(message);
837 pb_log_fn("failed (%u): %s\n", len,
849 int pb_protocol_deserialise_device(struct device *dev,
850 const struct pb_protocol_message *message)
856 len = message->payload_len;
857 pos = message->payload;
859 if (read_string(dev, &pos, &len, &dev->id))
862 if (len < sizeof(enum device_type))
864 dev->type = *(enum device_type *)(pos);
865 pos += sizeof(enum device_type);
866 len -= sizeof(enum device_type);
868 if (read_string(dev, &pos, &len, &dev->name))
871 if (read_string(dev, &pos, &len, &dev->description))
874 if (read_string(dev, &pos, &len, &dev->icon_file))
883 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
884 const struct pb_protocol_message *message)
890 len = message->payload_len;
891 pos = message->payload;
893 if (read_string(opt, &pos, &len, &opt->device_id))
896 if (read_string(opt, &pos, &len, &opt->id))
899 if (read_string(opt, &pos, &len, &opt->name))
902 if (read_string(opt, &pos, &len, &opt->description))
905 if (read_string(opt, &pos, &len, &opt->icon_file))
908 if (read_string(opt, &pos, &len, &opt->boot_image_file))
911 if (read_string(opt, &pos, &len, &opt->initrd_file))
914 if (read_string(opt, &pos, &len, &opt->dtb_file))
917 if (read_string(opt, &pos, &len, &opt->boot_args))
920 if (read_string(opt, &pos, &len, &opt->args_sig_file))
923 if (len < sizeof(bool))
925 opt->is_default = *(bool *)(pos);
929 if (read_u32(&pos, &len, &opt->type))
938 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
939 const struct pb_protocol_message *message)
945 len = message->payload_len;
946 pos = message->payload;
948 if (read_string(cmd, &pos, &len, &cmd->option_id))
951 if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
954 if (read_string(cmd, &pos, &len, &cmd->initrd_file))
957 if (read_string(cmd, &pos, &len, &cmd->dtb_file))
960 if (read_string(cmd, &pos, &len, &cmd->boot_args))
963 if (read_string(cmd, &pos, &len, &cmd->args_sig_file))
966 if (read_string(cmd, &pos, &len, &cmd->console))
975 int pb_protocol_deserialise_boot_status(struct status *status,
976 const struct pb_protocol_message *message)
982 len = message->payload_len;
983 pos = message->payload;
985 /* first up, the type enum... */
986 if (len < sizeof(uint32_t))
989 status->type = __be32_to_cpu(*(uint32_t *)(pos));
991 switch (status->type) {
999 pos += sizeof(uint32_t);
1000 len -= sizeof(uint32_t);
1002 /* message string */
1003 if (read_string(status, &pos, &len, &status->message))
1007 status->backlog = *(bool *)pos;
1008 pos += sizeof(status->backlog);
1011 status->boot_active = *(bool *)pos;
1012 pos += sizeof(status->boot_active);
1020 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
1021 const struct pb_protocol_message *message)
1023 unsigned int len, i;
1028 len = message->payload_len;
1029 pos = message->payload;
1031 /* type and identifier strings */
1032 if (read_string(sysinfo, &pos, &len, &sysinfo->type))
1035 if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
1038 /* Platform version strings for openpower platforms */
1039 if (read_u32(&pos, &len, &sysinfo->n_primary))
1041 sysinfo->platform_primary = talloc_array(sysinfo, char *,
1042 sysinfo->n_primary);
1043 for (i = 0; i < sysinfo->n_primary; i++) {
1044 if (read_string(sysinfo, &pos, &len, &tmp))
1046 sysinfo->platform_primary[i] = talloc_strdup(sysinfo, tmp);
1049 if (read_u32(&pos, &len, &sysinfo->n_other))
1051 sysinfo->platform_other = talloc_array(sysinfo, char *,
1053 for (i = 0; i < sysinfo->n_other; i++) {
1054 if (read_string(sysinfo, &pos, &len, &tmp))
1056 sysinfo->platform_other[i] = talloc_strdup(sysinfo, tmp);
1059 /* BMC version strings for openpower platforms */
1060 if (read_u32(&pos, &len, &sysinfo->n_bmc_current))
1062 sysinfo->bmc_current = talloc_array(sysinfo, char *,
1063 sysinfo->n_bmc_current);
1064 for (i = 0; i < sysinfo->n_bmc_current; i++) {
1065 if (read_string(sysinfo, &pos, &len, &tmp))
1067 sysinfo->bmc_current[i] = talloc_strdup(sysinfo, tmp);
1070 if (read_u32(&pos, &len, &sysinfo->n_bmc_golden))
1072 sysinfo->bmc_golden = talloc_array(sysinfo, char *,
1073 sysinfo->n_bmc_golden);
1074 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
1075 if (read_string(sysinfo, &pos, &len, &tmp))
1077 sysinfo->bmc_golden[i] = talloc_strdup(sysinfo, tmp);
1080 /* number of interfaces */
1081 if (read_u32(&pos, &len, &sysinfo->n_interfaces))
1084 sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
1085 sysinfo->n_interfaces);
1087 for (i = 0; i < sysinfo->n_interfaces; i++) {
1088 struct interface_info *if_info = talloc(sysinfo,
1089 struct interface_info);
1091 if (read_u32(&pos, &len, &if_info->hwaddr_size))
1094 if (len < if_info->hwaddr_size)
1097 if_info->hwaddr = talloc_memdup(if_info, pos,
1098 if_info->hwaddr_size);
1099 pos += if_info->hwaddr_size;
1100 len -= if_info->hwaddr_size;
1102 if (read_string(if_info, &pos, &len, &if_info->name))
1105 if_info->link = *(bool *)pos;
1106 pos += sizeof(if_info->link);
1108 if (read_string(if_info, &pos, &len, &if_info->address))
1110 if (read_string(if_info, &pos, &len, &if_info->address_v6))
1113 sysinfo->interfaces[i] = if_info;
1116 /* number of interfaces */
1117 if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
1120 sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
1121 sysinfo->n_blockdevs);
1123 for (i = 0; i < sysinfo->n_blockdevs; i++) {
1124 struct blockdev_info *bd_info = talloc(sysinfo,
1125 struct blockdev_info);
1127 if (read_string(bd_info, &pos, &len, &bd_info->name))
1130 if (read_string(bd_info, &pos, &len, &bd_info->uuid))
1133 if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
1136 sysinfo->blockdevs[i] = bd_info;
1139 for (i = 0; i < HWADDR_SIZE; i++) {
1141 sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
1154 static int pb_protocol_deserialise_config_interface(const char **buf,
1155 unsigned int *len, struct interface_config *iface)
1159 if (*len < sizeof(iface->hwaddr))
1162 memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
1163 *buf += sizeof(iface->hwaddr);
1164 *len -= sizeof(iface->hwaddr);
1166 if (read_u32(buf, len, &tmp))
1168 iface->ignore = !!tmp;
1173 if (read_u32(buf, len, &iface->method))
1176 if (iface->method == CONFIG_METHOD_STATIC) {
1177 if (read_string(iface, buf, len, &iface->static_config.address))
1180 if (read_string(iface, buf, len, &iface->static_config.gateway))
1183 if (read_string(iface, buf, len, &iface->static_config.url))
1187 if (read_u32(buf, len, &tmp))
1189 iface->override = !!tmp;
1194 int pb_protocol_deserialise_config(struct config *config,
1195 const struct pb_protocol_message *message)
1197 unsigned int len, i, tmp;
1202 len = message->payload_len;
1203 pos = message->payload;
1205 if (read_u32(&pos, &len, &tmp))
1207 config->autoboot_enabled = !!tmp;
1209 if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
1212 if (read_u32(&pos, &len, &tmp))
1214 config->safe_mode = !!tmp;
1216 if (read_u32(&pos, &len, &config->network.n_interfaces))
1219 config->network.interfaces = talloc_array(config,
1220 struct interface_config *, config->network.n_interfaces);
1222 for (i = 0; i < config->network.n_interfaces; i++) {
1223 struct interface_config *iface = talloc_zero(
1224 config->network.interfaces,
1225 struct interface_config);
1226 if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
1228 config->network.interfaces[i] = iface;
1231 if (read_u32(&pos, &len, &config->network.n_dns_servers))
1233 config->network.dns_servers = talloc_array(config, const char *,
1234 config->network.n_dns_servers);
1236 for (i = 0; i < config->network.n_dns_servers; i++) {
1237 if (read_string(config->network.dns_servers, &pos, &len, &str))
1239 config->network.dns_servers[i] = str;
1242 if (read_string(config, &pos, &len, &str))
1244 config->http_proxy = str;
1245 if (read_string(config, &pos, &len, &str))
1247 config->https_proxy = str;
1249 if (read_u32(&pos, &len, &config->n_autoboot_opts))
1251 config->autoboot_opts = talloc_array(config, struct autoboot_option,
1252 config->n_autoboot_opts);
1254 for (i = 0; i < config->n_autoboot_opts; i++) {
1255 if (read_u32(&pos, &len, &tmp))
1257 config->autoboot_opts[i].boot_type = (int)tmp;
1258 if (config->autoboot_opts[i].boot_type == BOOT_DEVICE_TYPE) {
1259 if (read_u32(&pos, &len, &tmp))
1261 config->autoboot_opts[i].type = tmp;
1263 if (read_string(config, &pos, &len, &str))
1265 config->autoboot_opts[i].uuid = str;
1269 if (read_u32(&pos, &len, &config->ipmi_bootdev))
1271 if (read_u32(&pos, &len, &tmp))
1273 config->ipmi_bootdev_persistent = !!tmp;
1275 if (read_u32(&pos, &len, &tmp))
1277 config->allow_writes = !!tmp;
1279 if (read_u32(&pos, &len, &config->n_consoles))
1282 config->consoles = talloc_array(config, char *, config->n_consoles);
1283 for (i = 0; i < config->n_consoles; i++) {
1284 if (read_string(config->consoles, &pos, &len, &str))
1286 config->consoles[i] = str;
1289 if (read_string(config, &pos, &len, &str))
1292 config->boot_console = str;
1294 if (read_u32(&pos, &len, &tmp))
1296 config->manual_console = !!tmp;
1298 if (read_string(config, &pos, &len, &str))
1309 int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
1310 const struct pb_protocol_message *message)
1312 unsigned int len, i, tmp;
1317 len = message->payload_len;
1318 pos = message->payload;
1320 if (read_string(opt, &pos, &len, &str))
1324 if (read_string(opt, &pos, &len, &str))
1328 if (read_string(opt, &pos, &len, &str))
1332 if (read_string(opt, &pos, &len, &str))
1334 opt->vendor_id = str;
1336 if (read_string(opt, &pos, &len, &str))
1340 if (read_string(opt, &pos, &len, &str))
1344 if (read_string(opt, &pos, &len, &str))
1346 opt->plugin_file = str;
1348 if (read_u32(&pos, &len, &tmp))
1350 opt->n_executables = tmp;
1352 opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
1353 if (!opt->executables)
1356 for (i = 0; i < opt->n_executables; i++) {
1357 if (read_string(opt, &pos, &len, &str))
1359 opt->executables[i] = talloc_strdup(opt, str);
1367 int pb_protocol_deserialise_temp_autoboot(struct autoboot_option *opt,
1368 const struct pb_protocol_message *message)
1370 unsigned int len, tmp;
1375 len = message->payload_len;
1376 pos = message->payload;
1378 if (read_u32(&pos, &len, &tmp))
1381 opt->boot_type = tmp;
1382 if (opt->boot_type == BOOT_DEVICE_TYPE) {
1383 if (read_u32(&pos, &len, &tmp))
1387 } else if (opt->boot_type == BOOT_DEVICE_UUID) {
1388 if (read_string(opt, &pos, &len, &str))
1402 int pb_protocol_deserialise_authenticate(struct auth_message *msg,
1403 const struct pb_protocol_message *message)
1408 len = message->payload_len;
1409 pos = message->payload;
1411 msg->op = *(enum auth_msg_type *)pos;
1412 pos += sizeof(enum auth_msg_type);
1415 case AUTH_MSG_REQUEST:
1416 if (read_string(msg, &pos, &len, &msg->password))
1419 case AUTH_MSG_RESPONSE:
1420 msg->authenticated = *(bool *)pos;
1421 pos += sizeof(bool);
1424 if (read_string(msg, &pos, &len, &msg->set_password.password))
1426 if (read_string(msg, &pos, &len,
1427 &msg->set_password.new_password))
1431 pb_log("%s: unable to parse\n", __func__);