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 | * 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 "paaIe.h" |
| 15 | #include "dataTypeCodecUtils.h" |
| 16 | |
| 17 | PaaIe::PaaIe() |
| 18 | { |
| 19 | ieType = 79; |
| 20 | // TODO |
| 21 | |
| 22 | } |
| 23 | |
| 24 | PaaIe::~PaaIe() { |
| 25 | // TODO Auto-generated destructor stub |
| 26 | } |
| 27 | |
| 28 | bool PaaIe::encodePaaIe(MsgBuffer &buffer, PaaIeData const &data) |
| 29 | { |
| 30 | buffer.skipBits(5); |
| 31 | |
| 32 | if (!(data.pdnType<= 3)) |
| 33 | { |
| 34 | errorStream.add((char *)"Data validation failure: pdnType\n"); |
| 35 | return false; |
| 36 | } |
| 37 | if(!(buffer.writeBits(data.pdnType, 3))) |
| 38 | { |
| 39 | errorStream.add((char *)"Encoding of pdnType failed\n"); |
| 40 | return false; |
| 41 | } |
| 42 | if (data.pdnType == 2 || data.pdnType == 3) |
| 43 | { |
| 44 | if (!(buffer.writeUint8(data.ipv6PrefixLength))) |
| 45 | { |
| 46 | errorStream.add((char *)"Encoding of ipv6PrefixLength failed\n"); |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | if (data.pdnType == 2 || data.pdnType == 3) |
| 51 | { |
| 52 | if (!(DataTypeCodecUtils::encodeIpAddressV6(buffer, data.ipV6Address))) |
| 53 | { |
| 54 | errorStream.add((char *)"Encoding of ipV6Address failed\n"); |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | if (data.pdnType == 1) |
| 59 | { |
| 60 | if (!(DataTypeCodecUtils::encodeIpAddressV4(buffer, data.ipV4Address))) |
| 61 | { |
| 62 | errorStream.add((char *)"Encoding of ipV4Address failed\n"); |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | bool PaaIe::decodePaaIe(MsgBuffer &buffer, PaaIeData &data, Uint16 length) |
| 71 | { |
| 72 | // TODO optimize the length checks |
| 73 | |
| 74 | Uint16 ieBoundary = buffer.getCurrentIndex() + length; |
| 75 | buffer.skipBits(5); |
| 76 | if (buffer.getCurrentIndex() > ieBoundary) |
| 77 | { |
| 78 | errorStream.add((char *)"Attempt to read beyond IE boundary: \n"); |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | data.pdnType = buffer.readBits(3); |
| 83 | // confirm that we are not reading beyond the IE boundary |
| 84 | if (buffer.getCurrentIndex() > ieBoundary) |
| 85 | { |
| 86 | errorStream.add((char *)"Attempt to read beyond IE boundary: pdnType\n"); |
| 87 | return false; |
| 88 | } |
| 89 | if (!(data.pdnType<= 3)) |
| 90 | { |
| 91 | errorStream.add((char *)"Data validation failure : pdnType\n"); |
| 92 | return false; //TODO need to add validations |
| 93 | } |
| 94 | |
| 95 | if (data.pdnType == 2 || data.pdnType == 3) |
| 96 | { |
| 97 | |
| 98 | buffer.readUint8(data.ipv6PrefixLength); |
| 99 | if (buffer.getCurrentIndex() > ieBoundary) |
| 100 | { |
| 101 | errorStream.add((char *)"Attempt to read beyond IE boundary: ipv6PrefixLength\n"); |
| 102 | return false; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | Uint16 lengthLeft = length; |
| 107 | |
| 108 | if (data.pdnType == 2 || data.pdnType == 3) |
| 109 | { |
| 110 | lengthLeft = ieBoundary - buffer.getCurrentIndex(); |
| 111 | if (!(DataTypeCodecUtils::decodeIpAddressV6(buffer, data.ipV6Address, lengthLeft))) |
| 112 | { |
| 113 | errorStream.add((char *)"Failed to decode: ipV6Address\n"); |
| 114 | return false; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if (data.pdnType == 1) |
| 119 | { |
| 120 | lengthLeft = ieBoundary - buffer.getCurrentIndex(); |
| 121 | if (!(DataTypeCodecUtils::decodeIpAddressV4(buffer, data.ipV4Address, lengthLeft))) |
| 122 | { |
| 123 | errorStream.add((char *)"Failed to decode: ipV4Address\n"); |
| 124 | return false; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // The IE is decoded now. The buffer index should be pointing to the |
| 129 | // IE Boundary. If not, we have some more data left for the IE which we don't know |
| 130 | // how to decode |
| 131 | if (ieBoundary == buffer.getCurrentIndex()) |
| 132 | { |
| 133 | return true; |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | errorStream.add((char *)"Unable to decode IE PaaIe\n"); |
| 138 | return false; |
| 139 | } |
| 140 | } |
| 141 | void PaaIe::displayPaaIe_v(PaaIeData const &data, Debug &stream) |
| 142 | { |
| 143 | stream.incrIndent(); |
| 144 | stream.add((char *)"PaaIeData:"); |
| 145 | stream.incrIndent(); |
| 146 | stream.endOfLine(); |
| 147 | |
| 148 | stream.add( (char *)"pdnType: "); |
| 149 | stream.add((Uint8)data.pdnType); |
| 150 | stream.endOfLine(); |
| 151 | |
| 152 | if (data.pdnType == 2 || data.pdnType == 3) |
| 153 | { |
| 154 | stream.add((char *)"ipv6PrefixLength: "); |
| 155 | stream.add(data.ipv6PrefixLength); |
| 156 | stream.endOfLine(); |
| 157 | } |
| 158 | |
| 159 | if (data.pdnType == 2 || data.pdnType == 3) |
| 160 | { |
| 161 | stream.add((char *)"ipV6Address:"); |
| 162 | stream.endOfLine(); |
| 163 | DataTypeCodecUtils::displayIpAddressV6_v(data.ipV6Address, stream); |
| 164 | } |
| 165 | |
| 166 | if (data.pdnType == 1) |
| 167 | { |
| 168 | stream.add((char *)"ipV4Address:"); |
| 169 | stream.endOfLine(); |
| 170 | DataTypeCodecUtils::displayIpAddressV4_v(data.ipV4Address, stream); |
| 171 | } |
| 172 | stream.decrIndent(); |
| 173 | stream.decrIndent(); |
| 174 | } |