1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
20 * @brief This file provides the implementation for Transport lyaer (eCPRI) API.
22 * @file xran_transport.c
23 * @ingroup group_lte_source_xran
24 * @author Intel Corporation
30 #include <rte_common.h>
31 #include <rte_config.h>
33 #include "xran_fh_o_du.h"
34 #include "xran_common.h"
35 #include "xran_transport.h"
36 #include "xran_pkt_cp.h"
37 #include "xran_cp_api.h"
38 #include "xran_up_api.h"
39 #include "xran_printf.h"
43 * @brief return eCPRI header size without eCPRI common header
47 * @return the size of eCPRI header without common header
49 int xran_get_ecpri_hdr_size(void)
51 return(sizeof(struct xran_ecpri_hdr) - sizeof(struct xran_ecpri_cmn_hdr));
55 * @brief Compose ecpriRtcid/ecpriPcid
59 * @param CU_Port_ID CU Port ID
60 * @param BanbSector_ID Band Sector ID
61 * @param CC_ID Component Carrier ID
62 * @param Ant_ID RU Port ID (antenna ID)
63 * @return uint16_t composed ecpriRtcid/ecpriPcid (network byte order)
65 uint16_t xran_compose_cid(uint8_t CU_Port_ID, uint8_t BandSector_ID, uint8_t CC_ID, uint8_t Ant_ID)
68 struct xran_eaxcid_config *conf;
70 conf = xran_get_conf_eAxC(NULL);
72 cid = ((CU_Port_ID << conf->bit_cuPortId) & conf->mask_cuPortId)
73 | ((BandSector_ID << conf->bit_bandSectorId) & conf->mask_bandSectorId)
74 | ((CC_ID << conf->bit_ccId) & conf->mask_ccId)
75 | ((Ant_ID << conf->bit_ruPortId) & conf->mask_ruPortId);
77 return (rte_cpu_to_be_16(cid));
81 * @brief Decompose ecpriRtcid/ecpriPcid
85 * @param cid composed ecpriRtcid/ecpriPcid (network byte order)
86 * @param result the pointer of the structure to store decomposed values
89 void xran_decompose_cid(uint16_t cid, struct xran_eaxc_info *result)
91 struct xran_eaxcid_config *conf;
93 conf = xran_get_conf_eAxC(NULL);
94 cid = rte_be_to_cpu_16(cid);
96 result->cuPortId = (cid&conf->mask_cuPortId) >> conf->bit_cuPortId;
97 result->bandSectorId = (cid&conf->mask_bandSectorId) >> conf->bit_bandSectorId;
98 result->ccId = (cid&conf->mask_ccId) >> conf->bit_ccId;
99 result->ruPortId = (cid&conf->mask_ruPortId) >> conf->bit_ruPortId;
105 * @brief modify the payload size of eCPRI header in xRAN packet
109 * @param mbuf Initialized rte_mbuf packet which has eCPRI header already
110 * @param size payload size to be updated
113 inline void xran_update_ecpri_payload_size(struct rte_mbuf *mbuf, int size)
115 struct xran_ecpri_hdr *ecpri_hdr;
117 ecpri_hdr = rte_pktmbuf_mtod(mbuf, struct xran_ecpri_hdr *);
119 ecpri_hdr->cmnhdr.ecpri_payl_size = rte_cpu_to_be_16(size);
124 * @brief Build ECPRI header and returns added length
129 * The pointer of the packet buffer to be parsed
131 * Component Carrier ID for this C-Plane message
133 * Antenna ID(RU Port ID) for this C-Plane message
135 * Sequence ID for this C-Plane message
137 * The pointer to ECPRI header
139 * added payload size on success
140 * XRAN_STATUS_RESOURCE if failed to allocate the space to packet buffer
142 int xran_build_ecpri_hdr(struct rte_mbuf *mbuf,
143 uint8_t CC_ID, uint8_t Ant_ID,
145 struct xran_ecpri_hdr **ecpri_hdr)
148 struct xran_ecpri_hdr *tmp;
151 tmp = (struct xran_ecpri_hdr *)rte_pktmbuf_append(mbuf, sizeof(struct xran_ecpri_hdr));
152 if(unlikely(tmp == NULL)) {
153 print_err("Fail to allocate the space for eCPRI hedaer!");
154 return (XRAN_STATUS_RESOURCE);
157 /* Fill common header */
158 tmp->cmnhdr.ecpri_ver = XRAN_ECPRI_VER;
159 tmp->cmnhdr.ecpri_resv = 0; // should be zero
160 tmp->cmnhdr.ecpri_concat = 0;
161 tmp->cmnhdr.ecpri_mesg_type = ECPRI_RT_CONTROL_DATA;
162 tmp->ecpri_xtc_id = xran_compose_cid(0, 0, CC_ID, Ant_ID);
164 /* TODO: Transport layer fragmentation is not supported */
165 tmp->ecpri_seq_id.seq_id = seq_id;
166 tmp->ecpri_seq_id.sub_seq_id = 0;
167 tmp->ecpri_seq_id.e_bit = 1;
169 /* Starts with eCPRI header size */
170 payloadlen = xran_get_ecpri_hdr_size();
178 * @brief Parse ECPRI header
183 * The pointer of the packet buffer to be parsed
185 * The pointer to ECPRI header
187 * The pointer of sturcture to store the information from header
189 * XRAN_STATUS_SUCCESS on success
190 * XRAN_STATUS_INVALID_PACKET if failed to parse the packet
192 int xran_parse_ecpri_hdr(struct rte_mbuf *mbuf,
193 struct xran_ecpri_hdr **ecpri_hdr,
194 struct xran_recv_packet_info *pkt_info)
199 *ecpri_hdr = rte_pktmbuf_mtod(mbuf, void *);
200 if(*ecpri_hdr == NULL) {
201 print_err("Invalid packet - eCPRI hedaer!");
202 return (XRAN_STATUS_INVALID_PACKET);
205 /* Process eCPRI header */
206 ret = XRAN_STATUS_SUCCESS;
207 if((*ecpri_hdr)->cmnhdr.ecpri_ver != XRAN_ECPRI_VER) {
208 print_err("Invalid eCPRI version - %d", (*ecpri_hdr)->cmnhdr.ecpri_ver);
209 ret = XRAN_STATUS_INVALID_PACKET;
211 if((*ecpri_hdr)->cmnhdr.ecpri_resv != 0) {
212 print_err("Invalid reserved field - %d", (*ecpri_hdr)->cmnhdr.ecpri_resv);
213 ret = XRAN_STATUS_INVALID_PACKET;
216 if(pkt_info != NULL) {
217 /* store the information from header */
218 pkt_info->ecpri_version = (*ecpri_hdr)->cmnhdr.ecpri_ver;
219 pkt_info->msg_type = (enum ecpri_msg_type)(*ecpri_hdr)->cmnhdr.ecpri_mesg_type;
220 pkt_info->payload_len = rte_be_to_cpu_16((*ecpri_hdr)->cmnhdr.ecpri_payl_size);
222 pkt_info->seq_id = (*ecpri_hdr)->ecpri_seq_id.seq_id;
223 pkt_info->subseq_id = (*ecpri_hdr)->ecpri_seq_id.sub_seq_id;
224 pkt_info->ebit = (*ecpri_hdr)->ecpri_seq_id.e_bit;
225 xran_decompose_cid((*ecpri_hdr)->ecpri_xtc_id, &(pkt_info->eaxc));