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