diff options
Diffstat (limited to 'src/lib/frct_pci.c')
-rw-r--r-- | src/lib/frct_pci.c | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/src/lib/frct_pci.c b/src/lib/frct_pci.c index 5ee14829..115a3eb9 100644 --- a/src/lib/frct_pci.c +++ b/src/lib/frct_pci.c @@ -24,18 +24,25 @@ #include <ouroboros/hash.h> #include <ouroboros/errno.h> -#define OUROBOROS_PREFIX "frct-pci" -#include <ouroboros/logs.h> - #include <assert.h> #include <string.h> -#define TYPE_SIZE 1 -#define SEQNO_SIZE 8 -#define FLAGS_SIZE 1 +#define TYPE_SIZE 1 +#define SEQNO_SIZE 8 +#define FLAGS_SIZE 1 +#define CONF_FLAGS_SIZE 1 +#define BASE_SIZE TYPE_SIZE + FLAGS_SIZE + SEQNO_SIZE +#define CONFIG_SIZE CONF_FLAGS_SIZE + +static size_t get_head_len(struct frct_pci * pci) +{ + size_t len = BASE_SIZE; + + if (pci->type & PDU_TYPE_CONFIG) + len += CONFIG_SIZE; -/* FIXME: Head size will differ on type */ -#define HEAD_SIZE TYPE_SIZE + FLAGS_SIZE + SEQNO_SIZE + return len; +} int frct_pci_ser(struct shm_du_buff * sdb, struct frct_pci * pci, @@ -43,22 +50,34 @@ int frct_pci_ser(struct shm_du_buff * sdb, { uint8_t * head; uint8_t * tail; + size_t len; + size_t offset = 0; assert(sdb); assert(pci); - head = shm_du_buff_head_alloc(sdb, HEAD_SIZE); + len = get_head_len(pci); + + head = shm_du_buff_head_alloc(sdb, len); if (head == NULL) return -EPERM; memcpy(head, &pci->type, TYPE_SIZE); - memcpy(head + TYPE_SIZE, &pci->flags, FLAGS_SIZE); - memcpy(head + TYPE_SIZE + FLAGS_SIZE, &pci->seqno, SEQNO_SIZE); + offset += TYPE_SIZE; + memcpy(head + offset, &pci->flags, FLAGS_SIZE); + offset += FLAGS_SIZE; + memcpy(head + offset, &pci->seqno, SEQNO_SIZE); + offset += SEQNO_SIZE; + + if (pci->type & PDU_TYPE_CONFIG) { + memcpy(head + offset, &pci->conf_flags, CONF_FLAGS_SIZE); + offset += CONF_FLAGS_SIZE; + } if (error_check) { tail = shm_du_buff_tail_alloc(sdb, hash_len(HASH_CRC32)); if (tail == NULL) { - shm_du_buff_head_release(sdb, HEAD_SIZE); + shm_du_buff_head_release(sdb, len); return -EPERM; } @@ -77,16 +96,25 @@ int frct_pci_des(struct shm_du_buff * sdb, uint8_t * tail; uint32_t crc; uint32_t crc2; + size_t offset = 0; assert(sdb); assert(pci); head = shm_du_buff_head(sdb); - /* FIXME: Depending on the type a different deserialization */ + /* Depending on the type a different deserialization. */ memcpy(&pci->type, head, TYPE_SIZE); - memcpy(&pci->flags, head + TYPE_SIZE, FLAGS_SIZE); - memcpy(&pci->seqno, head + TYPE_SIZE + FLAGS_SIZE, SEQNO_SIZE); + offset += TYPE_SIZE; + memcpy(&pci->flags, head + offset, FLAGS_SIZE); + offset += FLAGS_SIZE; + memcpy(&pci->seqno, head + offset, SEQNO_SIZE); + offset += SEQNO_SIZE; + + if (pci->type & PDU_TYPE_CONFIG) { + memcpy(&pci->conf_flags, head + offset, CONF_FLAGS_SIZE); + offset += CONF_FLAGS_SIZE; + } if (error_check) { tail = shm_du_buff_tail(sdb); @@ -99,14 +127,14 @@ int frct_pci_des(struct shm_du_buff * sdb, memcpy(&crc2, tail - hash_len(HASH_CRC32), hash_len(HASH_CRC32)); - /* Corrupted SDU */ + /* Corrupted SDU. */ if (crc != crc2) return -1; shm_du_buff_tail_release(sdb, hash_len(HASH_CRC32)); } - shm_du_buff_head_release(sdb, HEAD_SIZE); + shm_du_buff_head_release(sdb, get_head_len(pci)); return 0; } |