Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* action = 0x1: device add message
* payload:
* 4-byte len, id
* action = 0x1: device add message
* payload:
* 4-byte len, id
* 4-byte len, name
* 4-byte len, description
* 4-byte len, icon_file
* 4-byte len, name
* 4-byte len, description
* 4-byte len, icon_file
int pb_protocol_device_len(const struct device *dev)
{
return 4 + optional_strlen(dev->id) +
int pb_protocol_device_len(const struct device *dev)
{
return 4 + optional_strlen(dev->id) +
4 + optional_strlen(dev->name) +
4 + optional_strlen(dev->description) +
4 + optional_strlen(dev->icon_file);
4 + optional_strlen(dev->name) +
4 + optional_strlen(dev->description) +
4 + optional_strlen(dev->icon_file);
char *pos = buf;
pos += pb_protocol_serialise_string(pos, dev->id);
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);
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);
if (read_string(dev, &pos, &len, &dev->id))
goto out;
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;
if (read_string(dev, &pos, &len, &dev->name))
goto out;
#include <stdbool.h>
#include <list/list.h>
#include <stdbool.h>
#include <list/list.h>
+enum device_type {
+ DEVICE_TYPE_NETWORK,
+ DEVICE_TYPE_DISK,
+ DEVICE_TYPE_OPTICAL,
+ DEVICE_TYPE_UNKNOWN,
+};
+
struct device {
char *id;
struct device {
char *id;
char *name;
char *description;
char *icon_file;
char *name;
char *description;
char *icon_file;