slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
| 2 | * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org) |
| 3 | */ |
| 4 | |
| 5 | package org.onosproject.xran.codecs.pdu; |
| 6 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 8 | import org.onosproject.xran.codecs.api.CRNTI; |
| 9 | import org.onosproject.xran.codecs.api.ECGI; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 10 | import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream; |
| 11 | import org.onosproject.xran.codecs.ber.BerLength; |
| 12 | import org.onosproject.xran.codecs.ber.BerTag; |
| 13 | import org.onosproject.xran.codecs.ber.types.string.BerUTF8String; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 14 | |
| 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; |
| 17 | import java.io.Serializable; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 18 | import java.io.UnsupportedEncodingException; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 19 | |
| 20 | |
| 21 | public class UECapabilityEnquiry implements Serializable { |
| 22 | |
| 23 | private static final long serialVersionUID = 1L; |
| 24 | |
| 25 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 26 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 27 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | public byte[] code = null; |
| 29 | private CRNTI crnti = null; |
| 30 | private ECGI ecgi = null; |
| 31 | |
| 32 | public UECapabilityEnquiry() { |
| 33 | } |
| 34 | |
| 35 | public UECapabilityEnquiry(byte[] code) { |
| 36 | this.code = code; |
| 37 | } |
| 38 | |
| 39 | public void setCrnti(CRNTI crnti) { |
| 40 | this.crnti = crnti; |
| 41 | } |
| 42 | |
| 43 | public CRNTI getCrnti() { |
| 44 | return crnti; |
| 45 | } |
| 46 | |
| 47 | public void setEcgi(ECGI ecgi) { |
| 48 | this.ecgi = ecgi; |
| 49 | } |
| 50 | |
| 51 | public ECGI getEcgi() { |
| 52 | return ecgi; |
| 53 | } |
| 54 | |
| 55 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 56 | return encode(os, true); |
| 57 | } |
| 58 | |
| 59 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 60 | |
| 61 | if (code != null) { |
| 62 | for (int i = code.length - 1; i >= 0; i--) { |
| 63 | os.write(code[i]); |
| 64 | } |
| 65 | if (withTag) { |
| 66 | return tag.encode(os) + code.length; |
| 67 | } |
| 68 | return code.length; |
| 69 | } |
| 70 | |
| 71 | int codeLength = 0; |
| 72 | codeLength += ecgi.encode(os, false); |
| 73 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 74 | os.write(0xA1); |
| 75 | codeLength += 1; |
| 76 | |
| 77 | codeLength += crnti.encode(os, false); |
| 78 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 79 | os.write(0x80); |
| 80 | codeLength += 1; |
| 81 | |
| 82 | codeLength += BerLength.encodeLength(os, codeLength); |
| 83 | |
| 84 | if (withTag) { |
| 85 | codeLength += tag.encode(os); |
| 86 | } |
| 87 | |
| 88 | return codeLength; |
| 89 | |
| 90 | } |
| 91 | |
| 92 | public int decode(InputStream is) throws IOException { |
| 93 | return decode(is, true); |
| 94 | } |
| 95 | |
| 96 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 97 | int codeLength = 0; |
| 98 | int subCodeLength = 0; |
| 99 | BerTag berTag = new BerTag(); |
| 100 | |
| 101 | if (withTag) { |
| 102 | codeLength += tag.decodeAndCheck(is); |
| 103 | } |
| 104 | |
| 105 | BerLength length = new BerLength(); |
| 106 | codeLength += length.decode(is); |
| 107 | |
| 108 | int totalLength = length.val; |
| 109 | codeLength += totalLength; |
| 110 | |
| 111 | subCodeLength += berTag.decode(is); |
| 112 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 113 | crnti = new CRNTI(); |
| 114 | subCodeLength += crnti.decode(is, false); |
| 115 | subCodeLength += berTag.decode(is); |
| 116 | } |
| 117 | else { |
| 118 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 119 | } |
| 120 | |
| 121 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 122 | ecgi = new ECGI(); |
| 123 | subCodeLength += ecgi.decode(is, false); |
| 124 | if (subCodeLength == totalLength) { |
| 125 | return codeLength; |
| 126 | } |
| 127 | } |
| 128 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 129 | |
| 130 | |
| 131 | } |
| 132 | |
| 133 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 134 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 135 | encode(os, false); |
| 136 | code = os.getArray(); |
| 137 | } |
| 138 | |
| 139 | public String toString() { |
| 140 | StringBuilder sb = new StringBuilder(); |
| 141 | appendAsString(sb, 0); |
| 142 | return sb.toString(); |
| 143 | } |
| 144 | |
| 145 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 146 | |
| 147 | sb.append("{"); |
| 148 | sb.append("\n"); |
| 149 | for (int i = 0; i < indentLevel + 1; i++) { |
| 150 | sb.append("\t"); |
| 151 | } |
| 152 | if (crnti != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 153 | sb.append("crnti: ").append(crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | sb.append(",\n"); |
| 157 | for (int i = 0; i < indentLevel + 1; i++) { |
| 158 | sb.append("\t"); |
| 159 | } |
| 160 | if (ecgi != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 161 | sb.append("ecgi: "); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 162 | ecgi.appendAsString(sb, indentLevel + 1); |
| 163 | } |
| 164 | |
| 165 | sb.append("\n"); |
| 166 | for (int i = 0; i < indentLevel; i++) { |
| 167 | sb.append("\t"); |
| 168 | } |
| 169 | sb.append("}"); |
| 170 | } |
| 171 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 172 | public static XrancPdu constructPacket(ECGI ecgi, CRNTI crnti) { |
| 173 | UECapabilityEnquiry capabilityEnquiry = new UECapabilityEnquiry(); |
| 174 | capabilityEnquiry.setCrnti(crnti); |
| 175 | capabilityEnquiry.setEcgi(ecgi); |
| 176 | |
| 177 | XrancPduBody body = new XrancPduBody(); |
| 178 | body.setUECapabilityEnquiry(capabilityEnquiry); |
| 179 | |
| 180 | BerUTF8String ver = null; |
| 181 | try { |
| 182 | ver = new BerUTF8String("3"); |
| 183 | } catch (UnsupportedEncodingException e) { |
| 184 | e.printStackTrace(); |
| 185 | } |
| 186 | XrancApiID apiID = new XrancApiID(25); |
| 187 | XrancPduHdr hdr = new XrancPduHdr(); |
| 188 | hdr.setVer(ver); |
| 189 | hdr.setApiId(apiID); |
| 190 | |
| 191 | XrancPdu pdu = new XrancPdu(); |
| 192 | pdu.setHdr(hdr); |
| 193 | pdu.setBody(body); |
| 194 | |
| 195 | return pdu; |
| 196 | } |
| 197 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 198 | } |
| 199 | |