Example #1
0
        private void OnCallIncoming(int call, int call2replace, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
        {
            _Logger.Debug("Nueva llamada entrante [SrdId={0}] [SrcIp={1}] [SrcSubId={2}] [SrcRs={3}] [DstId={4}] [DstIp={5}] [DstSubId={6}]",
                          inInfo.SrcId, inInfo.SrcIp, inInfo.SrcSubId, inInfo.SrcRs, inInfo.DstId, inInfo.DstIp, inInfo.DstSubId);

            Top.WorkingThread.Enqueue("OnCallIncoming", delegate()
            {
                CORESIP_Answer answer = new CORESIP_Answer(SipAgent.SIP_NOT_FOUND);
                string dstId          = string.IsNullOrEmpty(inInfo.DstSubId) ? inInfo.DstId : inInfo.DstSubId;

                foreach (StrNumeroAbonado alias in Top.Cfg.HostAddresses)
                {
                    if (string.Compare(dstId, alias.NumeroAbonado, true) == 0)
                    {
                        answer.Value = SipAgent.SIP_DECLINE;

                        switch (info.Type)
                        {
                        case CORESIP_CallType.CORESIP_CALL_DIA:
                            General.SafeLaunchEvent(IncomingTlfCall, this, call, call2replace, info, inInfo, answer);
                            break;

                        case CORESIP_CallType.CORESIP_CALL_IA:
                            General.SafeLaunchEvent(IncomingLcCall, this, call, info, inInfo, answer);
                            break;

                        case CORESIP_CallType.CORESIP_CALL_GG_MONITORING:           //ULISES solo soporta G/G monitoring
                            General.SafeLaunchEvent(IncomingMonitoringCall, this, call, info, inInfo, answer);
                            break;

                        case CORESIP_CallType.CORESIP_CALL_MONITORING:
                        case CORESIP_CallType.CORESIP_CALL_AG_MONITORING:
                            answer.Value = SipAgent.SIP_BAD_REQUEST;                //ULISES solo soporta G/G monitoring
                            break;
                        }

                        break;
                    }
                }
                try
                {
                    if (answer.Value == SipAgent.SIP_MOVED_TEMPORARILY)
                    {
                        SipAgent.MovedTemporallyAnswerCall(call, answer.redirectTo, "unconditional");
                    }
                    else if (answer.Value != 0 && answer.Value != SipAgent.SIP_DECLINE)
                    {
                        SipAgent.AnswerCall(call, answer.Value);
                    }
                }
                catch (Exception exc)
                {
                    _Logger.Error("SipAgent.AnswerCall", exc.Message);
                }
            });
        }
Example #2
0
        /// <summary>
        /// Fill de data structure for an AID Position
        /// Search for resource in configuration if exist or create from scratch
        /// </summary>
        /// <param name="info"></param>
        /// <param name="inInfo"></param>
        /// <returns></returns>
        public bool FillData(CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
        {
            CfgEnlaceInterno link    = new CfgEnlaceInterno();
            string           literal = null;

            CfgRecursoEnlaceInterno rs = Top.Cfg.GetResourceFromUri(inInfo.SrcId, inInfo.SrcIp, inInfo.SrcSubId, inInfo.SrcRs);

            if (rs != null)
            {
                _UnknownResource = false;
                //El literal, es el display name que procede del SIP o el numero en su defecto
                TlfManager.ExtractIaInfo(rs, out literal, out _NumberWithPrefix);
                _Logger.Debug("Incoming: {0} {1} {2} lit {3} numbPre {4}", rs.Prefijo, rs.NumeroAbonado, rs.NombreRecurso, literal, _NumberWithPrefix);
            }
            else      // para que funcionen llamadas entrantes no configuradas de transito de un SCV
            {
                rs = Top.Cfg.GetATSResourceFromUri(inInfo.SrcId);
                if (rs != null)
                {
                    _UnknownResource = true;
                    //El literal, es el display name que procede del SIP o el numero en su defecto
                    TlfManager.ExtractIaInfo(rs, out literal, out _NumberWithPrefix);
                }
            }
            if (rs == null)
            //No encuentro configurado el recurso
            {
                rs                = new CfgRecursoEnlaceInterno();
                rs.Prefijo        = Cd40Cfg.UNKNOWN_DST;
                rs.NombreRecurso  = inInfo.SrcId;
                rs.NumeroAbonado  = string.Format("sip:{0}@{1}", inInfo.SrcId, inInfo.SrcIp);
                _UnknownResource  = true;
                _NumberWithPrefix = string.Format("{0:D2}{1}", rs.Prefijo, inInfo.SrcId);
                literal           = inInfo.SrcId;
            }
            if (!PermisoRed((uint)rs.Prefijo, true))
            {
                return(false);
            }


            if (!String.IsNullOrEmpty(inInfo.DisplayName))
            {
                literal = inInfo.DisplayName;
            }

            link.Literal = literal;
            link.ListaRecursos.Add(rs);
            link.Prioridad = Top.Cfg.Priority;
            link.OrigenR2  = Top.Cfg.GetNumeroAbonado(Top.Cfg.MainId, Cd40Cfg.ATS_DST) ?? Top.Cfg.MainId;

            Reset(link);

            return(true);
        }
Example #3
0
 private void OnIncomingCall(object sender, int call, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo, CORESIP_Answer answer)
 {
     foreach (LcPosition lc in _LcPositions)
     {
         answer.Value = lc.HandleIncomingCall(call, info, inInfo);
         if (answer.Value != SipAgent.SIP_DECLINE)
         {
             break;
         }
     }
 }
Example #4
0
        private void OnTransferRequest(int call, CORESIP_CallInfo info, CORESIP_CallTransferInfo transferInfo)
        {
            Debug.Assert(info.Type == CORESIP_CallType.CORESIP_CALL_DIA);
            _Logger.Debug("Nueva peticion de transferencia [CallId={0}] [DstId={1}] [DstIp={2}] [DstSubId={3}] [DstRs={4}]",
                          call, transferInfo.DstId, transferInfo.DstIp, transferInfo.DstSubId, transferInfo.DstRs);

            Top.WorkingThread.Enqueue("OnTransferRequest", delegate()
            {
                CORESIP_Answer answer = new CORESIP_Answer(SipAgent.SIP_DECLINE);
                General.SafeLaunchEvent(TlfTransferRequest, this, call, info, transferInfo, answer);

                if (answer.Value != 0)
                {
                    SipAgent.TransferAnswer(transferInfo.TsxKey, transferInfo.TxData, transferInfo.EvSub, answer.Value);
                }
            });
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sipCallId"></param>
        /// <param name="info"></param>
        /// <param name="inInfo"></param>
        /// <returns></returns>
        public int HandleIncomingCall(int sipCallId, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
        {
            SipCallInfo inCall = SipCallInfo.NewIncommingCall(_Channels, sipCallId, info, inInfo, false);

            if (inCall != null)
            {
                if ((Top.ScreenSaverEnabled) || Top.Hw.LCSpeaker == false)
                {
                    return(SipAgent.SIP_DECLINE);
                }
                // Si la telefonía va por altavoz y hay llamada de LC se quita
                // el estado "en espera de cuelgue"
                if (Top.Mixer.RxTlfAudioVia == TlfRxAudioVia.Speaker)
                {
                    Top.Tlf.SetHangToneOff();
                }
                MakeHangUpRx();
                RxState = LcRxState.Idle;

                if ((_ActiveRx != null) || ((_ActiveTx != null) && (_ActiveTx != this)))
                {
                    // Notificamos el Mem y lo borramos
                    _OldRxState = _RxState;
                    RxState     = LcRxState.Mem;
                    _RxState    = LcRxState.Idle;

                    return(SipAgent.SIP_BUSY);
                }
                else
                {
                    _SipCallRx = inCall;
                    _ActiveRx  = this;

                    _Channels.Sort(delegate(SipChannel a, SipChannel b)
                    {
                        return(b.First.CompareTo(a.First));
                    }
                                   );

                    return(SipAgent.SIP_OK);
                }
            }

            return(SipAgent.SIP_DECLINE);
        }
Example #6
0
        public override int HandleIncomingCall(int sipCallId, int call2replace, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
        {
            int ret = SipAgent.SIP_DECLINE;

            if (inInfo.SrcId == _Literal)
            {
                //it's for me
                _ActiveState = true;
                ret          = base.HandleIncomingCall(sipCallId, call2replace, info, inInfo);
                //Esta comprobación no se hace porque a veces la CORESIP pierde el NOTIFY del "deleted"
                //TODO Pendiente de hacer cuando se resuelva la CORESIP
                if (!_Subscribed)
                {
                    SipAgent.CreateConferenceSubscription(_SipCall.Ch.AccId, _SipCall.Ch.Uri);
                    _Subscribed = true;
                }
            }
            return(ret);
        }
Example #7
0
        private void OnCallState(int call, CORESIP_CallInfo info, CORESIP_CallStateInfo stateInfo)
        {
            switch (info.Type)
            {
            case CORESIP_CallType.CORESIP_CALL_DIA:
                if ((stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_CONFIRMED) ||
                    (stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_DISCONNECTED) ||
                    ((stateInfo.Role == CORESIP_CallRole.CORESIP_CALL_ROLE_UAC) &&
                     (stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_EARLY)))
                {
                    Top.WorkingThread.Enqueue("DIAStateChanged", delegate()
                    {
                        General.SafeLaunchEvent(TlfCallStateChanged, this, call, stateInfo);
                    });
                }
                break;

            case CORESIP_CallType.CORESIP_CALL_IA:
                if ((stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_CONFIRMED) ||
                    (stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_DISCONNECTED))
                {
                    Top.WorkingThread.Enqueue("IAStateChanged", delegate()
                    {
                        General.SafeLaunchEvent(LcCallStateChanged, this, call, stateInfo);
                    });
                }
                break;

            case CORESIP_CallType.CORESIP_CALL_MONITORING:
            case CORESIP_CallType.CORESIP_CALL_GG_MONITORING:
            case CORESIP_CallType.CORESIP_CALL_AG_MONITORING:
                if ((stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_CONFIRMED) ||
                    (stateInfo.State == CORESIP_CallState.CORESIP_CALL_STATE_DISCONNECTED))
                {
                    Top.WorkingThread.Enqueue("MonitoringStateChanged", delegate()
                    {
                        General.SafeLaunchEvent(MonitoringCallStateChanged, this, call, stateInfo);
                    });
                }
                break;
            }
        }
Example #8
0
        private void OnCallState(int call, CORESIP_CallInfo info, CORESIP_CallStateInfo stateInfo)
        {
            _log.From().Trace("OnCallState {0}, {1}, {2}", call, stateInfo.State, stateInfo.LastCode);
            switch (stateInfo.State)
            {
            case CORESIP_CallState.CORESIP_CALL_STATE_DISCONNECTED:
                SipAgentEvent?.Invoke(SipAgentEvents.CallDisconnected, call, "", null);
                break;

            case CORESIP_CallState.CORESIP_CALL_STATE_CONFIRMED:
                SipAgentEvent?.Invoke(SipAgentEvents.CallConnected, call, "", null);
                break;

            case CORESIP_CallState.CORESIP_CALL_STATE_INCOMING:
            case CORESIP_CallState.CORESIP_CALL_STATE_CALLING:
            case CORESIP_CallState.CORESIP_CALL_STATE_CONNECTING:
            case CORESIP_CallState.CORESIP_CALL_STATE_EARLY:
            case CORESIP_CallState.CORESIP_CALL_STATE_NULL:
                break;
            }
        }
Example #9
0
        private void OnIncomingMonitoringCall(object sender, int call, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo, CORESIP_Answer answer)
        {
            Debug.Assert(!_Froms.ContainsKey(call));
            TlfIaPosition from = new TlfIaPosition(1000);

            int code = from.HandleIncomingCall(call, -1, info, inInfo);

            Debug.Assert(code == SipAgent.SIP_RINGING);

            if (!from.IsTop)
            {
                answer.Value = SipAgent.SIP_NOT_ACCEPTABLE_HERE;
                return;
            }

            answer.Value             = 0;
            from.TlfPosStateChanged += OnFromMonitoringCallStateChanged;
            _Froms[call]             = from;

            General.SafeLaunchEvent(RemoteListenChanged, this, new ListenPickUpMsg(FunctionState.Executing, from.Literal, call));
        }
Example #10
0
 public override bool IsForMe(CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
 {
     return(inInfo.SrcId == _Literal);
 }
Example #11
0
        public override int HandleIncomingCall(int sipCallId, int call2replace, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
        {
            bool replacedCall = false;

            if ((Top.ScreenSaverEnabled) || (Top.Mixer.RxTlfAudioVia == TlfRxAudioVia.Speaker && !Top.Hw.LCSpeaker))
            {
                return(SipAgent.SIP_DECLINE);
            }

            if ((call2replace >= 0) && (CallId == call2replace))
            {
                MakeHangUp(SipAgent.SIP_GONE);
                replacedCall = true;
            }

            if ((info.Priority == CORESIP_Priority.CORESIP_PR_EMERGENCY) &&
                ((Top.Cfg.Permissions & Permissions.Intruded) == Permissions.Intruded) && (_SipCall != null))
            {
                if (_State == TlfState.Out)
                {
                    //En teclas de 19+1,  se admiten llamada con los datos que no coincidan con configuracion
                    SipCallInfo inCall = SipCallInfo.NewIncommingCall(_Channels, sipCallId, info, inInfo, true);

                    if (inCall != null)
                    {
                        if (((int)inCall.Priority < (int)_SipCall.Priority) ||
                            ((inCall.Priority == _SipCall.Priority) && (string.Compare(inInfo.SrcIp, Top.SipIp) < 0)))
                        {
                            _CallTout.Enabled = false;
                            SipAgent.HangupCall(_SipCall.Id);

                            _SipCall = inCall;
                            CORESIP_CallFlags flags = Settings.Default.EnableEchoCanceller &&
                                                      (_SipCall.Ch.Prefix == Cd40Cfg.PP_DST || (_SipCall.Ch.Prefix >= Cd40Cfg.RTB_DST && _SipCall.Ch.Prefix < Cd40Cfg.EyM_DEST)) ?
                                                      CORESIP_CallFlags.CORESIP_CALL_EC : CORESIP_CallFlags.CORESIP_CALL_NO_FLAGS;

                            return(SipAgent.SIP_OK | ((int)flags << 16));
                        }
                    }
                }

                if (EfectivePriority != CORESIP_Priority.CORESIP_PR_EMERGENCY && info.Priority != CORESIP_Priority.CORESIP_PR_EMERGENCY)
                {
                    MakeHangUp(0);
                }
            }

            if ((_SipCall == null) && !InOperation())                   // && PermisoRed((uint)(((SipChannel)inCall.Ch).Type),true))
            {
                if (FillData(info, inInfo) == false)
                {
                    return(SipAgent.SIP_DECLINE);
                }
            }
            int result = base.HandleIncomingCall(sipCallId, call2replace, info, inInfo);

            //Si no se acepta llamada entrante y se trataba de un replace que ya se ha colgado, se señaliza con error
            if (replacedCall &&
                ((result == SipAgent.SIP_DECLINE) || (result == SipAgent.SIP_BUSY)))
            {
                State = TlfState.Busy;
            }
            return(result);
        }
Example #12
0
 private void OnCallIncoming(int call, int call2replace, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo)
 {
     _log.From().Trace("OnCallIncoming {0}, {1}", call, inInfo.DstId);
     SipAgentEvent?.Invoke(SipAgentEvents.IncomingCall, call, inInfo.DstId, null);
 }
Example #13
0
        public static SipCallInfo NewIncommingCall(IEnumerable <SipChannel> channels, int callId, CORESIP_CallInfo info, CORESIP_CallInInfo inInfo, bool findNoConfigured)
        {
            SipPath    path    = null;
            SipChannel channel = null;

            foreach (SipChannel ch in channels)
            {
                ch.First = false;
            }

            foreach (SipChannel ch in channels)
            {
                path = ch.FindPath(inInfo.SrcId, inInfo.SrcIp, inInfo.SrcSubId, inInfo.SrcRs);
                if (path != null)
                {
                    channel = ch;
                    break;
                }
            }
            //Si no se encuentra path en todos los canales,
            //se hace una busqueda sin comparar con el recurso.
            if ((path == null) && (findNoConfigured))
            {
                foreach (SipChannel ch in channels)
                {
                    path = ch.FindPathNoConfigured(inInfo.SrcId, inInfo.SrcSubId);
                    if (path != null)
                    {
                        channel = ch;
                        break;
                    }
                }
            }
            if (path != null)
            {
                channel.First = true;
                return(new SipCallInfo(callId, inInfo.DstId, inInfo.SrcId, info.Priority, info.Type, channel, path.Remote, path.Line));
            }

            return(null);
        }