From 35c43358a110758090b48dd18628bb285ffddfc6 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 8 Nov 2017 19:25:48 +0100 Subject: lib: Use packed struct for FRCT header access This replaces the variable FRCT header with a packed struct, which significantly simplifies the implementation. The shm_du_buff calls to release the head/tail are updated to return a pointer to the original head or the new tail (in symmetry to the alloc calls, which return a pointer to the new head and old tail), so that it immediately points to the structure that is needed. The frct_pci sources are removed and frct is now fully in the frct.c source file. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/frct_pci.c | 129 ----------------------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 src/lib/frct_pci.c (limited to 'src/lib/frct_pci.c') diff --git a/src/lib/frct_pci.c b/src/lib/frct_pci.c deleted file mode 100644 index 509cc8e2..00000000 --- a/src/lib/frct_pci.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Protocol Control Information of FRCT - * - * Dimitri Staessens - * Sander Vrijders - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -#include -#include - -#include "frct_pci.h" - -#include -#include - -#define TYPE_SIZE 1 -#define FLAGS_SIZE 1 -#define SEQNO_SIZE 8 -#define CONF_FLAGS_SIZE 2 - -#define BASE_SIZE TYPE_SIZE + FLAGS_SIZE + SEQNO_SIZE - -#define head_len(pci) (pci->type & PDU_TYPE_CONFIG ? \ - BASE_SIZE + CONF_FLAGS_SIZE : BASE_SIZE) - -int frct_pci_ser(struct shm_du_buff * sdb, - struct frct_pci * pci, - bool error_check) -{ - uint8_t * head; - uint8_t * tail; - size_t offset = 0; - - assert(sdb); - assert(pci); - - head = shm_du_buff_head_alloc(sdb, head_len(pci)); - if (head == NULL) - return -EPERM; - - memcpy(head, &pci->type, TYPE_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->cflags, 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_len(pci)); - return -EPERM; - } - - *((uint32_t *) tail) = 0; - mem_hash(HASH_CRC32, (uint32_t *) tail, head, tail - head); - } - - return 0; -} - -int frct_pci_des(struct shm_du_buff * sdb, - struct frct_pci * pci, - bool error_check) -{ - uint8_t * head; - uint8_t * tail; - uint32_t crc; - uint32_t crc2; - size_t offset = 0; - - assert(sdb); - assert(pci); - - head = shm_du_buff_head(sdb); - - if (error_check) { - tail = shm_du_buff_tail(sdb); - - mem_hash(HASH_CRC32, &crc, head, - tail - head - hash_len(HASH_CRC32)); - - memcpy(&crc2, tail - hash_len(HASH_CRC32), - hash_len(HASH_CRC32)); - - /* Corrupted SDU. */ - if (crc != crc2) - return -1; - - shm_du_buff_tail_release(sdb, hash_len(HASH_CRC32)); - } - - /* Depending on the type a different deserialization. */ - memcpy(&pci->type, head, TYPE_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->cflags, head + offset, CONF_FLAGS_SIZE); - /* offset += CONF_FLAGS_SIZE; */ - } - - shm_du_buff_head_release(sdb, head_len(pci)); - - return 0; -} -- cgit v1.2.3