3 * Copyright 2019 AT&T Intellectual Property
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include "x2ap_generate_messages.h"
26 #include "x2ap_asn_codec.h"
27 #include "e2sim_defs.h"
29 int asn1_xer_print = 0;
30 int MAX_XML_BUFFER = 10000;
32 void x2ap_fetch_pdu_from_XML(X2AP_PDU_t **pdu, char *filename)
35 uint8_t buf[MAX_XML_BUFFER];
42 char *work_dir = getenv(WORKDIR_ENV);
44 strcpy(XML_path, work_dir);
45 strcat(XML_path, "/src/X2AP/MESSAGES/XML/");
46 strcat(XML_path, filename);
48 //printf("Generate X2AP PDU from XML file: %s\n", XML_path);
50 f = fopen(XML_path, "r");
52 size = fread(buf, 1, sizeof(buf), f);
53 if(size == 0 || size == sizeof(buf))
55 fprintf(stderr, "%s: Too large input\n", XML_path);
61 //printf("Decode the XER buffer\n");
62 rval = xer_decode(NULL, &asn_DEF_X2AP_PDU, (void **)pdu, buf, size);
63 assert(rval.code == RC_OK);
67 uint32_t x2ap_generate_x2_setup_request(uint8_t **buffer)
70 pdu = (X2AP_PDU_t *)calloc(1, sizeof(X2AP_PDU_t));
74 char *XML_file = "sample_x2_setup_request.xml";
76 x2ap_fetch_pdu_from_XML(&pdu, XML_file);
79 xer_fprint(stdout, &asn_DEF_X2AP_PDU, (void *)pdu);
81 if(X2AP_ASN_encode(pdu, buffer, &len) < 0)
83 fprintf(stderr, "Failed to APER encode X2 Setup Request\n");
91 uint32_t x2ap_generate_x2_setup_response(uint8_t **buffer)
94 pdu = (X2AP_PDU_t *)calloc(1, sizeof(X2AP_PDU_t));
98 char *XML_file = "sample_x2_setup_response.xml";
100 x2ap_fetch_pdu_from_XML(&pdu, XML_file);
103 xer_fprint(stdout, &asn_DEF_X2AP_PDU, (void *)pdu);
105 if(X2AP_ASN_encode(pdu, buffer, &len) < 0)
107 fprintf(stderr, "Failed to APER encode X2 Setup Request\n");