]> git.ozlabs.org Git - petitboot/blob - lib/pb-protocol/pb-protocol.h
protocol: expose discovery reinit over client/server protocol
[petitboot] / lib / pb-protocol / pb-protocol.h
1 #ifndef _PB_PROTOCOL_H
2 #define _PB_PROTOCOL_H
3
4 #include <stdint.h>
5 #include <stdio.h>
6
7 #include <list/list.h>
8 #include <types/types.h>
9
10 #define PB_SOCKET_PATH "/tmp/petitboot.ui"
11
12 #define PB_PROTOCOL_MAX_PAYLOAD_SIZE (64 * 1024)
13
14 enum pb_protocol_action {
15         PB_PROTOCOL_ACTION_DEVICE_ADD           = 0x1,
16         PB_PROTOCOL_ACTION_BOOT_OPTION_ADD      = 0x2,
17         PB_PROTOCOL_ACTION_DEVICE_REMOVE        = 0x3,
18 /*      PB_PROTOCOL_ACTION_BOOT_OPTION_REMOVE   = 0x4, */
19         PB_PROTOCOL_ACTION_BOOT                 = 0x5,
20         PB_PROTOCOL_ACTION_STATUS               = 0x6,
21         PB_PROTOCOL_ACTION_CANCEL_DEFAULT       = 0x7,
22         PB_PROTOCOL_ACTION_SYSTEM_INFO          = 0x8,
23         PB_PROTOCOL_ACTION_CONFIG               = 0x9,
24         PB_PROTOCOL_ACTION_REINIT               = 0xa,
25 };
26
27 struct pb_protocol_message {
28         uint32_t action;
29         uint32_t payload_len;
30         char     payload[];
31 };
32
33 void pb_protocol_dump_device(const struct device *dev, const char *text,
34         FILE *stream);
35 int pb_protocol_device_len(const struct device *dev);
36 int pb_protocol_boot_option_len(const struct boot_option *opt);
37 int pb_protocol_boot_len(const struct boot_command *boot);
38 int pb_protocol_boot_status_len(const struct boot_status *status);
39 int pb_protocol_system_info_len(const struct system_info *sysinfo);
40 int pb_protocol_config_len(const struct config *config);
41 int pb_protocol_device_cmp(const struct device *a, const struct device *b);
42
43 int pb_protocol_boot_option_cmp(const struct boot_option *a,
44         const struct boot_option *b);
45
46 int pb_protocol_serialise_string(char *pos, const char *str);
47 char *pb_protocol_deserialise_string(void *ctx,
48                 const struct pb_protocol_message *message);
49
50 int pb_protocol_serialise_device(const struct device *dev,
51                 char *buf, int buf_len);
52 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
53                 char *buf, int buf_len);
54 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
55                 char *buf, int buf_len);
56 int pb_protocol_serialise_boot_status(const struct boot_status *status,
57                 char *buf, int buf_len);
58 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
59                 char *buf, int buf_len);
60 int pb_protocol_serialise_config(const struct config *config,
61                 char *buf, int buf_len);
62
63 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
64
65 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
66                 enum pb_protocol_action action, int payload_len);
67
68 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
69
70 int pb_protocol_deserialise_device(struct device *dev,
71                 const struct pb_protocol_message *message);
72
73 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
74                 const struct pb_protocol_message *message);
75
76 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
77                 const struct pb_protocol_message *message);
78
79 int pb_protocol_deserialise_boot_status(struct boot_status *status,
80                 const struct pb_protocol_message *message);
81
82 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
83                 const struct pb_protocol_message *message);
84
85 int pb_protocol_deserialise_config(struct config *config,
86                 const struct pb_protocol_message *message);
87 #endif /* _PB_PROTOCOL_H */