/// <summary> Extracts a specified portion of the smpp buffer to a string </summary> /// <param name="propertyName"></param> /// <param name="length"></param> /// <param name="bCodepage"></param> /// <param name="offset"></param> /// <returns> PduPropertyDetail </returns> public PduPropertyDetail ExtractEncodedString(string propertyName, int length, byte bCodepage, ref int offset) { PduPropertyDetail detail = new PduPropertyDetail(offset, PduDataTypes.EncodedString, propertyName); try { if (length > 0) { detail.ValueString = null; if (bCodepage == (byte) DataCodings.Default) { bCodepage = (byte) DefaultEncoding; } detail.DataBlock = ListBuffer.GetRange(offset, length).ToArray(); switch (bCodepage) { case (byte) DataCodings.UCS2: case (byte) DataCodings.UnicodeFlashSMS: detail.ValueString = System.Text.Encoding.BigEndianUnicode.GetString(detail.DataBlock); break; case (byte) DataCodings.OctetUnspecified: case (byte) DataCodings.Octets: detail.ValueString = System.Text.Encoding.UTF8.GetString(detail.DataBlock); break; case (byte) DataCodings.Latin1: case (byte) DataCodings.Latin1Escape: detail.ValueString = SmppBuffer.ISO88591.GetString(detail.DataBlock); break; case (byte) DataCodings.ASCII: detail.ValueString = IA5GSMToString(detail.DataBlock, 0, length); break; } offset += length; } else { detail.DataBlock = new byte[1]; detail.DataBlock[0] = ListBuffer[offset]; detail.ValueString = null; } } catch { detail.DataBlock = new byte[1]; detail.DataBlock[0] = ListBuffer[offset]; detail.ValueString = null; offset += 1; } return detail; }
/// <summary> Extracts a specified portion of the smpp buffer to a byte array </summary> /// <param name="propertyName"></param> /// <param name="offset"></param> /// <param name="length"></param> /// <returns> PduPropertyDetail </returns> public PduPropertyDetail ExtractByteArray(string propertyName, ref int offset, ushort length) { PduPropertyDetail detail = new PduPropertyDetail(offset, PduDataTypes.ByteArray, propertyName); detail.DataBlock = ListBuffer.GetRange(offset, length).ToArray(); offset = offset + length; return detail; }
/// <summary> Extracts a specified portion of the smpp buffer to a string </summary> /// <param name="propertyName"></param> /// <param name="offset"></param> /// <returns> PduPropertyDetail </returns> public PduPropertyDetail ExtractCString(string propertyName, ref int offset) { PduPropertyDetail detail = new PduPropertyDetail(offset, PduDataTypes.CString, propertyName); int endofStringPosition = offset; try { endofStringPosition = ListBuffer.IndexOf(0, offset); if (endofStringPosition > offset) { detail.DataBlock = ListBuffer.GetRange(offset, endofStringPosition - offset).ToArray(); detail.ValueString = System.Text.ASCIIEncoding.ASCII.GetString(detail.DataBlock); offset = endofStringPosition + 1; } else { detail.DataBlock = new byte[1]; detail.DataBlock[0] = ListBuffer[offset]; detail.ValueString = null; offset += 1; } } catch (System.Exception) { detail.DataBlock = new byte[1]; detail.DataBlock[0] = ListBuffer[offset]; detail.ValueString = null; offset = endofStringPosition + 1; } return detail; }
/// <summary> Extracts a specified portion of the smpp buffer to a byte </summary> /// <param name="propertyName"></param> /// <param name="offset"></param> /// <returns> PduPropertyDetail </returns> public PduPropertyDetail ExtractByte(string propertyName, ref int offset) { PduPropertyDetail detail = new PduPropertyDetail(offset, PduDataTypes.Byte, propertyName); detail.DataBlock = new byte[1]; detail.DataBlock[0] = ListBuffer[offset]; offset += 1; detail.ValueByte = detail.DataBlock[0]; return detail; }
/// <summary> Called to extract the user data portion of the smpp buffer </summary> /// <param name="details"></param> /// <param name="udhi"></param> /// <param name="offset"></param> public void ExtractUserData(List<PduPropertyDetail> details, bool udhi, int offset) { PduPropertyDetail detail = null; if (udhi) { detail = ExtractByte("UserData_UdhLength", ref offset); details.Add(detail); byte udhLength = detail.ValueByte; int curOffset = offset; int countedUdhLegth = 0; while (curOffset + udhLength > offset) { detail = ExtractByte("UserData_UdhiType", ref offset); details.Add(detail); byte udhiType = detail.ValueByte; detail = ExtractByte("UserData_UdhiLength", ref offset); details.Add(detail); byte udhiLength = detail.ValueByte; countedUdhLegth += udhiLength + 2; if (countedUdhLegth > udhLength) { // Wrong UDH found break; } details.Add(ExtractByteArray("UserData_Headers", ref offset, udhiLength)); } } if (Length - offset > 0) { detail = new PduPropertyDetail(offset, PduDataTypes.ByteArray, "UserData_Payload"); detail.DataBlock = ListBuffer.GetRange(offset, Length - offset).ToArray(); details.Add(detail); } }
/// <summary> Extracts a specified portion of the smpp buffer to an unsigned short </summary> /// <param name="propertyName"></param> /// <param name="offset"></param> /// <returns> PduPropertyDetail </returns> public PduPropertyDetail ExtractShort(string propertyName, ref int offset) { PduPropertyDetail detail = new PduPropertyDetail(offset, PduDataTypes.UShort, propertyName); detail.DataBlock = ListBuffer.GetRange(offset, 2).ToArray(); byte[] value = detail.DataBlock; if (System.BitConverter.IsLittleEndian) { value[1] = ListBuffer[0 + offset]; value[0] = ListBuffer[1 + offset]; } else { value[1] = ListBuffer[0 + offset]; value[0] = ListBuffer[1 + offset]; } offset += 2; detail.ValueUShort = System.BitConverter.ToUInt16(value, 0); return detail; }
/// <summary> Called to return a list of property details from the PDU </summary> /// <returns> List PduPropertyDetail </returns> public List <PduPropertyDetail> Details() { List <PduPropertyDetail> details = null; try { int offset = 0; details = PduData.ExtractHeaderDetails(ref offset); details.Add(PduData.ExtractCString("ServiceType", ref offset)); details.Add(PduData.ExtractByte("SourceTon", ref offset)); details.Add(PduData.ExtractByte("SourceNpi", ref offset)); details.Add(PduData.ExtractCString("SourceAddr", ref offset)); details.Add(PduData.ExtractByte("DestTon", ref offset)); details.Add(PduData.ExtractByte("DestNpi", ref offset)); details.Add(PduData.ExtractCString("DestAddr", ref offset)); PduPropertyDetail esmClass = PduData.ExtractByte("EsmClass", ref offset); details.Add(esmClass); details.Add(PduData.ExtractByte("EsmClass", ref offset)); details.Add(PduData.ExtractByte("RegisteredDelivery", ref offset)); details.Add(PduData.ExtractByte("DataCoding", ref offset)); while (offset < PduData.Length) { PduData.ExtractTLV(details, ref offset); PduPropertyDetail tlvTag = details[details.Count - 3]; PduPropertyDetail tlvLength = details[details.Count - 2]; PduPropertyDetail tlvValue = details[details.Count - 1]; switch (tlvTag.ValueUShort) { case (ushort)OptionalTags.MessagePayload: GSMSpecificFeatures messageFeature = (GSMSpecificFeatures)(esmClass.ValueByte & 0xc0); SmppBuffer userData = new SmppBuffer(DefaultEncoding, tlvValue.DataBlock); userData.ExtractUserData(details, messageFeature == GSMSpecificFeatures.UDHI, offset); break; case (ushort)OptionalTags.SarMsgRefNum: tlvValue.PduDataType = PduDataTypes.UShort; tlvValue.Name = "SARReferenceNumber"; tlvValue.ValueUShort = SmppBuffer.BytesToShort(tlvValue.DataBlock, 0); break; case (ushort)OptionalTags.SarTotalSegments: tlvValue.PduDataType = PduDataTypes.Byte; tlvValue.Name = "SARTotalSegments"; tlvValue.ValueByte = tlvValue.DataBlock[0]; break; case (ushort)OptionalTags.SarSegmentSeqnum: tlvValue.PduDataType = PduDataTypes.Byte; tlvValue.Name = "SARSequenceNumber"; tlvValue.ValueByte = tlvValue.DataBlock[0]; break; } } } catch { } return(details); }
/// <summary> Called to return a list of property details from the PDU </summary> /// <returns> List PduPropertyDetail </returns> public List <PduPropertyDetail> Details() { List <PduPropertyDetail> details = null; try { int offset = 0; details = PduData.ExtractHeaderDetails(ref offset); details.Add(PduData.ExtractCString("ServiceType", ref offset)); details.Add(PduData.ExtractByte("SourceTon", ref offset)); details.Add(PduData.ExtractByte("SourceNpi", ref offset)); details.Add(PduData.ExtractCString("SourceAddr", ref offset)); details.Add(PduData.ExtractByte("DestTon", ref offset)); details.Add(PduData.ExtractByte("DestNpi", ref offset)); details.Add(PduData.ExtractCString("DestAddr", ref offset)); PduPropertyDetail esmClass = PduData.ExtractByte("EsmClass", ref offset); details.Add(esmClass); details.Add(PduData.ExtractByte("ProtocolId", ref offset)); details.Add(PduData.ExtractByte("PriorityFlag", ref offset)); details.Add(PduData.ExtractCString("ScheduleDeliveryTime", ref offset)); details.Add(PduData.ExtractCString("ValidityPeriod", ref offset)); details.Add(PduData.ExtractByte("RegisteredDelivery", ref offset)); details.Add(PduData.ExtractByte("ReplaceIfPresent", ref offset)); PduPropertyDetail dataCoding = PduData.ExtractByte("DataCoding", ref offset); details.Add(dataCoding); details.Add(PduData.ExtractByte("DefaultMsgId", ref offset)); PduPropertyDetail messageLength = PduData.ExtractByte("ShortMessageLength", ref offset); details.Add(messageLength); if (messageLength.ValueByte > 0) { PduPropertyDetail userDataProperty = PduData.ExtractByteArray("ShortMessage", ref offset, messageLength.ValueByte); userDataProperty.PduDataType = PduDataTypes.EncodedString; UserData userData = UserData.Create(new SmppBuffer(DefaultEncoding, userDataProperty.DataBlock), false); userDataProperty.ValueString = userData.ShortMessageText(DefaultEncoding, (DataCodings)dataCoding.ValueByte); details.Add(userDataProperty); } while (offset < PduData.Length) { PduData.ExtractTLV(details, ref offset); PduPropertyDetail tlvTag = details[details.Count - 3]; PduPropertyDetail tlvLength = details[details.Count - 2]; PduPropertyDetail tlvValue = details[details.Count - 1]; switch (tlvTag.ValueUShort) { case (ushort)OptionalTags.MessagePayload: GSMSpecificFeatures messageFeature = (GSMSpecificFeatures)(esmClass.ValueByte & 0xc0); SmppBuffer userData = new SmppBuffer(DefaultEncoding, tlvValue.DataBlock); userData.ExtractUserData(details, messageFeature == GSMSpecificFeatures.UDHI, offset); break; case (ushort)OptionalTags.SarMsgRefNum: tlvValue.PduDataType = PduDataTypes.UShort; tlvValue.Name = "SARReferenceNumber"; tlvValue.ValueUShort = SmppBuffer.BytesToShort(tlvValue.DataBlock, 0); break; case (ushort)OptionalTags.SarTotalSegments: tlvValue.PduDataType = PduDataTypes.Byte; tlvValue.Name = "SARTotalSegments"; tlvValue.ValueByte = tlvValue.DataBlock[0]; break; case (ushort)OptionalTags.SarSegmentSeqnum: tlvValue.PduDataType = PduDataTypes.Byte; tlvValue.Name = "SARSequenceNumber"; tlvValue.ValueByte = tlvValue.DataBlock[0]; break; } } } catch { } return(details); }