private void AnalyseSession()
        {
            string[] pairs     = trame.Split('/');
            string   DIR       = pairs[2];
            string   OPERATION = pairs[3];
            string   OAdC      = pairs[4];
            string   OTON      = pairs[5];
            string   ONPI      = pairs[6];
            string   STYP      = pairs[7];
            string   PWD       = System.Text.ASCIIEncoding.ASCII.GetString(EmiProtocol.HexStringToByteArray(pairs[8]));
            string   NPWD      = System.Text.ASCIIEncoding.ASCII.GetString(EmiProtocol.HexStringToByteArray(pairs[9]));
            string   VERS      = pairs[10];
            string   OPID      = pairs[14];

            viewAnalyse.Items.Add(new Variable("Direction", GetValueFrom(dirs, DIR)));
            viewAnalyse.Items.Add(new Variable("Operation", GetValueFrom(opers, OPERATION)));
            viewAnalyse.Items.Add(new Variable("OAdC - TCP/IP or abbreviated address,", OAdC));
            viewAnalyse.Items.Add(new Variable("OTON - Originator Type of Number", GetValueFrom(otons, OTON)));
            viewAnalyse.Items.Add(new Variable("ONPI - Originator Numbering Plan Id", GetValueFrom(onpis, ONPI)));
            viewAnalyse.Items.Add(new Variable("STYP - Subtype of operation", GetValueFrom(styps, STYP)));
            viewAnalyse.Items.Add(new Variable("PWD - Password", PWD));
            viewAnalyse.Items.Add(new Variable("NPWD - New Password", NPWD));
            viewAnalyse.Items.Add(new Variable("VERS - Version Number", VERS));
            viewAnalyse.Items.Add(new Variable("OPID - Originator Protocol Identifier:", GetValueFrom(opids, OPID)));
        }
        /// <summary>
        /// Fill the custom message viewer with the data provided
        /// </summary>
        /// <param name="message">The <see cref="T:Hummingbird.TestFramework.Messaging.Message" /> containing the Request, Response, or the Tag</param>
        public override void ParseMessage(Message message)
        {
            //Message.Tag is the RAW UCP message
            string tag = message.RequestText;
            var    obj = new EmiProtocol(tag, (EmiService.ReferredServer));

            ParseObject(obj);
        }
示例#3
0
        void InternalSendRequest(RequestData requestData)
        {
            AbstractMetadata requestMetadata = requestData.Metadata;
            object           requestObject   = requestData.Data;
            Message          message         = requestData.ReferencedMessage;

            message.Direction = MessageDirection.Outgoing;
            message.Status    = MessageStatus.Pending;
            EmiMessage mm = null;

            if (requestMetadata == MOMetadata)
            {
                SmsMo  request   = (SmsMo)requestObject;
                string messagemo = EmiProtocol.CreateMO(request.Sender, request.Receiver, request.MessageText, new DateTimeOffset(DateTime.Now), request.MessageFormat, MT.AlphaNumeric);
                mm = new EmiMessage
                {
                    CreateDate      = new DateTimeOffset(DateTime.Now),
                    Direction       = 0,
                    RAWMessage      = messagemo,
                    FriendlyMessage = $"SMS MO: {request.Sender} -> {request.Receiver} : {request.MessageText} ({request.MessageText.Length } chars)",
                    Type            = EmiMessageType.MO,
                    Message         = message
                };
                message.Title       = mm.FriendlyMessage;
                message.RequestText = mm.RAWMessage;
            }
            else if (requestMetadata == SRMetadata)
            {
                SmsSr  request   = (SmsSr)requestObject;
                string messagemo = EmiProtocol.CreateSR(request.OAdC, request.AdC, request.SCTS, request.Dst.ToString(), request.Rsn.ToString(), request.Text);
                mm = new EmiMessage
                {
                    CreateDate      = new DateTimeOffset(DateTime.Now),
                    Direction       = 0,
                    RAWMessage      = messagemo,
                    FriendlyMessage = $"SMS SR: {request.OAdC} -> {request.AdC} : {request.Text} ({request.Text.Length} chars)",
                    Type            = EmiMessageType.SR,
                    Message         = message
                };
                message.Title       = mm.FriendlyMessage;
                message.RequestText = mm.RAWMessage;
            }

            if (EmiService.Buffers.Count > 0)
            {
                EmiService.SendMOSRACK(mm, null);
            }
            else
            {
                message.Status       = MessageStatus.Failed;
                message.ErrorMessage = "You must have an active SMS Connection before sending SMS MO Messages.";
                throw new InvalidOperationException("You must have an active SMS Connection before sending SMS MO Messages.");
            }
        }
        private static void GetAdc(string AdC, string OAdC, out string sAdC, out string sOAdC)
        {
            sAdC  = AdC;
            sOAdC = OAdC;
            try
            {
                if (!int.TryParse(AdC, out int test))
                {
                    sAdC += " (Decoded value: " + EmiProtocol.GSM7HexToString(AdC.Substring(2)).Substring(0, int.Parse(AdC.Substring(0, 2), NumberStyles.HexNumber) * 8 / 14) + ")";
                }

                if (!int.TryParse(OAdC, out test))
                {
                    sOAdC += " (Decoded value: " + EmiProtocol.GSM7HexToString(OAdC.Substring(2)).Substring(0, int.Parse(OAdC.Substring(0, 2), NumberStyles.HexNumber) * 8 / 14) + ")";
                }
            }
            catch
            {
                //ignore error if there are errors
            }
        }
示例#5
0
        public void RunReceiver(object buffer)
        {
            MessageBuffers workingbuffer = (MessageBuffers)buffer;
            string         remoteaddress = workingbuffer.Connection.RemoteEndPoint.Address.ToString();

            while (workingbuffer.Running)
            {
                string msg = workingbuffer.ReadNextMessageIN();
                if (!string.IsNullOrEmpty(msg))
                {
                    //Response
                    EmiProtocol eo;
                    try
                    {
                        eo = new EmiProtocol(msg, ReferredServer);
                        string         operation = eo.OT;
                        string         response  = string.Empty;
                        string         SR        = string.Empty;
                        EmiMessageType MTType    = EmiMessageType.SYS;
                        EmiMessage     m2        = new EmiMessage();

                        if (operation != null)
                        {
                            if (eo.OT == "51")
                            {
                                MTType = EmiMessageType.MT;

                                if (!workingbuffer.AcceptsMT)
                                {
                                    response = eo.CreateACK51(false, "07", "Authentication failure");
                                }


                                //CHECK IF THE MT IS PING OR ACK?
                                string MSISDN = eo.AdC;
                                if (string.IsNullOrEmpty(MSISDN))
                                {
                                    MTType   = EmiMessageType.PING;
                                    m2.Type  = EmiMessageType.PING_ACK;
                                    response = eo.CreateACK51(false, "06", "AdC invalid");
                                }
                                else
                                {
                                    //HERE Check The return type
                                    switch (ReferredServer.mtBehavior)
                                    {
                                    case MTBehavior.ACK:
                                        response = eo.CreateACK51(true, string.Empty, string.Empty);
                                        m2.Type  = EmiMessageType.MT_ACK;

                                        //CHECK if SR is demanded
                                        if (ReferredServer.srActive)
                                        {
                                            SR = eo.CreateSRForMT(ReferredServer.srDst, ReferredServer.srRsn);
                                        }
                                        else
                                        {
                                            SR = string.Empty;
                                        }

                                        break;

                                    case MTBehavior.NACK:
                                        response = eo.CreateACK51(false, ReferredServer.nackCode.ToString(), string.Empty);
                                        m2.Type  = EmiMessageType.MT_NACK;
                                        break;

                                    case MTBehavior.Nothing:
                                        response = string.Empty;
                                        m2.Type  = EmiMessageType.SYS;
                                        break;
                                    }
                                }
                            }
                            else if (eo.OT == "52")
                            {
                                MTType   = EmiMessageType.MO_ACK;
                                response = string.Empty;
                            }
                            else if (eo.OT == "53")
                            {
                                MTType   = EmiMessageType.SR_ACK;
                                response = string.Empty;
                            }
                            else if (eo.OT == "60")
                            {
                                MTType   = EmiMessageType.SESSION;
                                response = eo.CreateACK60(true, string.Empty);
                                m2.Type  = EmiMessageType.SESSION_ACK;
                                workingbuffer.AcceptsMT = true;
                            }

                            //Add MT To Log

                            EmiMessage m = new EmiMessage
                            {
                                Type              = MTType,
                                Direction         = MessageDirection.Incoming,
                                CreateDate        = new DateTimeOffset(DateTime.Now),
                                RAWMessage        = msg,
                                EMIProtocolObject = eo
                            };

                            AbstractMetadata metadata = null;
                            if (m.Type == EmiMessageType.MT)
                            {
                                metadata = ReferredServer.MTMetadata;
                            }
                            else if (m.Type == EmiMessageType.SESSION)
                            {
                                metadata = ReferredServer.SSMetadata;
                            }


                            //Do not log if hidePingACK is true and MessageType is Ping or ACK.
                            if (!(ReferredServer.hidePingACK && (m.Type == EmiMessageType.PING || m.Type == EmiMessageType.MO_ACK || m.Type == EmiMessageType.SR_ACK)))
                            {
                                MessageQueue.Add(
                                    new Message()
                                {
                                    Metadata      = ReferredServer.MTMetadata,
                                    Title         = m.FriendlyMessage,
                                    Direction     = MessageDirection.Incoming,
                                    RequestObject = m.EMIProtocolObject,
                                    RequestText   = m.RAWMessage,
                                    Status        = MessageStatus.Received,
                                    Tag           = m.RAWMessage
                                });
                            }

                            if (response.StartsWith("\x02"))
                            {
                                //Add ACK/NACK to buffer:
                                m2.Direction         = 0;
                                m2.CreateDate        = new DateTimeOffset(DateTime.Now);
                                m2.RAWMessage        = response;
                                m2.EMIProtocolObject = new EmiProtocol(response);
                                lock (workingbuffer.MessageToBeSent)
                                {
                                    workingbuffer.MessageToBeSent.Enqueue(m2);
                                    Monitor.Pulse(workingbuffer.MessageToBeSent);
                                }



                                if (m2.Type == EmiMessageType.MT_ACK && !string.IsNullOrEmpty(SR))
                                {
                                    EmiMessage sr = new EmiMessage
                                    {
                                        Type              = EmiMessageType.SR,
                                        Direction         = 0,
                                        CreateDate        = new DateTimeOffset(DateTime.Now).AddSeconds(ReferredServer.srDelay),
                                        RAWMessage        = SR,
                                        ExpectedSendDate  = new DateTimeOffset(DateTime.Now).AddSeconds(ReferredServer.srDelay),
                                        EMIProtocolObject = new EmiProtocol(SR)
                                    };

                                    //Before we sent SR directly, like this ->
                                    //SendMOSRACK(sr)
                                    //Now we stock the SR to a queue, and there will be a thread who will look this queue.
                                    //With this method, the SR can be sent 5 or 10 seconds later.
                                    workingbuffer.SRToBeSent.Enqueue(sr);
                                }
                            }
                            else
                            {
                                //Log that nothing will be replied

                                /*
                                 * m2.Direction = 0
                                 * m2.CreateDate = new DateTimeOffset(DateTime.Now)
                                 * m2.RAWMessage = "Nothing has been sent for this MT"
                                 * lock(MainPage.Messages){
                                 *  MainPage.Messages.Add(m2)
                                 * }
                                 */
                            }
                            Thread.Sleep(10);
                        }
                    }
                    catch
                    {
                        //EMIProtocol is not valid
                    }
                }
                else
                {
                    Thread.Sleep(100); //If there is no MT to receive, sleep 10 milliseconds
                }
            }

            MessageQueue.Add(new Message()
            {
                Direction = MessageDirection.None,
                Status    = MessageStatus.Received,
                Title     = string.Format("SMSC: The client from {0} disconnected from this SMS Center", remoteaddress),
            });
            connections.Remove(workingbuffer.Connection);
            Buffers.Remove(workingbuffer);
        }
示例#6
0
        internal static string GetFriendlyMessage(string rawmessage)
        {
            string friendlyMessage = string.Empty;
            string op = "0";
            string to;
            string from;
            string direction = "O";

            try
            {
                string[] m = rawmessage.Split('/');
                op        = m[3];
                to        = m[4];
                from      = m[5];
                direction = m[2];
                string hexmessage = m[24];
                string message    = null;
                string XSER       = m[34];
                string MT4        = m[22];
                if (XSER.Contains("020108") || XSER.Contains("020109") || XSER.Contains("02010A") || XSER.Contains("02010B") || XSER.Contains("020118") || XSER.Contains("020119") || XSER.Contains("02011A") || XSER.Contains("02011B") || XSER.Contains("020128") || XSER.Contains("020129") || XSER.Contains("02012A") || XSER.Contains("02012B") || XSER.Contains("020138") || XSER.Contains("020139") || XSER.Contains("02013A") || XSER.Contains("02013B"))
                {
                    //Unicode
                    message = System.Text.UnicodeEncoding.BigEndianUnicode.GetString(EmiProtocol.Decode(hexmessage.ToCharArray()));
                }
                else
                {
                    //GSM8BIT / GSM7BIT
                    message = EmiProtocol.GSM8HexToString(hexmessage);
                }
                int shortcode;
                if (op == "51")
                {
                    if (int.TryParse(from, out shortcode))
                    {
                        if (m[5] != string.Empty)
                        {
                            friendlyMessage = string.Format("SMS: {0} -> {1} : {2} ({3} chars)", from, to, message, message.Length);
                        }
                    }
                    else
                    {
                        from = EmiProtocol.GSM7HexToString(from.Substring(2)).Substring(0, int.Parse(from.Substring(0, 2), NumberStyles.HexNumber) * 8 / 14);
                        if (m[5] != string.Empty)
                        {
                            friendlyMessage = string.Format("SMS: {0} -> {1} : {2} ({3} chars)", from, to, message, message.Length);
                        }
                    }
                }
                else
                {
                    if (int.TryParse(to, out shortcode))
                    {
                        if (m[5] != string.Empty)
                        {
                            friendlyMessage = string.Format("SMS: {0} -> {1} : {2} ({3} chars)", from, to, message, message.Length);
                        }
                    }
                    else
                    {
                        to = EmiProtocol.GSM7HexToString(to.Substring(2)).Substring(0, int.Parse(to.Substring(0, 2), NumberStyles.HexNumber) * 8 / 14);
                        if (m[5] != string.Empty)
                        {
                            friendlyMessage = string.Format("SMS: {0} -> {1} : {2} ({3} chars)", from, to, message, message.Length);
                        }
                    }
                }
            }
            catch
            {
                if (rawmessage[0] == '\x02')
                {
                    friendlyMessage = string.Empty;
                }
                else
                {
                    friendlyMessage = "SMS: " + rawmessage;
                }

                if (op == "60" && direction == "O")
                {
                    friendlyMessage = "SMS: Open Session Request";
                }
                else if (op == "60" && direction == "R")
                {
                    friendlyMessage = "SMS: Open Session Acknowledgment";
                }
                else if (op == "51" && direction == "R")
                {
                    friendlyMessage = "SMS: MT Acknowledgment";
                }
                else if (op == "51" && direction == "O")
                {
                    friendlyMessage = "SMS: Empty MT (Ping)";
                }
                else if (op == "52")
                {
                    friendlyMessage = "SMS: MO Acknowledgment";
                }
                else if (op == "53")
                {
                    friendlyMessage = "SMS: SR Acknowledgment";
                }
            }
            return(friendlyMessage);
        }
        private void AnalyseMT(string MT, int bit, string NMsg, string AMsg, string TMsg, string NB)
        {
            string decodedMsg = string.Empty;

            switch (MT)
            {
            case "2":
                viewAnalyse.Items.Add(new Variable("NMsg", NMsg));
                decodedMsg = NMsg;
                break;

            case "3":
                viewAnalyse.Items.Add(new Variable("AMsg", AMsg));
                decodedMsg = AMsg;
                break;

            case "4":
                viewAnalyse.Items.Add(new Variable("NB - No. of bits in Transparent Data (TD) message", NB));
                viewAnalyse.Items.Add(new Variable("TMsg", TMsg));
                decodedMsg = TMsg;
                break;
            }

            if (bit == 16)
            {
                viewAnalyse.Items.Add(new Variable("  (Decoded 16 bit Message)", System.Text.UnicodeEncoding.BigEndianUnicode.GetString(EmiProtocol.Decode(decodedMsg.ToCharArray()))));
            }
            else if (bit == 7)
            {
                viewAnalyse.Items.Add(new Variable("  (Decoded compressed 7 bit Message)", EmiProtocol.GSM7HexToString(decodedMsg)));
            }
            else
            {
                viewAnalyse.Items.Add(new Variable("  (Decoded 8 bit (uncompressed 7 bit) Message)", EmiProtocol.GSM8HexToString(decodedMsg)));
            }
        }
        private void ParseObject(object o)
        {
            EmiProtocol eo = (EmiProtocol)o;

            trame            = eo.OriginalTrame;
            txtTrameEMI.Text = trame;
            try
            {
                string operation = eo.OT;

                if (operation != null)
                {
                    if (eo.OT == "51")
                    {
                        if (eo.OR == "O")
                        {
                            messageType = EmiMessageType.MT;
                        }
                        else
                        {
                            messageType = EmiMessageType.MT_ACK;
                        }

                        //CHECK IF THE MT IS PING OR ACK?
                        string MSISDN = eo.AdC;
                        if (string.IsNullOrEmpty(MSISDN))
                        {
                            if (eo.OR == "O")
                            {
                                messageType = EmiMessageType.PING;
                            }
                            else
                            {
                                messageType = EmiMessageType.PING_ACK;
                            }
                        }
                    }
                    else if (eo.OT == "52")
                    {
                        if (eo.OR == "O")
                        {
                            messageType = EmiMessageType.MO;
                        }
                        else
                        {
                            messageType = EmiMessageType.MO_ACK;
                        }
                    }
                    else if (eo.OT == "53")
                    {
                        if (eo.OR == "O")
                        {
                            messageType = EmiMessageType.SR;
                        }
                        else
                        {
                            messageType = EmiMessageType.SR_ACK;
                        }
                    }
                    else if (eo.OT == "60")
                    {
                        if (eo.OR == "O")
                        {
                            messageType = EmiMessageType.SESSION;
                        }
                        else
                        {
                            messageType = EmiMessageType.SESSION_ACK;
                        }
                    }

                    Analyse();
                }
            }
            catch
            {
                viewAnalyse.Items.Add(new Variable("Error", "Your EMI frame is not valid"));
            }
        }