PageRenderTime 34ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitive.java

http://mobicents.googlecode.com/
Java | 234 lines | 164 code | 39 blank | 31 comment | 4 complexity | 8d10494e0082c622c7e5cc24710d204e MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.mtp;
  23. /**
  24. * @author sergey vetyutnev
  25. *
  26. */
  27. public class Mtp3TransferPrimitive {
  28. protected int si; // service indicator
  29. protected int ni; // network indicator
  30. protected int mp; // message priority
  31. protected int opc;
  32. protected int dpc;
  33. protected int sls;
  34. protected byte[] data;
  35. public Mtp3TransferPrimitive() {
  36. }
  37. public Mtp3TransferPrimitive(int si, int ni, int mp, int opc, int dpc, int sls, byte[] data) {
  38. this.si = si;
  39. this.ni = ni;
  40. this.mp = mp;
  41. this.opc = opc;
  42. this.dpc = dpc;
  43. this.sls = sls;
  44. this.data = data;
  45. }
  46. public int getSi() {
  47. return this.si;
  48. }
  49. public int getNi() {
  50. return this.ni;
  51. }
  52. public int getMp() {
  53. return this.mp;
  54. }
  55. public int getOpc() {
  56. return this.opc;
  57. }
  58. public int getDpc() {
  59. return this.dpc;
  60. }
  61. public int getSls() {
  62. return this.sls;
  63. }
  64. public byte[] getData() {
  65. return this.data;
  66. }
  67. public void setSi(int si) {
  68. this.si = si;
  69. }
  70. public void setNi(int ni) {
  71. this.ni = ni;
  72. }
  73. public void setMp(int mp) {
  74. this.mp = mp;
  75. }
  76. public void setOpc( int opc ) {
  77. this.opc = opc;
  78. }
  79. public void setDpc( int dpc ) {
  80. this.dpc = dpc;
  81. }
  82. public void setSls( int sls ) {
  83. this.sls = sls;
  84. }
  85. public void setData(byte[] data) {
  86. this.data = data;
  87. }
  88. public void decodeMtp3(byte[] msg) {
  89. // sio
  90. int sio = msg[0];
  91. this.si = sio & 0x0F;
  92. int ssi = (sio & 0xF0) >> 4;
  93. this.ni = ssi >> 2;
  94. this.mp = ssi & 0x03;
  95. // routing label
  96. byte b1 = msg[1];
  97. byte b2 = msg[2];
  98. byte b3 = msg[3];
  99. byte b4 = msg[4];
  100. this.dpc = ((b2 & 0x3f) << 8) | (b1 & 0xff);
  101. this.opc = ((b4 & 0x0f) << 10) | ((b3 & 0xff) << 2) | ((b2 & 0xc0) >> 6);
  102. this.sls = ((b4 & 0xf0) >> 4);
  103. // msu data
  104. this.data = new byte[msg.length - 5];
  105. System.arraycopy(msg, 5, this.data, 0, this.data.length);
  106. }
  107. public byte[] encodeMtp3() {
  108. byte[] res = new byte[this.data.length + 5];
  109. // sio
  110. int ssi = (this.ni & 0x03) << 2 | (this.mp & 0x03);
  111. res[0] = (byte) (((ssi & 0x0F) << 4) | (this.si & 0x0F));
  112. // routing label
  113. res[1] = (byte) dpc;
  114. res[2] = (byte) (((dpc >> 8) & 0x3F) | ((this.opc & 0x03) << 6));
  115. res[3] = (byte) (this.opc >> 2);
  116. res[4] = (byte) (((this.opc >> 10) & 0x0F) | ((sls & 0x0F) << 4));
  117. // msu data
  118. System.arraycopy(this.data, 0, res, 5, this.data.length);
  119. return res;
  120. }
  121. @Override
  122. public String toString() {
  123. StringBuilder sb = new StringBuilder();
  124. sb.append("MTP-TRANSFER: OPC=");
  125. sb.append(this.opc);
  126. sb.append(", DPC=");
  127. sb.append(this.dpc);
  128. sb.append(", SLS=");
  129. sb.append(this.sls);
  130. if (this.data != null) {
  131. sb.append(", MsgLen=");
  132. sb.append(this.data.length);
  133. }
  134. sb.append(", NI=");
  135. switch (this.ni) {
  136. case 0:
  137. sb.append("National");
  138. break;
  139. case 1:
  140. sb.append("NationalSpare");
  141. break;
  142. case 2:
  143. sb.append("International");
  144. break;
  145. case 3:
  146. sb.append("InternationalSpare");
  147. break;
  148. default:
  149. sb.append(this.ni);
  150. break;
  151. }
  152. sb.append(", SI=");
  153. switch (this.si) {
  154. case 0:
  155. sb.append("SNMM");
  156. break;
  157. case 1:
  158. sb.append("SNTMM");
  159. break;
  160. case 2:
  161. sb.append("SNTMM Special");
  162. break;
  163. case 3:
  164. sb.append("SCCP");
  165. break;
  166. case 4:
  167. sb.append("TUP");
  168. break;
  169. case 5:
  170. sb.append("ISDN");
  171. break;
  172. case 6:
  173. sb.append("DUP-1");
  174. break;
  175. case 7:
  176. sb.append("DUP-1");
  177. break;
  178. case 8:
  179. sb.append("MTP Testing");
  180. break;
  181. case 9:
  182. sb.append("Broadband ISDN");
  183. break;
  184. case 10:
  185. sb.append("Satellite ISDN");
  186. break;
  187. default:
  188. sb.append(this.si);
  189. break;
  190. }
  191. sb.append(", MP=");
  192. sb.append(this.mp);
  193. return sb.toString();
  194. }
  195. }