]> git.ozlabs.org Git - petitboot/blob - lib/pb-protocol/pb-protocol.h
lib/types: Create common file for type definitions
[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_ADD          = 0x1,
16         PB_PROTOCOL_ACTION_REMOVE       = 0x2,
17 };
18
19 struct pb_protocol_message {
20         uint32_t action;
21         uint32_t payload_len;
22         char     payload[];
23 };
24
25 void pb_protocol_dump_device(const struct device *dev, const char *text,
26         FILE *stream);
27 int pb_protocol_device_len(const struct device *dev);
28 int pb_protocol_device_cmp(const struct device *a, const struct device *b);
29
30 int pb_protocol_boot_option_cmp(const struct boot_option *a,
31         const struct boot_option *b);
32
33 int pb_protocol_serialise_string(char *pos, const char *str);
34 char *pb_protocol_deserialise_string(void *ctx,
35                 const struct pb_protocol_message *message);
36
37 int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len);
38
39 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
40
41 struct pb_protocol_message *pb_protocol_create_message(void *ctx,
42                 enum pb_protocol_action action, int payload_len);
43
44 struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
45
46 struct device *pb_protocol_deserialise_device(void *ctx,
47                 const struct pb_protocol_message *message);
48
49 #endif /* _PB_PROTOCOL_H */