📄 pdu.java
字号:
if (udhLength == 0) return 0;
// also takes into account the field holding the length
// it self
return udhLength + 1;
}
public int getUDHLength()
{
// compute based on the IEs
int udhLength = 0;
for (InformationElement ie : ieMap.values())
{
// length + 2 to account for the octet holding the IE length and id
udhLength = udhLength + ie.getLength() + 2;
}
return udhLength;
}
public byte[] getUDHData()
{
checkForUDHI(UDH_CHECK_MODE_IGNORE_IF_NONE);
int totalUdhLength = getTotalUDHLength();
if (totalUdhLength == 0) return null;
byte[] retVal = new byte[totalUdhLength];
System.arraycopy(udData, 0, retVal, 0, totalUdhLength);
return retVal;
}
// UDH portion of UD if UDHI is present
// only Concat and Port info will be treated specially
// other IEs will have to get extracted from the map manually and parsed
private HashMap<Integer, InformationElement> ieMap = new HashMap<Integer, InformationElement>();
private ArrayList<InformationElement> ieList = new ArrayList<InformationElement>();
public void addInformationElement(InformationElement ie)
{
checkForUDHI(UDH_CHECK_MODE_ADD_IF_NONE);
ieMap.put(ie.getIdentifier(), ie);
ieList.add(ie);
}
public InformationElement getInformationElement(int iei)
{
checkForUDHI(UDH_CHECK_MODE_IGNORE_IF_NONE);
return ieMap.get(iei);
}
// this is only used in the parser generator
public Iterator<InformationElement> getInformationElements()
{
checkForUDHI(UDH_CHECK_MODE_IGNORE_IF_NONE);
return ieList.iterator();
}
// ==================================================
// CONCAT INFO
// ==================================================
public boolean isConcatMessage()
{
// check if iei 0x00 or 0x08 is present
return (getConcatInfo() != null);
}
public ConcatInformationElement getConcatInfo()
{
checkForUDHI(UDH_CHECK_MODE_IGNORE_IF_NONE);
ConcatInformationElement concat = (ConcatInformationElement) getInformationElement(ConcatInformationElement.CONCAT_8BIT_REF);
if (concat == null)
{
concat = (ConcatInformationElement) getInformationElement(ConcatInformationElement.CONCAT_16BIT_REF);
}
return concat;
}
public int getMpRefNo()
{
ConcatInformationElement concat = getConcatInfo();
if (concat != null) return concat.getMpRefNo();
return 0;
}
public int getMpMaxNo()
{
ConcatInformationElement concat = getConcatInfo();
if (concat != null) return concat.getMpMaxNo();
return 1;
}
public int getMpSeqNo()
{
ConcatInformationElement concat = getConcatInfo();
if (concat != null) return concat.getMpSeqNo();
return 0;
}
// ==================================================
// PORT DATA
// ==================================================
public boolean isPortedMessage()
{
// check if iei 0x05 is present
return (getPortInfo() != null);
}
private PortInformationElement getPortInfo()
{
checkForUDHI(UDH_CHECK_MODE_IGNORE_IF_NONE);
return (PortInformationElement) getInformationElement(PortInformationElement.PORT_16BIT);
}
public int getDestPort()
{
PortInformationElement portIe = getPortInfo();
if (portIe == null) return -1;
return portIe.getDestPort();
}
public int getSrcPort()
{
PortInformationElement portIe = getPortInfo();
if (portIe == null) return -1;
return portIe.getSrcPort();
}
// ==================================================
// NON-UDH DATA
// ==================================================
// UD minus the UDH portion, same as userData if
// no UDH
// these fields store data for the generation step
private String decodedText;
private byte[] dataBytes;
public void setDataBytes(byte[] dataBytes)
{
this.dataBytes = dataBytes;
this.decodedText = null;
// clear the encoding bits for this field 8-bit/data
this.dataCodingScheme &= PduUtils.DCS_ENCODING_MASK;
this.dataCodingScheme |= PduUtils.DCS_ENCODING_8BIT;
this.dataCodingScheme |= PduUtils.DCS_CODING_GROUP_DATA;
}
public byte[] getDataBytes()
{
return dataBytes;
}
public boolean isBinary()
{
// use the DCS coding group or 8bit encoding
return ((this.dataCodingScheme & PduUtils.DCS_CODING_GROUP_DATA) == PduUtils.DCS_CODING_GROUP_DATA || (this.dataCodingScheme & PduUtils.DCS_ENCODING_8BIT) == PduUtils.DCS_ENCODING_8BIT);
}
public void setDecodedText(String decodedText)
{
this.decodedText = decodedText;
this.dataBytes = null;
// clears the coding group to be text again in case it was originally binary
this.dataCodingScheme &= PduUtils.DCS_CODING_GROUP_MASK;
}
public String getDecodedText()
{
// this should be try-catched in case the ud data is
// actually binary and might cause a decoding exception
if (decodedText != null) return decodedText;
if (udData == null) throw new NullPointerException("No udData to decode");
try
{
return decodeNonUDHDataAsString();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public byte[] getUserDataAsBytes()
{
int remainingLength = udData.length - (getTotalUDHLength());
byte[] retVal = new byte[remainingLength];
System.arraycopy(udData, getTotalUDHLength(), retVal, 0, remainingLength);
return retVal;
}
private String decodeNonUDHDataAsString()
{
// convert PDU to text depending on the encoding
// must also take into account the octet holding the length
int udhTotalBytes = getTotalUDHLength();
switch (PduUtils.extractDcsEncoding(getDataCodingScheme()))
{
case PduUtils.DCS_ENCODING_7BIT:
// if there is no UDH, udhData should be null
return PduUtils.decode7bitEncoding(udhTotalBytes, udData);
case PduUtils.DCS_ENCODING_8BIT:
return PduUtils.decode8bitEncoding(udhTotalBytes, udData);
case PduUtils.DCS_ENCODING_UCS2:
return PduUtils.decodeUcs2Encoding(udhTotalBytes, udData);
}
throw new RuntimeException("Invalid dataCodingScheme: " + getDataCodingScheme());
}
// PDU MANAGEMENT
private String rawPdu;
public String getRawPdu()
{
return rawPdu;
}
public void setRawPdu(String rawPdu)
{
this.rawPdu = rawPdu;
}
@Override
public final String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("=================================================\n");
sb.append("<< " + getClass().getSimpleName() + " >>");
sb.append("\n");
sb.append("Raw Pdu: ");
sb.append(rawPdu);
sb.append("\n");
sb.append("\n");
// smsc info
// first octet
if (smscAddress != null)
{
sb.append("SMSC Address: [Length: " + getSmscInfoLength() + " (" + PduUtils.byteToPdu((byte) getSmscInfoLength()) + ") octets");
sb.append(", Type: " + PduUtils.byteToPdu(smscAddressType) + " (" + PduUtils.byteToBits((byte) smscAddressType) + ")");
sb.append(", Address: " + smscAddress);
sb.append("]");
}
else
{
sb.append("SMSC Address: [Length: 0 octets]");
}
sb.append("\n");
sb.append(PduUtils.decodeFirstOctet(this));
String subclassInfo = pduSubclassInfo();
if (subclassInfo != null)
{
sb.append(subclassInfo);
}
sb.append("\n");
// ud, only for Submit and Delivery, Status Reports have no UD
if (udData != null)
{
switch (PduUtils.extractDcsEncoding(getDataCodingScheme()))
{
case PduUtils.DCS_ENCODING_7BIT:
sb.append("User Data Length: " + getUDLength() + " (" + PduUtils.byteToPdu(getUDLength()) + ") septets");
sb.append("\n");
break;
case PduUtils.DCS_ENCODING_8BIT:
case PduUtils.DCS_ENCODING_UCS2:
sb.append("User Data Length: " + getUDLength() + " (" + PduUtils.byteToPdu(getUDLength()) + ") octets");
sb.append("\n");
break;
}
sb.append("User Data (pdu) : " + PduUtils.bytesToPdu(getUDData()));
sb.append("\n");
if (hasTpUdhi())
{
// raw udh
sb.append("User Data Header (pdu) : " + PduUtils.bytesToPdu(getUDHData()));
sb.append("\n");
int udhLength = getUDHLength();
sb.append("User Data Header Length: " + udhLength + " (" + PduUtils.byteToPdu(udhLength) + ") octets");
sb.append("\n");
sb.append("\n");
// information elements
sb.append("UDH Information Elements:\n");
for (InformationElement ie : ieMap.values())
{
sb.append(ie.toString());
sb.append("\n");
}
// decoded text
// raw binary (as pdu)
sb.append("\n");
sb.append("Non UDH Data (pdu) : " + PduUtils.bytesToPdu(getUserDataAsBytes()));
sb.append("\n");
if (!isBinary())
{
sb.append("Non UDH Data (decoded): [" + getDecodedText() + "]");
sb.append("\n");
}
}
else
{
if (!isBinary())
{
sb.append("User Data (decoded): [" + getDecodedText() + "]");
sb.append("\n");
}
}
}
sb.append("=================================================\n");
return sb.toString();
}
protected String pduSubclassInfo()
{
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -