anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Infosys Limited |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | /****************************************************************************** |
| 8 | * |
| 9 | * This is an auto generated file. |
| 10 | * Please do not edit this file. |
| 11 | * All edits to be made through template source file |
| 12 | * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/stacktemplate.cpp.tt> |
| 13 | ******************************************************************************/ |
| 14 | #include <cstring> |
| 15 | #include <stdint.h> |
| 16 | #include "gtpV2Stack.h" |
| 17 | #include "msgClasses/gtpV2MsgFactory.h" |
| 18 | #include "msgClasses/manual/gtpV2Message.h" |
| 19 | [% FOREACH msg IN tempdata.msgList -%] |
| 20 | #include "msgClasses/[% msg.msgFileName %].h" |
| 21 | [% END -%] |
| 22 | |
| 23 | cmn::utils::Debug errorStream; |
| 24 | |
| 25 | GtpV2Stack::GtpV2Stack () |
| 26 | { |
| 27 | // TODO Auto-generated constructor stub |
| 28 | |
| 29 | } |
| 30 | |
| 31 | GtpV2Stack::~GtpV2Stack () |
| 32 | { |
| 33 | // TODO Auto-generated destructor stub |
| 34 | } |
| 35 | |
| 36 | bool |
| 37 | GtpV2Stack::encodeMessage (GtpV2MessageHeader & msgHeader, |
| 38 | MsgBuffer & buffer, void *data_p) |
| 39 | { |
| 40 | |
| 41 | //Clear the global errorStream |
| 42 | errorStream.clearStream (); |
| 43 | bool rc = false; |
| 44 | GtpV2Message & msg = |
| 45 | GtpV2MsgFactory::getInstance ().getMsgObject (msgHeader.msgType); |
| 46 | |
| 47 | uint16_t gtpHeaderStartIdx = buffer.getCurrentIndex(); |
| 48 | // Encode the header |
| 49 | GtpV2Message::encodeHeader (buffer, msgHeader); |
| 50 | |
| 51 | Uint16 startIndex = buffer.getCurrentIndex(); |
| 52 | |
| 53 | switch (msgHeader.msgType) |
| 54 | { |
| 55 | [% FOREACH msg IN tempdata.msgList -%] |
| 56 | case [% msg.className %]Type: |
| 57 | { |
| 58 | if (data_p != NULL) |
| 59 | { |
| 60 | rc = |
| 61 | dynamic_cast< |
| 62 | [% msg.className %] & >(msg). |
| 63 | encode[% msg.className %](buffer, |
| 64 | *(([% msg.className %]Data *) |
| 65 | data_p)); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | // Application has filled the data structure provided by the stack |
| 70 | rc = |
| 71 | dynamic_cast< |
| 72 | [% msg.className %] & >(msg). |
| 73 | encode[% msg.className %] (buffer, |
| 74 | [% msg.dataMember %]); |
| 75 | } |
| 76 | break; |
| 77 | } |
| 78 | [% END -%] |
| 79 | } |
| 80 | |
| 81 | Uint16 endIndex = buffer.getCurrentIndex (); |
| 82 | |
| 83 | Uint16 messageLength = (endIndex - startIndex)+8; |
| 84 | |
| 85 | buffer.goToIndex (gtpHeaderStartIdx + 2); // 2 is where length is encoded in a gtp message TODO remove hardcoding |
| 86 | buffer.writeUint16 (messageLength, false); |
| 87 | buffer.goToIndex (endIndex); |
| 88 | return rc; |
| 89 | } |
| 90 | |
| 91 | bool |
| 92 | GtpV2Stack::decodeGtpMessageHeader(GtpV2MessageHeader& msgHeader, MsgBuffer& buffer) |
| 93 | { |
| 94 | return GtpV2Message::decodeHeader (buffer, msgHeader); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | bool |
| 99 | GtpV2Stack::decodeMessage (GtpV2MessageHeader& msgHeader, |
| 100 | MsgBuffer& buffer,void* data_p) |
| 101 | { |
| 102 | errorStream.clearStream(); |
| 103 | // First decode the message header |
| 104 | bool rc = false; |
| 105 | |
| 106 | |
| 107 | |
| 108 | Uint16 msgDataLength = msgHeader.msgLength; |
| 109 | |
| 110 | if (msgHeader.teidPresent) |
| 111 | { |
| 112 | msgDataLength = msgDataLength - 8; //teid and sequence number |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | msgDataLength = msgDataLength - 4; //only sequence number |
| 117 | } |
| 118 | |
| 119 | // Validate the length before proceeding |
| 120 | if (msgDataLength != buffer.lengthLeft() ) |
| 121 | { |
| 122 | // Encoded message length does not match the number of bytes left in the message |
| 123 | errorStream.add ((char *)"Message length does not match bytes in buffer\n"); |
| 124 | errorStream.add ((char *)"Computed Message length: "); |
| 125 | errorStream.add (msgDataLength); |
| 126 | errorStream.add ((char *)" Bytes Left in buffer: "); |
| 127 | errorStream.add (buffer.lengthLeft()); |
| 128 | errorStream.endOfLine (); |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | GtpV2Message& msg = |
| 133 | GtpV2MsgFactory::getInstance ().getMsgObject (msgHeader.msgType); |
| 134 | |
| 135 | switch (msgHeader.msgType){ |
| 136 | [% FOREACH msg IN tempdata.msgList -%] |
| 137 | case [% msg.className %]Type: |
| 138 | { |
| 139 | if (data_p != NULL) |
| 140 | { |
| 141 | rc = |
| 142 | dynamic_cast< |
| 143 | [% msg.className %] & >(msg). |
| 144 | decode[% msg.className %](buffer, |
| 145 | *([% msg.className %]Data*) |
| 146 | data_p, msgDataLength); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | // Application wants to use the data structure provided by the stack |
| 151 | // let us first clear any data present in the internal data structure |
| 152 | memset (&[% msg.dataMember %], 0, |
| 153 | sizeof ([% msg.className %]Data)); |
| 154 | rc = |
| 155 | dynamic_cast< |
| 156 | [% msg.className %] & >(msg). |
| 157 | decode[% msg.className %](buffer, |
| 158 | [% msg.dataMember %], |
| 159 | msgDataLength); |
| 160 | } |
| 161 | break; |
| 162 | } |
| 163 | [% END -%] |
| 164 | } |
| 165 | return rc; |
| 166 | } |
| 167 | |
| 168 | void |
| 169 | GtpV2Stack::display_v(Uint8 msgType, Debug& stream, void* data_p) |
| 170 | { |
| 171 | // Display the messageType |
| 172 | stream.add ((char *)"MessageType: "); |
| 173 | stream.add (msgType); |
| 174 | stream.endOfLine (); |
| 175 | |
| 176 | GtpV2Message& msg = GtpV2MsgFactory::getInstance ().getMsgObject (msgType); |
| 177 | |
| 178 | switch (msgType){ |
| 179 | [% FOREACH msg IN tempdata.msgList -%] |
| 180 | case [% msg.className %]Type: |
| 181 | { |
| 182 | stream.add ((char *)"Message: [% msg.className %]"); |
| 183 | stream.endOfLine (); |
| 184 | if (data_p != NULL) |
| 185 | { |
| 186 | dynamic_cast< |
| 187 | [% msg.className %] & >(msg). |
| 188 | display[% msg.className %]Data_v (* |
| 189 | (([% msg.className %]Data*) data_p), stream); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | // Application wants to use the data structure provided by the stack |
| 194 | dynamic_cast< |
| 195 | [% msg.className %] & >(msg). |
| 196 | display[% msg.className %]Data_v |
| 197 | ([% msg.dataMember %], stream); |
| 198 | } |
| 199 | break; |
| 200 | } |
| 201 | [% END -%] |
| 202 | } |
| 203 | } |