| 1 |
/* |
| 2 |
* Copyright (c) 2019, Intel Corporation |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are met: |
| 6 |
* |
| 7 |
* * Redistributions of source code must retain the above copyright notice, |
| 8 |
* this list of conditions and the following disclaimer. |
| 9 |
* * Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* * Neither the name of Intel Corporation nor the names of its contributors |
| 13 |
* may be used to endorse or promote products derived from this software |
| 14 |
* without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#pragma once |
| 29 |
|
| 30 |
#include <errno.h> |
| 31 |
#include <stdint.h> |
| 32 |
|
| 33 |
#ifdef __cplusplus |
| 34 |
extern "C" { |
| 35 |
#endif |
| 36 |
|
| 37 |
#define AVTP_IECIIDC_TAG_NO_CIP 0x00 |
| 38 |
#define AVTP_IECIIDC_TAG_CIP 0x01 |
| 39 |
|
| 40 |
enum avtp_ieciidc_field { |
| 41 |
AVTP_IECIIDC_FIELD_SV, |
| 42 |
AVTP_IECIIDC_FIELD_MR, |
| 43 |
AVTP_IECIIDC_FIELD_TV, |
| 44 |
AVTP_IECIIDC_FIELD_SEQ_NUM, |
| 45 |
AVTP_IECIIDC_FIELD_TU, |
| 46 |
AVTP_IECIIDC_FIELD_STREAM_ID, |
| 47 |
AVTP_IECIIDC_FIELD_TIMESTAMP, |
| 48 |
AVTP_IECIIDC_FIELD_STREAM_DATA_LEN, |
| 49 |
AVTP_IECIIDC_FIELD_GV, |
| 50 |
AVTP_IECIIDC_FIELD_GATEWAY_INFO, |
| 51 |
AVTP_IECIIDC_FIELD_TAG, |
| 52 |
AVTP_IECIIDC_FIELD_CHANNEL, |
| 53 |
AVTP_IECIIDC_FIELD_TCODE, |
| 54 |
AVTP_IECIIDC_FIELD_SY, |
| 55 |
AVTP_IECIIDC_FIELD_CIP_QI_1, |
| 56 |
AVTP_IECIIDC_FIELD_CIP_QI_2, |
| 57 |
AVTP_IECIIDC_FIELD_CIP_SID, |
| 58 |
AVTP_IECIIDC_FIELD_CIP_DBS, |
| 59 |
AVTP_IECIIDC_FIELD_CIP_FN, |
| 60 |
AVTP_IECIIDC_FIELD_CIP_QPC, |
| 61 |
AVTP_IECIIDC_FIELD_CIP_SPH, |
| 62 |
AVTP_IECIIDC_FIELD_CIP_DBC, |
| 63 |
AVTP_IECIIDC_FIELD_CIP_FMT, |
| 64 |
AVTP_IECIIDC_FIELD_CIP_SYT, |
| 65 |
|
| 66 |
/* Fields defined below are the FDF - Format Dependent Field - fields. |
| 67 |
* As they are poorly described in the IEEE 1722 - it usually refers to |
| 68 |
* the IEC 61883-1, which in turn refers to each relevant IEC 61883 |
| 69 |
* part, this comment is an attempt to summarize the description of |
| 70 |
* those fields, as described in IEC 61883. |
| 71 |
* |
| 72 |
* Note that FDF is the one defined on Figure 23 of IEEE 1722-2016, and |
| 73 |
* FDF_3 is the one with 3 octets, seen on Figure 24 of the same |
| 74 |
* standard. |
| 75 |
* |
| 76 |
* - IEC 61883-4 uses FDF_3, with fields: |
| 77 |
* - TSF (Bit 0) |
| 78 |
* |
| 79 |
* - IEC 61883-6 uses FDF, with fields: |
| 80 |
* - EVT (Bits 2-3) |
| 81 |
* - SFC (Bits 5-7) |
| 82 |
* - N (Bit 4) |
| 83 |
* - NO-DATA (All 8 bits set to 1) |
| 84 |
* |
| 85 |
* - IEC 61883-7 uses FDF_3, with fields: |
| 86 |
* - TSF (Bit 0) |
| 87 |
* |
| 88 |
* - IEC 61883-8 uses FDF, with fields: |
| 89 |
* - ND (Bit 0) |
| 90 |
*/ |
| 91 |
AVTP_IECIIDC_FIELD_CIP_TSF, |
| 92 |
AVTP_IECIIDC_FIELD_CIP_EVT, |
| 93 |
AVTP_IECIIDC_FIELD_CIP_SFC, |
| 94 |
AVTP_IECIIDC_FIELD_CIP_N, |
| 95 |
AVTP_IECIIDC_FIELD_CIP_ND, |
| 96 |
AVTP_IECIIDC_FIELD_CIP_NO_DATA, |
| 97 |
AVTP_IECIIDC_FIELD_MAX, |
| 98 |
}; |
| 99 |
|
| 100 |
struct avtp_ieciidc_cip_payload { |
| 101 |
uint32_t cip_1; |
| 102 |
uint32_t cip_2; |
| 103 |
uint8_t cip_data_payload[0]; |
| 104 |
}; |
| 105 |
|
| 106 |
struct avtp_ieciidc_cip_source_packet { |
| 107 |
uint32_t avtp_source_packet_header_timestamp; |
| 108 |
uint8_t cip_with_sph_payload[0]; |
| 109 |
}; |
| 110 |
|
| 111 |
/* Get value from IEC 61883/IIDC AVTPDU field. |
| 112 |
* @pdu: Pointer to PDU struct. |
| 113 |
* @field: PDU field to be retrieved. |
| 114 |
* @val: Pointer to variable which the retrieved value should be saved. |
| 115 |
* |
| 116 |
* Returns: |
| 117 |
* 0: Success. |
| 118 |
* -EINVAL: If any argument is invalid. |
| 119 |
*/ |
| 120 |
int avtp_ieciidc_pdu_get(const struct avtp_stream_pdu *pdu, |
| 121 |
enum avtp_ieciidc_field field, uint64_t *val); |
| 122 |
|
| 123 |
/* Set value from IEC 61883/IIDC AVTPDU field. |
| 124 |
* @pdu: Pointer to PDU struct. |
| 125 |
* @field: PDU field to be set. |
| 126 |
* @val: Value to be set. |
| 127 |
* |
| 128 |
* Returns: |
| 129 |
* 0: Success. |
| 130 |
* -EINVAL: If any argument is invalid. |
| 131 |
*/ |
| 132 |
int avtp_ieciidc_pdu_set(struct avtp_stream_pdu *pdu, |
| 133 |
enum avtp_ieciidc_field field, uint64_t val); |
| 134 |
|
| 135 |
/* Initialize IEC 61883/IIDC AVTPDU. The following fields are pre-initialised: |
| 136 |
* 'subtype' -> AVTP_SUBTYPE_61883_IIDC |
| 137 |
* 'sv' -> 0x01 |
| 138 |
* 'tcode' -> 0x0A |
| 139 |
* 'tag' -> tag informed on parameter |
| 140 |
* All other fields are set to zero. |
| 141 |
* @pdu: Pointer to PDU struct. |
| 142 |
* @tag: Value of AVTP_IECIIDC_FIELD_TAG. |
| 143 |
* |
| 144 |
* Return values: |
| 145 |
* 0: Success. |
| 146 |
* -EINVAL: If any argument is invalid. |
| 147 |
*/ |
| 148 |
int avtp_ieciidc_pdu_init(struct avtp_stream_pdu *pdu, uint8_t tag); |
| 149 |
|
| 150 |
#ifdef __cplusplus |
| 151 |
} |
| 152 |
#endif |