summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@intel.com>2018-01-19 10:35:45 -0800
committerAndre Guedes <andre.guedes@intel.com>2018-01-26 18:00:09 -0800
commite6bd6c11453005069d1cc59a8a9d522ce65d830a (patch)
tree87c42b27d35ff4967eea79218e4f2c02cd7fcaf1
parentd1ee5ba8a03a578c0b1aace651bbd84e0fc88d27 (diff)
downloadOpen-AVB-e6bd6c11453005069d1cc59a8a9d522ce65d830a.tar.gz
AVTP library initial commit
This patch adds the initial infrastructure to bootstrap the libavtp project. The goal of libavtp is to provide a standalone library that implements AVTP packetization so applications and AVB frameworks could use it instead of having their own AVTP packetization implementation.
-rw-r--r--lib/libavtp/LICENSE24
-rw-r--r--lib/libavtp/README.md32
-rw-r--r--lib/libavtp/include/avtp.h97
-rw-r--r--lib/libavtp/meson.build15
-rw-r--r--lib/libavtp/src/avtp.c98
-rw-r--r--lib/libavtp/src/util.h45
6 files changed, 311 insertions, 0 deletions
diff --git a/lib/libavtp/LICENSE b/lib/libavtp/LICENSE
new file mode 100644
index 00000000..f0eb281f
--- /dev/null
+++ b/lib/libavtp/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2017, Intel Corporation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/lib/libavtp/README.md b/lib/libavtp/README.md
new file mode 100644
index 00000000..70eb2134
--- /dev/null
+++ b/lib/libavtp/README.md
@@ -0,0 +1,32 @@
+# About
+
+Open source implementation of Audio Video Transport Protocol (AVTP) specified
+in IEEE 1722-2016 spec.
+
+Libavtp is under BSD License. For more information see LICENSE file.
+
+# Build
+
+Before building libavtp make sure you have all the required software installed
+in your system. Below are the requirements and their tested versions:
+
+* Meson >= 0.43
+* Ninja >= 1.8.2
+
+The first step to build libavtp is to generate the build system files.
+
+```
+$ meson build
+```
+
+Then build libavtp by running the following command. The building artifacts
+will be created under the build/ in the top-level directory.
+
+```
+$ ninja -C build
+```
+
+To install libavtp on your system run:
+```
+$ sudo ninja -C build install
+```
diff --git a/lib/libavtp/include/avtp.h b/lib/libavtp/include/avtp.h
new file mode 100644
index 00000000..5322f772
--- /dev/null
+++ b/lib/libavtp/include/avtp.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2017, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <errno.h>
+#include <stdint.h>
+
+/* AVTP subtypes values. For further information refer to section 4.4.3.2 from
+ * IEEE 1722-2016 spec.
+ */
+#define AVTP_SUBTYPE_61883_IIDC 0x00
+#define AVTP_SUBTYPE_MMA_STREAM 0x01
+#define AVTP_SUBTYPE_AAF 0x02
+#define AVTP_SUBTYPE_CVF 0x03
+#define AVTP_SUBTYPE_CRF 0x04
+#define AVTP_SUBTYPE_TSCF 0x05
+#define AVTP_SUBTYPE_SVF 0x06
+#define AVTP_SUBTYPE_RVF 0x07
+#define AVTP_SUBTYPE_AEF_CONTINUOUS 0x6E
+#define AVTP_SUBTYPE_VSF_STREAM 0x6F
+#define AVTP_SUBTYPE_EF_STREAM 0x7F
+#define AVTP_SUBTYPE_NTSCF 0x82
+#define AVTP_SUBTYPE_ESCF 0xEC
+#define AVTP_SUBTYPE_EECF 0xED
+#define AVTP_SUBTYPE_AEF_DISCRETE 0xEE
+#define AVTP_SUBTYPE_ADP 0xFA
+#define AVTP_SUBTYPE_AECP 0xFB
+#define AVTP_SUBTYPE_ACMP 0xFC
+#define AVTP_SUBTYPE_MAAP 0xFE
+#define AVTP_SUBTYPE_EF_CONTROL 0xFF
+
+/* XXX: Fields from PDU structs should not be read or written directly since
+ * they are encoded in Network order which may be different from the Host
+ * order (see section 3.4.1 from IEEE 1722-2016 spec for further information).
+ *
+ * Any read or write operation with PDU structs should be done via getter and
+ * setter APIs which handle byte order conversion.
+ */
+struct avtp_common_pdu {
+ uint32_t subtype_data;
+ uint8_t pdu_specific[0];
+} __attribute__ ((__packed__));
+
+enum avtp_field {
+ AVTP_FIELD_SUBTYPE,
+ AVTP_FIELD_VERSION,
+ AVTP_FIELD_MAX,
+};
+
+/* Get value from Common AVTPDU field.
+ * @pdu: Pointer to PDU struct.
+ * @field: PDU field to be retrieved.
+ * @val: Pointer to variable which the retrieved value should be saved.
+ *
+ * Returns:
+ * 0: Success.
+ * -EINVAL: If any argument is invalid.
+ */
+int avtp_pdu_get(const struct avtp_common_pdu *pdu, enum avtp_field field,
+ uint32_t *val);
+
+/* Set value from Common AVTPDU field.
+ * @pdu: Pointer to PDU struct.
+ * @field: PDU field to be set.
+ * @val: Value to be set.
+ *
+ * Returns:
+ * 0: Success.
+ * -EINVAL: If any argument is invalid.
+ */
+int avtp_pdu_set(struct avtp_common_pdu *pdu, enum avtp_field field,
+ uint32_t val);
diff --git a/lib/libavtp/meson.build b/lib/libavtp/meson.build
new file mode 100644
index 00000000..f5d29815
--- /dev/null
+++ b/lib/libavtp/meson.build
@@ -0,0 +1,15 @@
+project(
+ 'libavtp',
+ 'c',
+ version: '0.1',
+ license: 'BSD-3-Clause',
+)
+
+library(
+ 'avtp',
+ 'src/avtp.c',
+ include_directories: include_directories('include'),
+ install: true,
+)
+
+install_headers('include/avtp.h')
diff --git a/lib/libavtp/src/avtp.c b/lib/libavtp/src/avtp.c
new file mode 100644
index 00000000..e3132457
--- /dev/null
+++ b/lib/libavtp/src/avtp.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2017, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <arpa/inet.h>
+#include <stddef.h>
+
+#include "avtp.h"
+#include "util.h"
+
+#define SHIFT_SUBTYPE (31 - 7)
+#define SHIFT_VERSION (31 - 11)
+
+#define MASK_SUBTYPE (BITMASK(8) << SHIFT_SUBTYPE)
+#define MASK_VERSION (BITMASK(3) << SHIFT_VERSION)
+
+int avtp_pdu_get(const struct avtp_common_pdu *pdu, enum avtp_field field,
+ uint32_t *val)
+{
+ uint32_t bitmap, mask;
+ uint8_t shift;
+
+ if (!pdu || !val)
+ return -EINVAL;
+
+ switch (field) {
+ case AVTP_FIELD_SUBTYPE:
+ mask = MASK_SUBTYPE;
+ shift = SHIFT_SUBTYPE;
+ break;
+ case AVTP_FIELD_VERSION:
+ mask = MASK_VERSION;
+ shift = SHIFT_VERSION;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ bitmap = ntohl(pdu->subtype_data);
+
+ *val = BITMAP_GET_VALUE(bitmap, mask, shift);
+
+ return 0;
+}
+
+int avtp_pdu_set(struct avtp_common_pdu *pdu, enum avtp_field field,
+ uint32_t value)
+{
+ uint32_t bitmap, mask;
+ uint8_t shift;
+
+ if (!pdu)
+ return -EINVAL;
+
+ switch (field) {
+ case AVTP_FIELD_SUBTYPE:
+ mask = MASK_SUBTYPE;
+ shift = SHIFT_SUBTYPE;
+ break;
+ case AVTP_FIELD_VERSION:
+ mask = MASK_VERSION;
+ shift = SHIFT_VERSION;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ bitmap = ntohl(pdu->subtype_data);
+
+ BITMAP_SET_VALUE(bitmap, value, mask, shift);
+
+ pdu->subtype_data = htonl(bitmap);
+
+ return 0;
+}
diff --git a/lib/libavtp/src/util.h b/lib/libavtp/src/util.h
new file mode 100644
index 00000000..2a6ec3b0
--- /dev/null
+++ b/lib/libavtp/src/util.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#define BIT(n) (1UL << n)
+
+#define BITMASK(len) (BIT(len) - 1)
+
+/* Get value from the bits within 'bitmap' represented by 'mask'. The 'mask'
+ * parameter must be a continuous bit mask (e.g. 0b00111000). This macro
+ * doesn't work with non-continuous bit masks (e.g. 0b00101001).
+ */
+#define BITMAP_GET_VALUE(bitmap, mask, shift) \
+ ((bitmap & mask) >> shift)
+
+/* Set the value 'val' in the 'bitmap' variable at the position represented by
+ * 'mask'.
+ */
+#define BITMAP_SET_VALUE(bitmap, val, mask, shift) \
+ (bitmap = (bitmap & ~mask) | ((val << shift) & mask))