- unsigned int offset;
- uint32_t tmp;
-
- if (p == NULL || buffer == NULL)
- return -EINVAL;
-
- /* TODO: check for packet payload being NULL? */
- if (buffer->data == NULL || buffer->len < sizeof(*p))
- return -EINVAL;
-
- offset = 0;
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.packet_type));
- p->header.packet_type = le32toh(tmp);
- offset += sizeof(p->header.packet_type);
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.unknown1));
- p->header.unknown1 = le32toh(tmp);
- offset += sizeof(p->header.unknown1);
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.unknown2));
- p->header.unknown2 = le32toh(tmp);
- offset += sizeof(p->header.unknown2);
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.width));
- p->header.width = le32toh(tmp);
- offset += sizeof(p->header.width);
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.height));
- p->header.height = le32toh(tmp);
- offset += sizeof(p->header.height);
-
- memcpy(&tmp, buffer->data + offset, sizeof(p->header.payload_size));
- p->header.payload_size = le32toh(tmp);
- offset += sizeof(p->header.payload_size);
-
- /* malloc & memcpy payload of size p->header.payload_size */
-
- return 0;
-}