Example #1
0
        /// <summary> Called to create a PduBind object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> BindSm </returns>
        public static BindSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            BindSm bindSm = new BindSm(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(bindSm, ref offset);

                bindSm.SystemId = buf.ExtractCString(ref offset);
                bindSm.Password = buf.ExtractCString(ref offset);
                bindSm.SystemType = buf.ExtractCString(ref offset);
                bindSm.InterfaceVersion = buf.ExtractByte(ref offset);
                bindSm.AddrTon = buf.ExtractByte(ref offset);
                bindSm.AddrNpi = buf.ExtractByte(ref offset);
                bindSm.AddressRange = buf.ExtractCString(ref offset);
            }

            catch
            {
                bindSm = null;
            }

            return bindSm;
        }
Example #2
0
        /// <summary> Called to create a AlertNotification object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> AlertNotification </returns>
        public static AlertNotification Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            AlertNotification alertNotification = new AlertNotification(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(alertNotification, ref offset);

                alertNotification.SourceAddrTon = buf.ExtractByte(ref offset);
                alertNotification.SourceAddrNpi = buf.ExtractByte(ref offset);
                alertNotification.SourceAddr = buf.ExtractCString(ref offset);
                alertNotification.EsmeAddrTon = buf.ExtractByte(ref offset);
                alertNotification.EsmeAddrNpi = buf.ExtractByte(ref offset);
                alertNotification.EsmeAddr = buf.ExtractCString(ref offset);

                while (offset - start_offset < alertNotification.Length)
                {
                    alertNotification.Optional.Add(buf.ExtractTLV(ref offset));
                }
            }

            catch
            {
                alertNotification = null;
            }

            return alertNotification;
        }
Example #3
0
        /// <summary> Called to return the buffer of byte for this object </summary>
        /// <returns> A byte array </returns>
        public byte[] GetPDU()
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }
Example #4
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        byte[] IPacket.GetPDU()
        {
            // Create buffer and add header information
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            // Insert final length
            tmpBuff.AddFinalLength();

            // Return byte array
            return tmpBuff.Buffer;
        }
Example #5
0
        /// <summary> Called to create a new EnquireLink object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> EnquireLink </returns>
        public static EnquireLinkSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            EnquireLinkSm enquireLink = new EnquireLinkSm(defaultEncoding);

            try
            {
                buf.ExtractHeader(enquireLink, ref offset);
            }

            catch
            {
                enquireLink = null;
            }

            return enquireLink;
        }
Example #6
0
        /// <summary> Called to create a PduUnBind object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> PduUnBind </returns>
        public static UnBindSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            UnBindSm unBind = new UnBindSm(defaultEncoding);

            try
            {
                buf.ExtractHeader(unBind, ref offset);
            }

            catch
            {
                unBind = null;
            }

            return unBind;
        }
Example #7
0
        /// <summary> Called to create a GenericNack object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> GenericNack </returns>
        public static GenericNackSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            GenericNackSm genericNack = new GenericNackSm(defaultEncoding);

            try
            {
                buf.ExtractHeader(genericNack, ref offset);
            }

            catch
            {
                genericNack = null;
            }

            return genericNack;
        }
Example #8
0
        /// <summary> Called to create a QuerySm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> QuerySm </returns>
        public static QuerySm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            QuerySm querySm = new QuerySm(defaultEncoding);

            try
            {
                buf.ExtractHeader(querySm, ref offset);

                querySm.MessageId = buf.ExtractCString(ref offset);
                querySm.SourceTon = buf.ExtractByte(ref offset);
                querySm.SourceNpi = buf.ExtractByte(ref offset);
                querySm.SourceAddr = buf.ExtractCString(ref offset);
            }

            catch
            {
                querySm = null;
            }

            return querySm;
        }
Example #9
0
        /// <summary> Called to covnert the short message into a string </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="dataCoding"></param>
        /// <returns> string </returns>
        public string ShortMessageText(DataCodings defaultEncoding, DataCodings dataCoding)
        {
            SmppBuffer smppBuff = new SmppBuffer(defaultEncoding, ShortMessage);

            return smppBuff.ExtractEncodedString(dataCoding);
        }
Example #10
0
 /// <summary> Called to create a UserData object </summary>
 /// <param name="buf"></param>
 /// <param name="udhi"></param>
 /// <returns> UserData</returns>
 public static UserData Create(SmppBuffer buf, bool udhi)
 {
     return buf.ExtractUserData(udhi, 0);
 }
Example #11
0
        /// <summary> Called to add a user data header collection to the buffer </summary>
        /// <param name="userDataHeaderCollection"></param>
        public void AddUserDataHeaderCollection(UserDataHeaderCollection userDataHeaderCollection)
        {
            if (userDataHeaderCollection.Count > 0)
            {
                SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding);

                foreach (UserDataHeader header in userDataHeaderCollection)
                {
                    tmpBuff.AddUserDataHeader(header);
                }

                AddByte(Convert.ToByte(tmpBuff.Length));
                AddSmppBuffer(tmpBuff);
            }
        }
Example #12
0
        /// <summary> Called to add a user data object to the buffer </summary>
        /// <param name="userData"></param>
        public void AddUserData(UserData userData)
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding);

            if (userData.Headers.Count > 0)
            {
                tmpBuff.AddUserDataHeaderCollection(userData.Headers);
            }

            if ((userData.ShortMessage != null) && (userData.ShortMessage.Length > 0))
            {
                tmpBuff.AddBytes(userData.ShortMessage);
            }

            AddByte(Convert.ToByte(tmpBuff.Length));
            AddSmppBuffer(tmpBuff);
        }
Example #13
0
        /// <summary> Called to create a QuerySmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> QuerySmResp </returns>
        public static QuerySmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            QuerySmResp querySmResp = new QuerySmResp(defaultEncoding);

            try
            {
                buf.ExtractHeader(querySmResp, ref offset);

                querySmResp.MessageId = buf.ExtractCString(ref offset);
                querySmResp.FinalDateString = buf.ExtractCString(ref offset);
                querySmResp.MessageState = (MessageState) buf.ExtractByte(ref offset);
                querySmResp.ErrorCode = buf.ExtractByte(ref offset);
            }

            catch
            {
                querySmResp = null;
            }

            return querySmResp;
        }
Example #14
0
        /// <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("DefaultMessageId", 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;
        }
Example #15
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        public byte[] GetPDU()
        {
            // Create buffer and add header information
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            // Add properties
            tmpBuff.AddCString(ServiceType);
            tmpBuff.AddCString(MessageId);
            tmpBuff.AddByte(SourceTon);
            tmpBuff.AddByte(SourceNpi);
            tmpBuff.AddCString(SourceAddr);
            tmpBuff.AddByte(DestTon);
            tmpBuff.AddByte(DestNpi);
            tmpBuff.AddCString(DestAddr);

            // Insert final length
            tmpBuff.AddFinalLength();

            // Return byte array
            return tmpBuff.Buffer;
        }
Example #16
0
        /// <summary> Prepare SubmitSm instances for sending as wap push </summary>
        /// <param name="transactionId"></param>
        /// <param name="serviceType"></param>
        /// <param name="srcTon"></param>
        /// <param name="srcNpi"></param>
        /// <param name="srcAddr"></param>
        /// <param name="destTon"></param>
        /// <param name="destNpi"></param>
        /// <param name="destAddr"></param>
        /// <param name="url"></param>
        /// <param name="title"></param>
        /// <returns> A SubmitSm object </returns>
        public SubmitSm PrepareWapPush(byte transactionId, string serviceType, byte srcTon, byte srcNpi, string srcAddr, byte destTon,
                                       byte destNpi, string destAddr, string url, string title)
        {
            SubmitSm sp = null;

            SmppBuffer sb = new SmppBuffer(DefaultEncoding);

            sb.AddByte(transactionId);
            sb.AddByte(0x06);  //PDU Type: Push
            sb.AddByte(0x01);  //Header Length
            sb.AddByte(0xAE); // application/vnd.wap.sic 0x24 ^ 0x80

            // WAP Binary XML
            sb.AddByte(0x02);  //Version 1.2
            sb.AddByte(0x05);  //Public Identifier
            sb.AddByte(0x6a);  //Character Set: utf-8
            sb.AddByte(0x00);  //String table 0 bytes

            sb.AddByte(0x45);  //(.C) <si>
            sb.AddByte(0xc6);  //(AC) <indication

            string urlTmp = url;
            if (url.StartsWith("http://www."))
            {
                sb.AddByte(0x0d);
                urlTmp = url.Remove(0, "http://www.".Length);
            }
            else if (url.StartsWith("http://"))
            {
                sb.AddByte(0x0c);
                urlTmp = url.Remove(0, "http://".Length);
            }
            else if (url.StartsWith("https://www."))
            {
                sb.AddByte(0x0f);
                urlTmp = url.Remove(0, "https://www.".Length);
            }
            else if (url.StartsWith("https://"))
            {
                sb.AddByte(0x0e);
                urlTmp = url.Remove(0, "https://".Length);
            }
            else
            {
                sb.AddByte(0x0b);
            }

            string[] parts = Regex.Split(urlTmp, @"(\.com/|\.org/\.edu/|\.net/)");
            foreach (string part in parts)
            {
                if (part == ".com/")
                {
                    sb.AddByte(0x85);
                }
                else if (part == ".edu/")
                {
                    sb.AddByte(0x86);
                }
                else if (part == ".net/")
                {
                    sb.AddByte(0x87);
                }
                else if (part == ".org/")
                {
                    sb.AddByte(0x88);
                }
                else
                {
                    sb.AddEncodedString(part, DataCodings.Octets);
                }
            }

            sb.AddByte(0x07);  // action='signal-medium'
            sb.AddByte(0x01);  // END attribute list
            sb.AddEncodedString(title, DataCodings.Octets);

            sb.AddByte(0x01);  // END </indication>
            sb.AddByte(0x01);  // END </si>

            if (sb.Buffer.Length < 255 - 7)
            {
                sp = SubmitSm.Create(DefaultEncoding, serviceType, srcTon, srcNpi, srcAddr, destTon, destNpi, destAddr);

                sp.EsmClass = 0x40;
                sp.DataCoding = DataCodings.Class1ME8Bit;
                sp.ShortMessageBytes = sb.Buffer;

                sp.UserData.Headers.Add(
                    InformationElementIdentifiers.ApplicationPortAddressingScheme16bit,
                    new byte[] { 0x0b, 0x84, 0x23, 0xf0 } );
            }
            else
            {
                throw new ArgumentException("Message too large to send", "message_length");
            }

            return sp;
        }
Example #17
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        public byte[] GetPDU()
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddCString(SystemId);
            tmpBuff.AddCString(Password);
            tmpBuff.AddCString(SystemType);
            tmpBuff.AddByte(InterfaceVersion);
            tmpBuff.AddByte(AddrTon);
            tmpBuff.AddByte(AddrNpi);
            tmpBuff.AddCString(AddressRange);

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }
Example #18
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        public byte[] GetPDU()
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddCString(MessageId);
            tmpBuff.AddByte(SourceTon);
            tmpBuff.AddByte(SourceNpi);
            tmpBuff.AddCString(SourceAddr);

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }
Example #19
0
        /// <summary> Called to create a SubmitMultiResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> SubmitMultiResp </returns>
        public static SubmitMultiSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            SubmitMultiSmResp submitMultiResp = new SubmitMultiSmResp(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(submitMultiResp, ref offset);

                if (submitMultiResp.Length > Header.HEADER_LENGTH)
                {
                    submitMultiResp.MessageId = buf.ExtractCString(ref offset);
                    submitMultiResp.UnsuccessDestinationAddresses = buf.ExtractUnsuccessDestinationAddresses(ref offset);

                    while (offset - start_offset < submitMultiResp.Length)
                    {
                        submitMultiResp.Optional.Add(buf.ExtractTLV(ref offset));
                    }
                }
            }

            catch
            {
                submitMultiResp = null;
            }

            return submitMultiResp;
        }
Example #20
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        public byte[] GetPDU()
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddCString(MessageId);
            tmpBuff.AddCString(FinalDateString);
            tmpBuff.AddByte((byte) MessageState);
            tmpBuff.AddByte((byte) ErrorCode);

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }
Example #21
0
        /// <summary> Called to create a PduUnBindResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> PduUnBindResp </returns>
        internal static UnBindSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            UnBindSmResp res = new UnBindSmResp(defaultEncoding);

            try
            {
                buf.ExtractHeader(res, ref offset);
            }

            catch
            {
                res = null;
            }

            return res;
        }
Example #22
0
        /// <summary> Prepare SubmitMulti instances for sending with methods Submit or SubmitAsync </summary>
        /// <param name="mode"></param>
        /// <param name="serviceType"></param>
        /// <param name="srcTon"></param>
        /// <param name="srcNpi"></param>
        /// <param name="srcAddr"></param>
        /// <param name="destList"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <returns> SubmitMulti </returns>
        public SubmitMultiSm PrepareSubmit(SubmitMode mode, string serviceType, byte srcTon, byte srcNpi, string srcAddr, List<DestinationAddress> destList,
                                         DataCodings submitDataCoding, DataCodings encodeDataCoding, string message)
        {
            SubmitMultiSm submitMulti = null;

            if (!SmppBuffer.IsSupportedTextDataCoding(encodeDataCoding))
            {
                OnError(string.Format("Unsupported data coding [{0}]", encodeDataCoding));
                encodeDataCoding = DataCodings.Default;
            }

            // Standard 160 bytes
            int maxBytes = ShortMessageMaxBytes;
            if (encodeDataCoding == DataCodings.UCS2)
            {
                // Unicode message
                maxBytes = 140;
            }

            // Convert the message to a byte array
            byte[] messageBytes = new SmppBuffer(DefaultEncoding, message, encodeDataCoding).Buffer;

            switch (mode)
            {
                case SubmitMode.ShortMessage:
                    submitMulti = SubmitMultiSm.Create(DefaultEncoding, serviceType, srcTon, srcNpi, srcAddr, destList);
                    submitMulti.DataCoding = submitDataCoding;

                    if (messageBytes.Length > maxBytes)
                    {
                        List<byte> memory = new List<byte>(messageBytes);
                        submitMulti.ShortMessageBytes = memory.GetRange(0, 160).ToArray();
                    }
                    else
                    {
                        submitMulti.ShortMessageBytes = messageBytes;
                    }
                    break;

                case SubmitMode.Payload:
                    submitMulti = SubmitMultiSm.Create(DefaultEncoding, _SystemType, srcTon, srcNpi, srcAddr, destList);
                    submitMulti.DataCoding = submitDataCoding;
                    submitMulti.Optional.AddMessagePayload(messageBytes);
                    break;
            }

            return submitMulti;
        }
Example #23
0
        /// <summary> Prepare SubmitSm instances for sending with methods Submit or SubmitAsync </summary>
        /// <param name="mode"></param>
        /// <param name="serviceType"></param>
        /// <param name="srcTon"></param>
        /// <param name="srcNpi"></param>
        /// <param name="srcAddr"></param>
        /// <param name="destTon"></param>
        /// <param name="destNpi"></param>
        /// <param name="destAddr"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <returns> List SubmitSm </returns>
        public List<SubmitSm> PrepareSubmitLarge(SubmitMode mode, string serviceType, byte srcTon, byte srcNpi, string srcAddr, byte destTon, byte destNpi,
                                                 string destAddr, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message)
        {
            List<SubmitSm> submitSmList = new List<SubmitSm>();

            if (!SmppBuffer.IsSupportedTextDataCoding(encodeDataCoding))
            {
                OnError(string.Format("Unsupported data coding [{0}]", encodeDataCoding));
                encodeDataCoding = DataCodings.Default;
            }

            // Standard 160 bytes
            int maxBytes = ShortMessageMaxBytes;
            if (encodeDataCoding == DataCodings.UCS2)
            {
                // Unicode message
                maxBytes = 140;
            }

            // Convert the message to a byte array
            byte[] messageBytes = new SmppBuffer(DefaultEncoding, message, encodeDataCoding).Buffer;

            switch (mode)
            {
                case SubmitMode.ShortMessage:
                    if (messageBytes.Length <= maxBytes)
                    {
                        SubmitSm submitSm = SubmitSm.Create(DefaultEncoding, serviceType, srcTon, srcNpi, srcAddr, destTon, destNpi, destAddr);

                        submitSm.DataCoding = submitDataCoding;
                        submitSm.ShortMessageBytes = messageBytes;

                        submitSmList.Add(submitSm);
                    }
                    else
                    {
                        // Subtract 6 bytes for the UDHI header
                        maxBytes = maxBytes - 6;

                        if (encodeDataCoding == DataCodings.Default       ||
                            encodeDataCoding == DataCodings.ASCII         ||
                            encodeDataCoding == DataCodings.Latin1        ||
                            encodeDataCoding == DataCodings.Latin1Escape  ||
                            encodeDataCoding == DataCodings.DefaultFlashSMS)
                        {
                            maxBytes = Convert.ToInt32(Math.Floor(Convert.ToDouble(maxBytes) * 8 / 7));
                        }

                        byte messageReference = SequenceGenerator.ByteCounter;
                        int sequenceNumber = 1;

                        // Split the message in parts we can send
                        List<byte[]> parts = SmppBuffer.SplitMessageOnParts(messageBytes, maxBytes);

                        foreach (byte[] part in parts)
                        {
                            SubmitSm submitSm = SubmitSm.Create(DefaultEncoding, serviceType, srcTon, srcNpi, srcAddr, destTon, destNpi, destAddr);

                            submitSm.DataCoding = submitDataCoding;
                            submitSm.UserData.Headers.AddConcatenatedShortMessages8bit(DefaultEncoding, messageReference, Convert.ToByte(parts.Count), Convert.ToByte(sequenceNumber));
                            submitSm.ShortMessageBytes = part;
                            submitSmList.Add(submitSm);

                            sequenceNumber++;
                        }
                    }
                    break;

                case SubmitMode.Payload:
                    if (messageBytes.Length <= maxBytes)
                    {
                        SubmitSm submitSm = SubmitSm.Create(DefaultEncoding, _SystemType, srcTon, srcNpi, srcAddr, destTon, destNpi, destAddr);

                        submitSm.DataCoding = submitDataCoding;
                        submitSm.Optional.AddMessagePayload(messageBytes);

                        submitSmList.Add(submitSm);
                    }
                    else
                    {
                        // Subtract 6 bytes for the UDHI header
                        maxBytes = maxBytes - 6;

                        if (encodeDataCoding == DataCodings.Default       ||
                            encodeDataCoding == DataCodings.ASCII         ||
                            encodeDataCoding == DataCodings.Latin1        ||
                            encodeDataCoding == DataCodings.Latin1Escape  ||
                            encodeDataCoding == DataCodings.DefaultFlashSMS)
                        {
                            maxBytes = Convert.ToInt32(Math.Floor(Convert.ToDouble(maxBytes) * 8 / 7));
                        }

                        byte messageReference = SequenceGenerator.ByteCounter;
                        int sequenceNumber = 1;

                        // Split the message in parts we can send
                        List<byte[]> parts = SmppBuffer.SplitMessageOnParts(messageBytes, maxBytes);

                        foreach (byte[] part in parts)
                        {
                            SubmitSm submitSm = SubmitSm.Create(DefaultEncoding, serviceType, srcTon, srcNpi, srcAddr, destTon, destNpi, destAddr);

                            submitSm.DataCoding = submitDataCoding;

                            submitSm.Optional.AddSARReferenceNumber(Convert.ToUInt16(messageReference));
                            submitSm.Optional.AddSARSequenceNumber(Convert.ToByte(sequenceNumber));
                            submitSm.Optional.AddSARTotalSegments(Convert.ToByte(parts.Count));
                            submitSm.Optional.AddMoreMessagesToSend(sequenceNumber < parts.Count);
                            submitSm.Optional.AddMessagePayload(part);

                            submitSmList.Add(submitSm);

                            sequenceNumber++;
                        }
                    }
                    break;
            }

            // All messages need the same validity period
            foreach (SubmitSm submitSm in submitSmList)
            {
                submitSm.ValidityPeriod = DateTime.Now.AddDays(2).ToString("yyMMddhhmmss000+");
            }

            return submitSmList;
        }
Example #24
0
        /// <summary> Called to create a DeliverSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> DeliverSmResp </returns>
        public static DeliverSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            DeliverSmResp deliverSmResp = new DeliverSmResp(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(deliverSmResp, ref offset);

                if (deliverSmResp.Length > Header.HEADER_LENGTH)
                {
                    deliverSmResp.MessageId = buf.ExtractCString(ref offset);

                    while (offset - start_offset < deliverSmResp.Length)
                    {
                        deliverSmResp.Optional.Add(buf.ExtractTLV(ref offset));
                    }
                }
            }

            catch
            {
                deliverSmResp = null;
            }

            return deliverSmResp;
        }
Example #25
0
        /// <summary> Parses the smpp buffer to a DeliverSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> DeliverSm </returns>
        public static DeliverSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            DeliverSm deliverSm = new DeliverSm(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(deliverSm, ref offset);

                deliverSm.ServiceType = buf.ExtractCString(ref offset);
                deliverSm.SourceTon = buf.ExtractByte(ref offset);
                deliverSm.SourceNpi = buf.ExtractByte(ref offset);
                deliverSm.SourceAddr = buf.ExtractCString(ref offset);
                deliverSm.DestTon = buf.ExtractByte(ref offset);
                deliverSm.DestNpi = buf.ExtractByte(ref offset);
                deliverSm.DestAddr = buf.ExtractCString(ref offset);
                deliverSm.EsmClass = buf.ExtractByte(ref offset);
                deliverSm.ProtocolId = buf.ExtractByte(ref offset);
                deliverSm.PriorityFlag = buf.ExtractByte(ref offset);
                deliverSm.ScheduleDeliveryTime = buf.ExtractCString(ref offset);
                deliverSm.ValidityPeriod = buf.ExtractCString(ref offset);
                deliverSm.RegisteredDelivery = buf.ExtractByte(ref offset);
                deliverSm.ReplaceIfPresent = buf.ExtractByte(ref offset);
                deliverSm.DataCoding = (DataCodings) buf.ExtractByte(ref offset);
                deliverSm.DefaultMessageId = buf.ExtractByte(ref offset);
                deliverSm.ShortMessageLength = buf.ExtractByte(ref offset);

                if (deliverSm.ShortMessageLength > 0)
                {
                    deliverSm.UserDataBuffer = new SmppBuffer(defaultEncoding, buf.ExtractByteArray(ref offset, deliverSm.ShortMessageLength));
                }

                while (offset - start_offset < deliverSm.Length)
                {
                    deliverSm.Optional.Add(buf.ExtractTLV(ref offset));
                }

                if (deliverSm.ShortMessageLength == 0)
                {
                    if (deliverSm.Optional != null && deliverSm.Optional.Count > 0)
                    {
                        TLV tlv_payload = deliverSm.Optional[OptionalTags.MessagePayload];
                        if (tlv_payload != null)
                        {
                            deliverSm.UserDataBuffer = new SmppBuffer(defaultEncoding, tlv_payload.Value);
                        }

                        TLV tlv_globalSeq = deliverSm.Optional[OptionalTags.SarMsgRefNum];
                        if (tlv_globalSeq != null)
                        {
                            deliverSm.MessageReferenceNumber = SmppBuffer.BytesToShort(tlv_globalSeq.Value, 0);
                        }

                        TLV tlv_pocketsNumber = deliverSm.Optional[OptionalTags.SarTotalSegments];
                        if (tlv_pocketsNumber != null)
                        {
                            deliverSm.TotalSegments = tlv_pocketsNumber.Value[0];
                        }

                        TLV tlv_localSeq = deliverSm.Optional[OptionalTags.SarSegmentSeqnum];
                        if (tlv_localSeq != null)
                        {
                            deliverSm.SeqmentNumber = tlv_localSeq.Value[0];
                        }
                    }
                }

                if (deliverSm.UserDataBuffer != null && deliverSm.UserDataBuffer.Length > 0)
                {
                    bool hasUDHI = deliverSm.MessageFeature == GSMSpecificFeatures.UDHI || deliverSm.MessageFeature == GSMSpecificFeatures.UDHIandReplyPath;
                    deliverSm.UserData = UserData.Create(deliverSm.UserDataBuffer, hasUDHI);

                    if (deliverSm.UserData.Headers.Count > 0)
                    {
                        UserDataHeader udh = deliverSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessages8bit];
                        if (udh != null)
                        {
                            deliverSm.MessageReferenceNumber = udh.Data[0];
                            deliverSm.TotalSegments = udh.Data[1];
                            deliverSm.SeqmentNumber = udh.Data[2];
                        }

                        udh = deliverSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessage16bit];
                        if (udh != null)
                        {
                            deliverSm.MessageReferenceNumber = SmppBuffer.BytesToShort(udh.Data, 0);
                            deliverSm.TotalSegments = udh.Data[2];
                            deliverSm.SeqmentNumber = udh.Data[3];
                        }
                    }
                }
                else
                {
                    deliverSm.UserData = UserData.Create();
                }
            }

            catch
            {
                deliverSm = null;
            }

            return deliverSm;
        }
Example #26
0
 /// <summary> Called to add the buffer of another SmppBuffer </summary>
 /// <param name="smppBuffer"></param>
 public void AddSmppBuffer(SmppBuffer smppBuffer)
 {
     ListBuffer.AddRange(smppBuffer.Buffer);
 }
Example #27
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> A byte array </returns>
        public byte[] GetPDU()
        {
            if (UserData.Headers.Count > 0)
            {
                EsmClass |= 0x40;
            }

            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddCString(ServiceType);
            tmpBuff.AddByte(SourceTon);
            tmpBuff.AddByte(SourceNpi);
            tmpBuff.AddCString(SourceAddr);
            tmpBuff.AddByte(DestTon);
            tmpBuff.AddByte(DestNpi);
            tmpBuff.AddCString(DestAddr);
            tmpBuff.AddByte(EsmClass);
            tmpBuff.AddByte(ProtocolId);
            tmpBuff.AddByte(PriorityFlag);
            tmpBuff.AddTimeString(ScheduleDeliveryTime, 17);
            tmpBuff.AddTimeString(ValidityPeriod, 17);
            tmpBuff.AddByte(RegisteredDelivery);
            tmpBuff.AddByte(ReplaceIfPresent);
            tmpBuff.AddByte((byte) DataCoding);
            tmpBuff.AddByte(DefaultMessageId);
            tmpBuff.AddUserData(UserData);
            tmpBuff.AddTLVCollection(Optional);

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }
Example #28
0
        /// <summary> Called to create a CancelSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> CancelSmResp </returns>
        internal static CancelSmResp Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            CancelSmResp cancelSmResp = new CancelSmResp(defaultEncoding);

            try
            {
                buf.ExtractHeader(cancelSmResp, ref offset);
            }

            catch
            {
                cancelSmResp = null;
            }

            return cancelSmResp;
        }
Example #29
0
        /// <summary> Called to create a CancelSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> CancelSm </returns>
        internal static CancelSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            CancelSm cancelSm = new CancelSm(defaultEncoding);

            try
            {
                buf.ExtractHeader(cancelSm, ref offset);

                cancelSm.ServiceType = buf.ExtractCString(ref offset);
                cancelSm.MessageId = buf.ExtractCString(ref offset);
                cancelSm.SourceTon = buf.ExtractByte(ref offset);
                cancelSm.SourceNpi = buf.ExtractByte(ref offset);
                cancelSm.SourceAddr = buf.ExtractCString(ref offset);
                cancelSm.DestTon = buf.ExtractByte(ref offset);
                cancelSm.DestNpi = buf.ExtractByte(ref offset);
                cancelSm.DestAddr = buf.ExtractCString(ref offset);
            }

            catch
            {
                cancelSm = null;
            }

            return cancelSm;
        }
Example #30
0
        /// <summary> Called to return the PDU for this type of object </summary>
        /// <returns> byte[] </returns>
        public byte[] GetPDU()
        {
            SmppBuffer tmpBuff = new SmppBuffer(DefaultEncoding, this);

            tmpBuff.AddCString(MessageId);

            if (Optional.Count > 0)
            {
                tmpBuff.AddTLVCollection(Optional);
            }

            tmpBuff.AddFinalLength();

            return tmpBuff.Buffer;
        }