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