diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-09-18 11:03:17 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-09-18 11:43:27 +0800 |
commit | 7b793150f96a6fe6033ac1390a663b1b62be2df6 (patch) | |
tree | e5969cfcdaacbb001544e02089444c2be13b4a7e /lib/pb-protocol | |
parent | e17f6c7e1bcf7a5f67d0f1a51c39af0d8ab104d4 (diff) | |
download | petitboot-7b793150f96a6fe6033ac1390a663b1b62be2df6.zip petitboot-7b793150f96a6fe6033ac1390a663b1b62be2df6.tar.gz |
types: Add device_type to struct device
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/pb-protocol')
-rw-r--r-- | lib/pb-protocol/pb-protocol.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index bcc7230..681b250 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -22,6 +22,7 @@ * action = 0x1: device add message * payload: * 4-byte len, id + * 1-byte type * 4-byte len, name * 4-byte len, description * 4-byte len, icon_file @@ -166,6 +167,7 @@ static int optional_strlen(const char *str) int pb_protocol_device_len(const struct device *dev) { return 4 + optional_strlen(dev->id) + + sizeof(dev->type) + 4 + optional_strlen(dev->name) + 4 + optional_strlen(dev->description) + 4 + optional_strlen(dev->icon_file); @@ -209,6 +211,8 @@ int pb_protocol_serialise_device(const struct device *dev, char *pos = buf; pos += pb_protocol_serialise_string(pos, dev->id); + *(enum device_type *)pos = dev->type; + pos += sizeof(enum device_type); pos += pb_protocol_serialise_string(pos, dev->name); pos += pb_protocol_serialise_string(pos, dev->description); pos += pb_protocol_serialise_string(pos, dev->icon_file); @@ -384,6 +388,12 @@ int pb_protocol_deserialise_device(struct device *dev, if (read_string(dev, &pos, &len, &dev->id)) goto out; + if (len < sizeof(enum device_type)) + goto out; + dev->type = *(enum device_type *)(pos); + pos += sizeof(enum device_type); + len -= sizeof(enum device_type); + if (read_string(dev, &pos, &len, &dev->name)) goto out; |