]> git.ozlabs.org Git - petitboot/blob - lib/pb-protocol/pb-protocol.h
lib: Add AUTH_MSG_DECRYPT
[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         PB_PROTOCOL_ACTION_ADD_URL              = 0xb,
26         PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD    = 0xc,
27         PB_PROTOCOL_ACTION_PLUGINS_REMOVE       = 0xd,
28         PB_PROTOCOL_ACTION_PLUGIN_INSTALL       = 0xe,
29         PB_PROTOCOL_ACTION_TEMP_AUTOBOOT        = 0xf,
30         PB_PROTOCOL_ACTION_AUTHENTICATE         = 0x10,
31 };
32
33 struct pb_protocol_message {
34         uint32_t action;
35         uint32_t payload_len;
36         char     payload[];
37 };
38
39 enum auth_msg_type {
40         AUTH_MSG_REQUEST,
41         AUTH_MSG_RESPONSE,
42         AUTH_MSG_SET,
43         AUTH_MSG_DECRYPT,
44 };
45
46 struct auth_message {
47         enum auth_msg_type op;
48         union {
49                 bool    authenticated;
50                 char    *password;
51                 struct {
52                         char    *password;
53                         char    *new_password;
54                 } set_password;
55                 struct {
56                         char    *password;
57                         char    *device_id;
58                 } decrypt_dev;
59         };
60 };
61
62 void pb_protocol_dump_device(const struct device *dev, const char *text,
63         FILE *stream);
64 int pb_protocol_device_len(const struct device *dev);
65 int pb_protocol_boot_option_len(const struct boot_option *opt);
66 int pb_protocol_boot_len(const struct boot_command *boot);
67 int pb_protocol_boot_status_len(const struct status *status);
68 int pb_protocol_system_info_len(const struct system_info *sysinfo);
69 int pb_protocol_config_len(const struct config *config);
70 int pb_protocol_url_len(const char *url);
71 int pb_protocol_plugin_option_len(const struct plugin_option *opt);
72 int pb_protocol_temp_autoboot_len(const struct autoboot_option *opt);
73 int pb_protocol_authenticate_len(struct auth_message *msg);
74 int pb_protocol_device_cmp(const struct device *a, const struct device *b);
75
76 int pb_protocol_boot_option_cmp(const struct boot_option *a,
77         const struct boot_option *b);
78
79 int pb_protocol_serialise_string(char *pos, const char *str);
80 char *pb_protocol_deserialise_string(void *ctx,
81                 const struct pb_protocol_message *message);
82
83 int pb_protocol_serialise_device(const struct device *dev,
84                 char *buf, int buf_len);
85 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
86                 char *buf, int buf_len);
87 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
88                 char *buf, int buf_len);
89 int pb_protocol_serialise_boot_status(const struct status *status,
90                 char *buf, int buf_len);
91 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
92                 char *buf, int buf_len);
93 int pb_protocol_serialise_config(const struct config *config,
94                 char *buf, int buf_len);
95 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len);
96 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
97                 char *buf, int buf_len);
98 int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt,
99                 char *buf, int buf_len);
100 int pb_protocol_serialise_authenticate(struct auth_message *msg,
101                 char *buf, int buf_len);
102
103 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
104
105 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
106                 enum pb_protocol_action action, int payload_len);
107
108 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
109
110 int pb_protocol_deserialise_device(struct device *dev,
111                 const struct pb_protocol_message *message);
112
113 int pb_protocol_deserialise_boot_option(struct boot_option *opt,
114                 const struct pb_protocol_message *message);
115
116 int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
117                 const struct pb_protocol_message *message);
118
119 int pb_protocol_deserialise_boot_status(struct status *status,
120                 const struct pb_protocol_message *message);
121
122 int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
123                 const struct pb_protocol_message *message);
124
125 int pb_protocol_deserialise_config(struct config *config,
126                 const struct pb_protocol_message *message);
127
128 int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
129                 const struct pb_protocol_message *message);
130
131 int pb_protocol_deserialise_temp_autoboot(struct autoboot_option *opt,
132                 const struct pb_protocol_message *message);
133
134 int pb_protocol_deserialise_authenticate(struct auth_message *msg,
135                 const struct pb_protocol_message *message);
136 #endif /* _PB_PROTOCOL_H */