/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/dialog/MAPOpenInfoImpl.java

http://mobicents.googlecode.com/ · Java · 319 lines · 207 code · 55 blank · 57 comment · 27 complexity · 7184c80f85bd73b4df9010557660bc03 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.ss7.map.dialog;
  23. import java.io.IOException;
  24. import org.mobicents.protocols.asn.AsnException;
  25. import org.mobicents.protocols.asn.AsnInputStream;
  26. import org.mobicents.protocols.asn.AsnOutputStream;
  27. import org.mobicents.protocols.asn.Tag;
  28. import org.mobicents.protocols.ss7.map.api.MAPException;
  29. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  30. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  31. import org.mobicents.protocols.ss7.map.api.primitives.AddressString;
  32. import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
  33. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  34. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  35. import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
  36. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  37. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  38. /**
  39. * Below is Ericsson MAP-OpenInfo
  40. *
  41. * MAP−OpenInfo ::= SEQUENCE (
  42. * imsi (0) IMSI OPTIONAL,
  43. * originationReference (1) AddressString OPTIONAL,
  44. * msisdn (2) AddressString,
  45. * ...
  46. * vlrNo (3) AddressString OPTIONAL
  47. * )
  48. *
  49. * @author amit bhayani
  50. * @author sergey vetyutnev
  51. *
  52. */
  53. public class MAPOpenInfoImpl implements MAPAsnPrimitive {
  54. public static final int MAP_OPEN_INFO_TAG = 0x00;
  55. protected static final int DESTINATION_REF_TAG = 0x00;
  56. protected static final int ORIGINATION_REF_TAG = 0x01;
  57. protected static final int ERI_MSISDN_TAG = 0x02;
  58. protected static final int ERI_NLR_NO_TAG = 0x03;
  59. protected static final int OPEN_INFO_TAG_CLASS = Tag.CLASS_CONTEXT_SPECIFIC;
  60. protected static final boolean OPEN_INFO_TAG_PC_PRIMITIVE = true;
  61. protected static final boolean OPEN_INFO_TAG_PC_CONSTRUCTED = false;
  62. private AddressString destReference;
  63. private AddressString origReference;
  64. private MAPExtensionContainer extensionContainer;
  65. private boolean eriStyle;
  66. private IMSI eriImsi;
  67. private AddressString eriVlrNo;
  68. public AddressString getDestReference() {
  69. return this.destReference;
  70. }
  71. public AddressString getOrigReference() {
  72. return this.origReference;
  73. }
  74. public MAPExtensionContainer getExtensionContainer() {
  75. return extensionContainer;
  76. }
  77. public boolean getEriStyle() {
  78. return this.eriStyle;
  79. }
  80. public IMSI getEriImsi() {
  81. return eriImsi;
  82. }
  83. public AddressString getEriVlrNo() {
  84. return eriVlrNo;
  85. }
  86. public void setDestReference(AddressString destReference) {
  87. this.destReference = destReference;
  88. }
  89. public void setOrigReference(AddressString origReference) {
  90. this.origReference = origReference;
  91. }
  92. public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
  93. this.extensionContainer = extensionContainer;
  94. }
  95. public void setEriStyle(boolean eriStyle) {
  96. this.eriStyle = eriStyle;
  97. }
  98. public void setEriImsi(IMSI eriImsi) {
  99. this.eriImsi = eriImsi;
  100. }
  101. public void setEriVlrNo(AddressString eriVlrNo) {
  102. this.eriVlrNo = eriVlrNo;
  103. }
  104. @Override
  105. public int getTag() throws MAPException {
  106. return MAP_OPEN_INFO_TAG;
  107. }
  108. @Override
  109. public int getTagClass() {
  110. return Tag.CLASS_CONTEXT_SPECIFIC;
  111. }
  112. @Override
  113. public boolean getIsPrimitive() {
  114. return false;
  115. }
  116. @Override
  117. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  118. try {
  119. int length = ansIS.readLength();
  120. this._decode(ansIS, length);
  121. } catch (IOException e) {
  122. throw new MAPParsingComponentException("IOException when decoding MAPOpenInfo: " + e.getMessage(), e,
  123. MAPParsingComponentExceptionReason.MistypedParameter);
  124. } catch (AsnException e) {
  125. throw new MAPParsingComponentException("AsnException when decoding MAPOpenInfo: " + e.getMessage(), e,
  126. MAPParsingComponentExceptionReason.MistypedParameter);
  127. }
  128. }
  129. @Override
  130. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  131. try {
  132. this._decode(ansIS, length);
  133. } catch (IOException e) {
  134. throw new MAPParsingComponentException("IOException when decoding MAPOpenInfo: " + e.getMessage(), e,
  135. MAPParsingComponentExceptionReason.MistypedParameter);
  136. } catch (AsnException e) {
  137. throw new MAPParsingComponentException("AsnException when decoding MAPOpenInfo: " + e.getMessage(), e,
  138. MAPParsingComponentExceptionReason.MistypedParameter);
  139. }
  140. }
  141. private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException {
  142. // Definitioon from GSM 09.02 version 5.15.1 Page 690
  143. // map-open [0] IMPLICIT SEQUENCE {
  144. // destinationReference [0] IMPLICIT OCTET STRING ( SIZE( 1 .. 20 ) )
  145. // OPTIONAL,
  146. // originationReference [1] IMPLICIT OCTET STRING ( SIZE( 1 .. 20 ) )
  147. // OPTIONAL,
  148. // ... ,
  149. // extensionContainer SEQUENCE {
  150. // privateExtensionList [0] IMPLICIT SEQUENCE ( SIZE( 1 .. 10 ) ) OF
  151. // SEQUENCE {
  152. // extId MAP-EXTENSION .&extensionId ( {
  153. // ,
  154. // ...} ) ,
  155. // extType MAP-EXTENSION .&ExtensionType ( {
  156. // ,
  157. // ...} { @extId } ) OPTIONAL} OPTIONAL,
  158. // pcs-Extensions [1] IMPLICIT SEQUENCE {
  159. // ... } OPTIONAL,
  160. // ... } OPTIONAL},
  161. this.destReference = null;
  162. this.origReference = null;
  163. this.extensionContainer = null;
  164. this.eriStyle = false;
  165. this.eriImsi = null;
  166. this.eriVlrNo = null;
  167. AsnInputStream localAis = ais.readSequenceStreamData(length);
  168. // checking for Ericsson-style
  169. int startPos = localAis.position();
  170. while (localAis.available() > 0) {
  171. int tag = localAis.readTag();
  172. if (localAis.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC && tag == ERI_MSISDN_TAG) {
  173. this.eriStyle = true;
  174. break;
  175. }
  176. localAis.advanceElement();
  177. }
  178. // parsing
  179. localAis.position(startPos);
  180. while (localAis.available() > 0) {
  181. int tag = localAis.readTag();
  182. switch (localAis.getTagClass()) {
  183. case Tag.CLASS_CONTEXT_SPECIFIC:
  184. switch (tag) {
  185. case DESTINATION_REF_TAG:
  186. if (this.eriStyle) {
  187. this.eriImsi = new IMSIImpl();
  188. ((IMSIImpl) this.eriImsi).decodeAll(localAis);
  189. } else {
  190. this.destReference = new AddressStringImpl();
  191. ((AddressStringImpl) this.destReference).decodeAll(localAis);
  192. }
  193. break;
  194. case ORIGINATION_REF_TAG:
  195. this.origReference = new AddressStringImpl();
  196. ((AddressStringImpl)this.origReference).decodeAll(localAis);
  197. break;
  198. case ERI_MSISDN_TAG:
  199. this.destReference = new AddressStringImpl();
  200. ((AddressStringImpl) this.destReference).decodeAll(localAis);
  201. break;
  202. case ERI_NLR_NO_TAG:
  203. this.eriVlrNo = new AddressStringImpl();
  204. ((AddressStringImpl)this.eriVlrNo).decodeAll(localAis);
  205. break;
  206. default:
  207. localAis.advanceElement();
  208. break;
  209. }
  210. break;
  211. case Tag.CLASS_UNIVERSAL:
  212. switch (tag) {
  213. case Tag.SEQUENCE:
  214. this.extensionContainer = new MAPExtensionContainerImpl();
  215. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(localAis);
  216. break;
  217. default:
  218. localAis.advanceElement();
  219. break;
  220. }
  221. break;
  222. default:
  223. localAis.advanceElement();
  224. break;
  225. }
  226. }
  227. }
  228. @Override
  229. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  230. this.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, MAP_OPEN_INFO_TAG);
  231. }
  232. @Override
  233. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  234. try {
  235. asnOs.writeTag(tagClass, false, tag);
  236. int pos = asnOs.StartContentDefiniteLength();
  237. this.encodeData(asnOs);
  238. asnOs.FinalizeContent(pos);
  239. } catch (AsnException e) {
  240. throw new MAPException("AsnException when encoding MAPOpenInfo: " + e.getMessage(), e);
  241. }
  242. }
  243. @Override
  244. public void encodeData(AsnOutputStream asnOS) throws MAPException {
  245. if (this.eriStyle) {
  246. if (this.destReference == null)
  247. throw new MAPException("Error when encoding MAPOpenInf Ericsson style: destReference parameter must not be null");
  248. if (this.eriImsi != null)
  249. ((IMSIImpl) this.eriImsi).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, DESTINATION_REF_TAG);
  250. if (this.origReference != null)
  251. ((AddressStringImpl) this.origReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ORIGINATION_REF_TAG);
  252. ((AddressStringImpl) this.destReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ERI_MSISDN_TAG);
  253. if (this.eriVlrNo != null)
  254. ((AddressStringImpl) this.eriVlrNo).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ERI_NLR_NO_TAG);
  255. } else {
  256. if (this.destReference != null)
  257. ((AddressStringImpl) this.destReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, DESTINATION_REF_TAG);
  258. if (this.origReference != null)
  259. ((AddressStringImpl) this.origReference).encodeAll(asnOS, Tag.CLASS_CONTEXT_SPECIFIC, ORIGINATION_REF_TAG);
  260. if (this.extensionContainer != null)
  261. ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOS);
  262. }
  263. }
  264. }