static struct blob_buf conf;
struct blob_attr **messages = NULL;
+int *message_len;
int n_messages = 0;
static struct avl_tree devices;
return 0;
}
-static bool convert_message(struct blob_attr *attr)
+static int convert_message(struct blob_attr *attr)
{
char *data;
int len;
- if (!attr)
- return true;
-
data = blobmsg_data(attr);
len = strlen(data);
if (len % 2)
- return false;
+ return -1;
+
+ if (hexstr2bin(data, data, len / 2))
+ return -1;
- return !hexstr2bin(data, data, len / 2);
+ return len / 2;
}
static int parse_config(void)
n_messages++;
messages = calloc(n_messages, sizeof(*messages));
+ message_len = calloc(n_messages, sizeof(*message_len));
n_messages = 0;
blobmsg_for_each_attr(cur, tb[CONF_MESSAGES], rem) {
- if (!convert_message(cur)) {
+ int len = convert_message(cur);
+
+ if (len < 0) {
fprintf(stderr, "Invalid data in message %d\n", n_messages);
return -1;
}
+
+ message_len[n_messages] = len;
messages[n_messages++] = cur;
}
int interface;
int msg_endpoint;
int response_endpoint;
+ bool need_response;
char idstr[10];
char mfg[128], prod[128], serial[128];
};
extern struct blob_attr **messages;
+extern int *message_len;
extern int n_messages;
void handle_switch(struct usbdev_data *data);