blob: 7629c057d019e7db8833f1818ef5336a6cecff6b [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright 2019-present Infosys Limited  
3 *   
4 * SPDX-License-Identifier: Apache-2.0    
5 */
6/******************************************************************************
7 *
8 * This is an auto generated file.
9 * Please do not edit this file.
10 * All edits to be made through template source file
11 * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt>
12 ******************************************************************************/
13
14#include "causeIe.h"
15#include "dataTypeCodecUtils.h"
16
17CauseIe::CauseIe()
18{
19 ieType = 2;
20 // TODO
21
22}
23
24CauseIe::~CauseIe() {
25 // TODO Auto-generated destructor stub
26}
27
28bool CauseIe::encodeCauseIe(MsgBuffer &buffer, CauseIeData const &data)
29{
30 if (!(buffer.writeUint8(data.causeValue)))
31 {
32 errorStream.add((char *)"Encoding of causeValue failed\n");
33 return false;
34 }
35 buffer.skipBits(5);
36
37 if(!(buffer.writeBits(data.pce, 1)))
38 {
39 errorStream.add((char *)"Encoding of pce failed\n");
40 return false;
41 }
42 if(!(buffer.writeBits(data.pbe, 1)))
43 {
44 errorStream.add((char *)"Encoding of pbe failed\n");
45 return false;
46 }
47 if(!(buffer.writeBits(data.cs, 1)))
48 {
49 errorStream.add((char *)"Encoding of cs failed\n");
50 return false;
51 }
52 if (data.offendingIeDataPresent)
53 {
54 if (!(DataTypeCodecUtils::encodeOffendingIeData(buffer, data.offendingIeData)))
55 {
56 errorStream.add((char *)"Encoding of offendingIeData failed\n");
57 return false;
58 }
59 }
60
61 return true;
62}
63
64bool CauseIe::decodeCauseIe(MsgBuffer &buffer, CauseIeData &data, Uint16 length)
65{
66 // TODO optimize the length checks
67
68 Uint16 ieBoundary = buffer.getCurrentIndex() + length;
69
70 buffer.readUint8(data.causeValue);
71 if (buffer.getCurrentIndex() > ieBoundary)
72 {
73 errorStream.add((char *)"Attempt to read beyond IE boundary: causeValue\n");
74 return false;
75 }
76 buffer.skipBits(5);
77 if (buffer.getCurrentIndex() > ieBoundary)
78 {
79 errorStream.add((char *)"Attempt to read beyond IE boundary: \n");
80 return false;
81 }
82
83 data.pce = buffer.readBits(1);
84 // confirm that we are not reading beyond the IE boundary
85 if (buffer.getCurrentIndex() > ieBoundary)
86 {
87 errorStream.add((char *)"Attempt to read beyond IE boundary: pce\n");
88 return false;
89 }
90 data.pbe = buffer.readBits(1);
91 // confirm that we are not reading beyond the IE boundary
92 if (buffer.getCurrentIndex() > ieBoundary)
93 {
94 errorStream.add((char *)"Attempt to read beyond IE boundary: pbe\n");
95 return false;
96 }
97 data.cs = buffer.readBits(1);
98 // confirm that we are not reading beyond the IE boundary
99 if (buffer.getCurrentIndex() > ieBoundary)
100 {
101 errorStream.add((char *)"Attempt to read beyond IE boundary: cs\n");
102 return false;
103 }
104
105 Uint16 lengthLeft = length;
106
107 if (length == 6)
108 {
109 lengthLeft = ieBoundary - buffer.getCurrentIndex();
110 if (!(DataTypeCodecUtils::decodeOffendingIeData(buffer, data.offendingIeData, lengthLeft)))
111 {
112 errorStream.add((char *)"Failed to decode: offendingIeData\n");
113 return false;
114 }
115 data.offendingIeDataPresent = true;
116 }
117
118 // The IE is decoded now. The buffer index should be pointing to the
119 // IE Boundary. If not, we have some more data left for the IE which we don't know
120 // how to decode
121 if (ieBoundary == buffer.getCurrentIndex())
122 {
123 return true;
124 }
125 else
126 {
127 errorStream.add((char *)"Unable to decode IE CauseIe\n");
128 return false;
129 }
130}
131void CauseIe::displayCauseIe_v(CauseIeData const &data, Debug &stream)
132{
133 stream.incrIndent();
134 stream.add((char *)"CauseIeData:");
135 stream.incrIndent();
136 stream.endOfLine();
137
138 stream.add((char *)"causeValue: ");
139 stream.add(data.causeValue);
140 stream.endOfLine();
141
142 stream.add( (char *)"pce: ");
143 stream.add((Uint8)data.pce);
144 stream.endOfLine();
145
146 stream.add( (char *)"pbe: ");
147 stream.add((Uint8)data.pbe);
148 stream.endOfLine();
149
150 stream.add( (char *)"cs: ");
151 stream.add((Uint8)data.cs);
152 stream.endOfLine();
153
154 if (data.offendingIeDataPresent)
155 {
156 stream.add((char *)"offendingIeData:");
157 stream.endOfLine();
158 DataTypeCodecUtils::displayOffendingIeData_v(data.offendingIeData, stream);
159 }
160 stream.decrIndent();
161 stream.decrIndent();
162}