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