Beispiel #1
0
        private bool AuthenticationRequest()
        {
            _logger.LogDebug("SMS sending AUTHENTICATION_REQUEST start. SendId: {0}", SendId);

            int localPort = Send(ACKPacketFactory.AUTHENTICATION_REQUEST(SendId, Password));

            // If localport == 0 then sending error
            if (localPort == 0)
            {
                return(false);
            }

            // Get requvest
            string ret = Get(localPort);

            // if request error message
            if (ret.StartsWith(string.Format("ERROR {0}", SendId)))
            {
                ErrorMessage = "Authentication error!";
                _logger.LogWarning("SMS sending AUTHENTICATION_REQUEST error. SendId: {0} Return value: {1}", SendId, ret);
                return(false);
            }

            // if not request SEND message
            if (!ret.StartsWith(string.Format("SEND {0}", SendId)))
            {
                ErrorMessage = "Unknow Authentication error!";
                _logger.LogWarning("SMS sending AUTHENTICATION_REQUEST error. SendId: {0} Return value: {1}", SendId, ret);
                return(false);
            }

            _logger.LogDebug("SMS sending AUTHENTICATION_REQUEST sucessfully. SendId: {0}", SendId);

            return(true);
        }
Beispiel #2
0
        private bool BulkSmsRequest(string message)
        {
            _logger.LogDebug("SMS sending BULK_SMS_REQUEST start. SendId: {0}", SendId);

            int localPort = Send(ACKPacketFactory.BULK_SMS_REQUEST(SendId, message));

            // If localport == 0 then sending error
            if (localPort == 0)
            {
                return(false);
            }

            // get request
            string ret = Get(localPort);

            if (!ret.StartsWith(string.Format("PASSWORD {0}", SendId)))
            {
                ErrorMessage = "BULK_SMS_REQUEST error!";
                _logger.LogWarning("Bulk SMS BULK_SMS_REQUEST error. SendID: {0} Return value: {1}", SendId, ret);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return(false);
            }

            _logger.LogDebug("SMS sending BULK_SMS_REQUEST successfully. SendId: {0}", SendId);
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Extract registration packet
        /// </summary>
        /// <param name="data"></param>
        private void Registration(string data, string host, int port)
        {
            _logger.LogDebug("Start Registration processing");

            GoIpRegistrationPacket packet = new GoIpRegistrationPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("Received registration data authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK_MESSAGE(packet.req, 400), host, port);
                OnRegistration?.Invoke(this, new GoIpRegisterEventArgs("Authentication error!", packet, host, port, 400));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            if (string.IsNullOrEmpty(packet.imei))
            {
                _logger.LogInformation("Received SMS data without IMEI. packet id: {0}", packet.authid);
                Send(ACKPacketFactory.ACK_MESSAGE(packet.req, 400), host, port);
                OnRegistration?.Invoke(this, new GoIpRegisterEventArgs("No IMEI! (No SIM?)", packet, host, port, 400));
                return;
            }

            _logger.LogInformation("Received registration OK. Packet id: {0} IMEI: {1}", packet.authid, packet.imei);
            Send(ACKPacketFactory.ACK_MESSAGE(packet.req, 200), host, port);
            OnRegistration?.Invoke(this, new GoIpRegisterEventArgs("OK", packet, host, port, 400));
        }
Beispiel #4
0
        private void SubmitNumberRequest(string number, int telid)
        {
            _logger.LogDebug("SMS sending SUBMIT_NUMBER_REQUEST start. SendId: {0} TeliId: {1} Phone number: {2}",
                             SendId, telid, number);
            while (true)
            {
                int localPort = Send(ACKPacketFactory.SUBMIT_NUMBER_REQUEST(SendId, telid, number));

                // If localport == 0 then sending error
                if (localPort == 0)
                {
                    return;
                }

                // Get requvest
                string ret = Get(localPort);

                if (ret.StartsWith(string.Format("OK {0} {1}", SendId, telid)))
                {
                    _logger.LogInformation("SMS sending SUBMIT_NUMBER_REQUEST successfully. SendId: {0} TeliId: {1} Phone number: {2}", SendId, telid, number);
                    OnSmsSendMessage(this, new GoIpSendMessageEventArgs(number, SendId, "OK"));
                    break;
                }

                if (ret.StartsWith(string.Format("ERROR {0} {1}", SendId, telid)))
                {
                    _logger.LogWarning("SMS sending SUBMIT_NUMBER_REQUEST error. SendId: {0} TeliId: {1} Phone number: {2}", SendId, telid, number);
                    OnSmsSendMessage(this, new GoIpSendMessageEventArgs(number, SendId, "ERROR"));
                    break;
                }

                if (ret.StartsWith(string.Format("WAIT {0} {1}", SendId, telid)))
                {
                    _logger.LogInformation("SMS sending SUBMIT_NUMBER_REQUEST WAIT. SendId: {0} TeliId: {1} Phone number: {2}", SendId, telid, number);
                    OnSmsSendMessage(this, new GoIpSendMessageEventArgs(number, SendId, "WAIT"));
                }
                else
                {
                    _logger.LogDebug("SMS sending SUBMIT_NUMBER_REQUEST illegal operation. SendId: {0} TeliId: {1} Phone number: {2} Return value: {3}",
                                     SendId, telid, number, ret);
                }

                // Wait 3 second
                System.Threading.Thread.Sleep(3000);
            }

            _logger.LogDebug("SMS sending SUBMIT_NUMBER_REQUEST successfully.  SendId: {0} TeliId: {1} Phone number: {2}", SendId, telid, number);
            return;
        }
Beispiel #5
0
        private string GetCommand(string command, string logtext, bool needPassword = true)
        {
            // null Error message
            ErrorMessage = "";

            _logger.LogDebug("Start {0} func", logtext);
            int localPort = 0;

            if (needPassword)
            {
                localPort = Send(ACKPacketFactory.REQUEST(command, SendId, Password));
            }
            else
            {
                localPort = Send(ACKPacketFactory.SEND(command, SendId));
            }


            if (localPort == 0)
            {
                ErrorMessage = string.Format("{0} sending error!", logtext);
                return("");
            }

            // get request
            string ret = Get(localPort);

            if (ret.StartsWith(string.Format("ERROR {0}", SendId)))
            {
                ErrorMessage = ret.Substring(string.Format("ERROR {0} ", SendId).Length);
                _logger.LogWarning("{0} receive error. SendID: {1} Error message: {2}", logtext, SendId, ErrorMessage);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return("");
            }

            if (!ret.StartsWith(string.Format("{0} {1}", command, SendId)))
            {
                ErrorMessage = string.Format("{0} sending error!", logtext);
                _logger.LogWarning("{0} receive error. SendID: {1} Return value: {2}", logtext, SendId, ret);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return("");
            }


            _logger.LogDebug("End {0} func", logtext);
            return(ret.Substring(string.Format("{0} {1} ", command, SendId).Length));
        }
Beispiel #6
0
        /// <summary>
        /// Set GSM call forward
        /// </summary>
        /// <param name="ftime">timeout (second) of noreply forward type. Other types set to 0.</param>
        /// <param name="mode">enable or disable forward。3:enable,4:disable</param>
        /// <param name="num">forward to this number</param>
        /// <param name="reason">type of call forward. 0: unconditional,1: busy,2: noreply,3: noreachable, 4: all,5:busy,noreply,noreachable</param>
        /// <returns></returns>
        public bool SetGsmCallForward(string reason, string mode, string num, int ftime)
        {
            string s = SetCommand("CF", string.Format("{0} {1} {2} {3} {4}", Password, reason, mode, num, ftime.ToString()), "Set GSM call forward");

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            // null Error message
            ErrorMessage = "";

            _logger.LogDebug("Start {0} func", "Set GSM call forward");

            int localPort = Send(ACKPacketFactory.REQUEST("CF", SendId, Password, reason, mode, num, ftime.ToString()));

            if (localPort == 0)
            {
                ErrorMessage = string.Format("{0} sending error!", "Set GSM call forward");
                return(false);
            }

            // get request
            string ret = Get(localPort);

            if (ret.StartsWith(string.Format("CFERROR {0}", SendId)))
            {
                ErrorMessage = ret.Substring(string.Format("ERROR {0} ", SendId).Length);
                _logger.LogWarning("{0} receive error. SendID: {1} Error message: {2}", "Set GSM call forward", SendId, ErrorMessage);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return(false);
            }

            if (!ret.StartsWith(string.Format("{0} {1}", "CFOK", SendId)))
            {
                ErrorMessage = string.Format("{0} sending error!", "Set GSM call forward");
                _logger.LogWarning("{0} receive error. SendID: {1} Return value: {2}", "Set GSM call forward", SendId, ret);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return(false);
            }

            Send(ACKPacketFactory.SEND("DONE", SendId));

            _logger.LogDebug("End {0} func", "Set GSM call forward");
            return(true);
        }
Beispiel #7
0
        private void CellList(string data, string host, int port)
        {
            _logger.LogDebug("Start GoIp Cell list event");

            GoIpCellListPacket packet = new GoIpCellListPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("GoIp Cell list event authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("CELLS", packet.receiveid.ToString(), "Cell list event authentication error!"), host, port);
                OnCellListChanged?.Invoke(this, new GoIpCellListEvenetArgs("GoIp Cell list event authentication error!", packet.celllist, host, port));
                return;
            }

            _logger.LogInformation("Received GoIp Cell list event. ReceiveId: {0} Cell list: {1}", packet.receiveid, packet.celllist);

            Send(ACKPacketFactory.ACK("CELLS", packet.receiveid.ToString(), ""), host, port);
            OnCellListChanged?.Invoke(this, new GoIpCellListEvenetArgs("OK", packet.celllist, host, port));
        }
Beispiel #8
0
        private void ReceiveSms(string data, string host, int port)
        {
            _logger.LogDebug("Start SMS processing");

            GoIpMessagePacket packet = new GoIpMessagePacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("Received SMS data authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("RECEIVE", packet.receiveid.ToString(), "Authentication error!"), host, port);
                OnMessage?.Invoke(this, new GoIpMessageEventArgs("Receive SMS authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received SMS OK. ReceiveId: {0} Mobile: {1} Message: {2}", packet.receiveid, packet.Srcnum, packet.Message);

            Send(ACKPacketFactory.ACK("RECEIVE", packet.receiveid.ToString(), ""), host, port);
            OnMessage?.Invoke(this, new GoIpMessageEventArgs("OK", packet, host, port));
        }
Beispiel #9
0
        private void DeliverReport(string data, string host, int port)
        {
            _logger.LogDebug("Start SMS delivery report");

            GoIpSmsDeliveryReportPacket packet = new GoIpSmsDeliveryReportPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("Received SMS delivery report authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("DELIVER", packet.receiveid.ToString(), "Authentication error!"), host, port);
                OnDeliveryReport?.Invoke(this, new GoIpDeliveryReportEventArgs("Delivery report authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received SMS delivery report OK. ReceiveId: {0} Send number: {1} SMS no: {2}", packet.receiveid, packet.send_num, packet.sms_no);

            Send(ACKPacketFactory.ACK("DELIVER", packet.receiveid.ToString(), ""), host, port);
            OnDeliveryReport?.Invoke(this, new GoIpDeliveryReportEventArgs("OK", packet, host, port));
        }
Beispiel #10
0
        private void State(string data, string host, int port)
        {
            _logger.LogDebug("Start GoIp State");

            GoIpStatePacket packet = new GoIpStatePacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("GoIp state report authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("STATE", packet.receiveid.ToString(), "State authentication error!"), host, port);
                OnStateChange?.Invoke(this, new GoIpStateEventArgs("GoIp state authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received GoIp state. ReceiveId: {0} : Gsm state: {1}", packet.receiveid, packet.gsm_remain_state);

            Send(ACKPacketFactory.ACK("STATE", packet.receiveid.ToString(), ""), host, port);
            OnStateChange?.Invoke(this, new GoIpStateEventArgs("OK", packet, host, port));
        }
Beispiel #11
0
        private void RecordData(string data, string host, int port)
        {
            _logger.LogDebug("Start GoIp Record event");

            GoIpRecordPacket packet = new GoIpRecordPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("GoIp record event authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("RECORD", packet.receiveid.ToString(), "Record event authentication error!"), host, port);
                OnRecord?.Invoke(this, new GoIpRecordEventArgs("GoIp record event authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received GoIp record event. ReceiveId: {0} Send num: {1} Direction: {2}", packet.receiveid, packet.send_num, packet.direction);

            Send(ACKPacketFactory.ACK("RECORD", packet.receiveid.ToString(), ""), host, port);
            OnRecord?.Invoke(this, new GoIpRecordEventArgs("OK", packet, host, port));
        }
Beispiel #12
0
        private void HangupData(string data, string host, int port)
        {
            _logger.LogDebug("Start GoIp Hangup event");

            GoIpHangupPacket packet = new GoIpHangupPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("GoIp Hangup event authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("HANGUP", packet.receiveid.ToString(), "Hangup event authentication error!"), host, port);
                OnHangup?.Invoke(this, new GoIpHangupEventArgs("GoIp Hangup event authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received GoIp Hangup event. ReceiveId: {0} Number: {1} Cause: {2}", packet.receiveid, packet.num, packet.cause);

            Send(ACKPacketFactory.ACK("REMAIN", packet.receiveid.ToString(), ""), host, port);
            OnHangup?.Invoke(this, new GoIpHangupEventArgs("OK", packet, host, port));
        }
Beispiel #13
0
        private void ExpiryData(string data, string host, int port)
        {
            _logger.LogDebug("Start GoIp Expiry event");

            GoIpExpiryPacket packet = new GoIpExpiryPacket(data);

            // if auth error
            if (packet.authid != _options.AuthId || packet.password != _options.AuthPassword)
            {
                // TODO: log?
                _logger.LogInformation("GoIp Expiry event authentication error. Data: {0}", data);
                Send(ACKPacketFactory.ACK("EXPIRY", packet.receiveid.ToString(), "Expiry event authentication error!"), host, port);
                OnExpiry?.Invoke(this, new GoIpExpiryEventArgs("GoIp Expiry event authentication error!", packet, host, port));
                return;
            }

            packet.password = "";  // Delete password for security reasons

            _logger.LogInformation("Received GoIp Expiry event. ReceiveId: {0} Expiry: {1}", packet.receiveid, packet.exp);

            Send(ACKPacketFactory.ACK("EXPIRY", packet.receiveid.ToString(), ""), host, port);
            OnExpiry?.Invoke(this, new GoIpExpiryEventArgs("OK", packet, host, port));
        }