+static void unserialize_header(uint8_t *buffer, struct am7xxx_header *h)
+{
+ uint8_t **buffer_iterator = &buffer;
+
+ h->packet_type = get_le32(buffer_iterator);
+ h->unknown0 = get_8(buffer_iterator);
+ h->header_data_len = get_8(buffer_iterator);
+ h->unknown2 = get_8(buffer_iterator);
+ h->unknown3 = get_8(buffer_iterator);
+ h->header_data.data.field0 = get_le32(buffer_iterator);
+ h->header_data.data.field1 = get_le32(buffer_iterator);
+ h->header_data.data.field2 = get_le32(buffer_iterator);
+ h->header_data.data.field3 = get_le32(buffer_iterator);
+}
+
+static int read_header(am7xxx_device dev, struct am7xxx_header *h)
+{
+ uint8_t *buffer;
+ int ret;
+
+ buffer = calloc(AM7XXX_HEADER_WIRE_SIZE, 1);
+ if (buffer == NULL) {
+ perror("calloc buffer");
+ return -ENOMEM;
+ }
+
+ ret = read_data(dev, buffer, AM7XXX_HEADER_WIRE_SIZE);
+ if (ret < 0)
+ goto out;
+
+ unserialize_header(buffer, h);
+
+#if DEBUG
+ printf("\n");
+ dump_header(h);
+ printf("\n");
+#endif
+
+ ret = 0;
+
+out:
+ free(buffer);
+ return ret;
+}
+