lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_rootlayerpdu.h
1 /******************************************************************************
2  * Copyright 2018 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************
16  * This file is a part of lwpa. For more information, go to:
17  * https://github.com/ETCLabs/lwpa
18  ******************************************************************************/
19 
20 /* rootlayerpdu.h: Functions to parse or pack a Root Layer PDU block (as
21  * defined in ANSI E1.17) and its associated preambles. */
22 #ifndef _LWPA_ROOTLAYERPDU_H_
23 #define _LWPA_ROOTLAYERPDU_H_
24 
25 #include <stddef.h>
26 #include "lwpa_int.h"
27 #include "lwpa_bool.h"
28 #include "lwpa_cid.h"
29 #include "acn_prot.h"
30 #include "lwpa_pdu.h"
31 
42 #define ACN_TCP_PREAMBLE_SIZE 16
44 #define ACN_UDP_PREAMBLE_SIZE 16
46 #define RLP_HEADER_SIZE_NORMAL_LEN 22
48 #define RLP_HEADER_SIZE_EXT_LEN 23
49 
56 #define VECTOR_ROOT_SDT ACN_PROTOCOL_SDT
57 #define VECTOR_ROOT_DRAFT_E131_DATA ACN_PROTOCOL_DRAFT_E131_DATA
58 #define VECTOR_ROOT_E131_DATA ACN_PROTOCOL_E131_DATA
59 #define VECTOR_ROOT_E131_EXTENDED ACN_PROTOCOL_E131_EXTENDED
60 #define VECTOR_ROOT_LLRP ACN_PROTOCOL_LLRP
61 #define VECTOR_ROOT_BROKER ACN_PROTOCOL_BROKER
62 #define VECTOR_ROOT_RPT ACN_PROTOCOL_RPT
63 #define VECTOR_ROOT_EPT ACN_PROTOCOL_EPT
67 typedef struct TcpPreamble
68 {
70  const uint8_t *rlp_block;
72  size_t rlp_block_len;
74 
76 typedef struct UdpPreamble
77 {
79  const uint8_t *rlp_block;
81  size_t rlp_block_len;
83 
85 typedef struct RootLayerPdu
86 {
90  uint32_t vector;
92  const uint8_t *pdata;
94  size_t datalen;
96 
97 #ifdef __cplusplus
98 extern "C" {
99 #endif
100 
101 bool parse_tcp_preamble(const uint8_t *buf, size_t buflen, TcpPreamble *preamble);
102 bool parse_udp_preamble(const uint8_t *buf, size_t buflen, UdpPreamble *preamble);
103 bool parse_root_layer_header(const uint8_t *buf, size_t buflen, RootLayerPdu *pdu, RootLayerPdu *last_pdu);
104 bool parse_root_layer_pdu(const uint8_t *buf, size_t buflen, RootLayerPdu *pdu, LwpaPdu *last_pdu);
105 
106 size_t pack_tcp_preamble(uint8_t *buf, size_t buflen, size_t rlp_block_len);
107 size_t pack_udp_preamble(uint8_t *buf, size_t buflen);
108 size_t root_layer_buf_size(const RootLayerPdu *pdu_block, size_t num_pdus);
109 size_t pack_root_layer_header(uint8_t *buf, size_t buflen, const RootLayerPdu *pdu);
110 size_t pack_root_layer_block(uint8_t *buf, size_t buflen, const RootLayerPdu *pdu_block, size_t num_pdus);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
118 #endif /* _LWPA_ROOTLAYERPDU_H_ */
bool parse_root_layer_pdu(const uint8_t *buf, size_t buflen, RootLayerPdu *pdu, LwpaPdu *last_pdu)
Parse a Root Layer PDU.
Definition: lwpa_rootlayerpdu.c:209
size_t pack_tcp_preamble(uint8_t *buf, size_t buflen, size_t rlp_block_len)
Pack an ACN TCP Preamble into a buffer.
Definition: lwpa_rootlayerpdu.c:267
size_t pack_root_layer_header(uint8_t *buf, size_t buflen, const RootLayerPdu *pdu)
Pack only the header of a Root Layer PDU block into a buffer.
Definition: lwpa_rootlayerpdu.c:318
bool parse_tcp_preamble(const uint8_t *buf, size_t buflen, TcpPreamble *preamble)
Parse an ACN TCP Preamble.
Definition: lwpa_rootlayerpdu.c:52
size_t pack_root_layer_block(uint8_t *buf, size_t buflen, const RootLayerPdu *pdu_block, size_t num_pdus)
Pack a Root Layer PDU block into a buffer.
Definition: lwpa_rootlayerpdu.c:360
struct TcpPreamble TcpPreamble
Holds the information contained in an ACN TCP Preamble.
struct UdpPreamble UdpPreamble
Holds the information contained in an ACN UDP Preamble.
size_t pack_udp_preamble(uint8_t *buf, size_t buflen)
Pack an ACN UDP Preamble into a buffer.
Definition: lwpa_rootlayerpdu.c:238
struct RootLayerPdu RootLayerPdu
Holds the information contained in an ACN Root Layer PDU.
bool parse_root_layer_header(const uint8_t *buf, size_t buflen, RootLayerPdu *pdu, RootLayerPdu *last_pdu)
Parse only the header of a Root Layer PDU.
Definition: lwpa_rootlayerpdu.c:112
bool parse_udp_preamble(const uint8_t *buf, size_t buflen, UdpPreamble *preamble)
Parse an ACN UDP Preamble.
Definition: lwpa_rootlayerpdu.c:77
size_t root_layer_buf_size(const RootLayerPdu *pdu_block, size_t num_pdus)
Get the buffer size to allocate for a Root Layer PDU block.
Definition: lwpa_rootlayerpdu.c:291
The CID type.
Definition: lwpa_cid.h:55
Holds state data used when parsing multiple PDUs in a PDU block.
Definition: lwpa_pdu.h:116
Holds the information contained in an ACN Root Layer PDU.
Definition: lwpa_rootlayerpdu.h:86
const uint8_t * pdata
A pointer to the Data segment of this PDU.
Definition: lwpa_rootlayerpdu.h:92
size_t datalen
The length of the Data segment of this PDU.
Definition: lwpa_rootlayerpdu.h:94
uint32_t vector
The Vector indicates the type of data contained in the Data segment.
Definition: lwpa_rootlayerpdu.h:90
LwpaCid sender_cid
The CID of the component that sent this Root Layer PDU.
Definition: lwpa_rootlayerpdu.h:88
Holds the information contained in an ACN TCP Preamble.
Definition: lwpa_rootlayerpdu.h:68
const uint8_t * rlp_block
Pointer to the beginning of the Root Layer PDU block.
Definition: lwpa_rootlayerpdu.h:70
size_t rlp_block_len
Length of the Root Layer PDU block.
Definition: lwpa_rootlayerpdu.h:72
Holds the information contained in an ACN UDP Preamble.
Definition: lwpa_rootlayerpdu.h:77
const uint8_t * rlp_block
Pointer to the beginning of the Root Layer PDU block.
Definition: lwpa_rootlayerpdu.h:79
size_t rlp_block_len
Length of the Root Layer PDU block.
Definition: lwpa_rootlayerpdu.h:81