LibIms_Steps.ttcn 79.5 KB
Newer Older
						v_sipUrl.components.sip.userInfo := {userOrTelephoneSubscriber:="", password:=omit};
						v_sipUrl.components.sip.hostPort := {host := PX_IMS_SUT_PCSCF1_HOME_DOMAIN, portField :=PX_IMS_SUT_PCSCF1_PORT}
						}						
						
				// following setting is used in relation to the route headers list elements
				case (c_interfaceSIPURL_IMS_SUT_PCSCF1_domain) {
						v_sipUrl.components.sip.userInfo := {userOrTelephoneSubscriber:="", password:=omit};
						v_sipUrl.components.sip.hostPort := {host := PX_IMS_SUT_PCSCF1_HOME_DOMAIN, portField :=PX_IMS_SUT_PCSCF1_PORT}
						}						
				case (c_interfaceSIPURL_IMS_SUT_PCSCF1_ip) {
						v_sipUrl.components.sip.userInfo := {userOrTelephoneSubscriber:="", password:=omit};
						v_sipUrl.components.sip.hostPort := {host := PX_IMS_SUT_PCSCF1_IPADDR, portField :=PX_IMS_TS_SCSCF_PORT}
						}						
                case (c_interfaceProfile_IMS_SUT_SCSCF) {
                        v_sipUrl.components.sip.userInfo := {userOrTelephoneSubscriber:="", password:=omit};
                        v_sipUrl.components.sip.hostPort := {host := PX_IMS_TS_SCSCF_HOME_DOMAIN, portField :=PX_IMS_SUT_PCSCF1_PORT}
                        }
				case (c_conferenceProfile_factoryURI) {
        				v_sipUrl.components.sip.userInfo := {userOrTelephoneSubscriber:=PX_IMS_SUT_CONF_FACTORY_NAME, password:=omit};
        				v_sipUrl.components.sip.hostPort := {host := PX_IMS_SUT_CONF_HOME_DOMAIN, portField := omit}
					}						
			if(p_user == c_serviceProfile_EMERGENCY or p_user == c_serviceProfile_EMERGENCY_INVALID)
				{return(v_urnUrl)}
			else
				{return(v_sipUrl)}
		 * @desc sets user parameters with PIXIT values
		 * @param p_user identifies the selected user configuration and location
		 * @verdict 
		 */
		function f_init_interfaceprofile(in integer p_interface) runs on ImsComponent
		{
			select(p_interface){
				case (c_interfaceProfile_IMS_SUT_IBCF1) { //variant c_interfaceProfile_IMS_SUT_IBCF1
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_IBCF1_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_IBCF1_IPADDR;	
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_IBCF1_HOME_DOMAIN;	
				}
				case (c_interfaceProfile_IMS_SUT_IBCF2) { //variant c_interfaceProfile_IMS_SUT_IBCF2
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_IBCF2_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_IBCF2_IPADDR;	
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_IBCF2_HOME_DOMAIN;
				}
				case (c_interfaceProfile_IMS_SUT_PCSCF1) { //variant c_interfaceProfile_IMS_SUT_PCSCF1
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_PCSCF1_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_PCSCF1_IPADDR;	
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_PCSCF1_HOME_DOMAIN;
				}
				case (c_interfaceProfile_IMS_SUT_PCSCF2) { //variant c_interfaceProfile_IMS_SUT_PCSCF2
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_PCSCF2_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_PCSCF2_IPADDR;	
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_PCSCF2_HOME_DOMAIN;
				}
				case (c_interfaceProfile_IMS_SUT_PCSCF) { //variant c_interfaceProfile_IMS_SUT_PCSCF
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_PCSCF_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_PCSCF_IPADDR;
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_PCSCF_HOME_DOMAIN;	
				}
				case (c_interfaceProfile_IMS_SUT_SCSCF) { //variant c_interfaceProfile_IMS_SUT_SCSCF
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_SCSCF_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_SCSCF_IPADDR;	
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_SCSCF_HOME_DOMAIN;				
				}
				case (c_interfaceProfile_IMS_SUT_ICSCF) { //variant c_interfaceProfile_IMS_SUT_ICSCF
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_ICSCF_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_ICSCF_IPADDR;		
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_ICSCF_HOME_DOMAIN;
				}
				case (c_interfaceProfile_IMS_SUT_MGCF) { //variant c_interfaceProfile_IMS_SUT_MGCF
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_IMGCF_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_IMGCF_IPADDR;		
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_IMGCF_HOME_DOMAIN;
				}
				case (c_interfaceProfile_IMS_SUT_AS) { //variant c_interfaceProfile_IMS_SUT_AS
				vc_interfaceprofile.SUTPort := PX_IMS_SUT_AS_PORT;
				vc_interfaceprofile.SUTIpaddr := PX_IMS_SUT_AS_IPADDR;		
				vc_interfaceprofile.SUTHomeDomain := PX_IMS_SUT_AS_HOME_DOMAIN;
				}
		}	
		
        /*
         * 
         * @desc retrieves user DomainPort value of the interface profile
         * @param p_interface identifies the selected interface
         * @return DomainPort template 
         */
        function f_get_userDomainPort (in SipUserProfile p_userProfile) runs on ImsComponent return /*template*/ HostPort
        {
                return {p_userProfile.homeDomain, p_userProfile.currPort}
        }
		 * @desc retrieves HostPort value of the interface profile
		 * @param p_interface identifies the selected interface
		 * @return HostPort template 
		 */
		function f_get_interfaceHostPort (in ImsInterfaceProfile p_interface) runs on ImsComponent return /*template*/ HostPort // STS commented out template but check why in there in first place
		{
				return {p_interface.SUTIpaddr,p_interface.SUTPort}
		}	
		
		/*
		 * 
		 * @desc retrieves DomainPort value of the interface profile
		 * @param p_interface identifies the selected interface
		 * @return DomainPort template 
		 */
		function f_get_interfaceDomainPort (in ImsInterfaceProfile p_interface) runs on ImsComponent return /*template*/ HostPort
		{
				return {p_interface.SUTHomeDomain,p_interface.SUTPort}
		}	
		
		/*
		 * @desc retrieves SipUrl of the interface profile
		 * @param p_interface identifies the selected interface
		 * @return SipUrl template 
		 */
		function f_get_interfaceNameAddr(in ImsInterfaceProfile p_interface) runs on ImsComponent return template NameAddr
		{
				return mw_SipUrl_SUTinterface(p_interface.SUTIpaddr,p_interface.SUTPort)
		}		
		
		
	}
	group registration {

		/**
		 * 
		 * @desc  registration and authentication with MD5
		 * @param p_cSeq_s		cseq parameter 
		 * @param p_auth		flag indicating if authentication is needed
		 */
		function f_Registration_IMS(inout CSeq p_cSeq_s, in boolean p_auth) runs on SipComponent
		{
			f_setHeaders_REGISTER(p_cSeq_s);
			f_SendREGISTER(m_REGISTER_Request_IMS(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via_REG, vc_contact, m_add_Authorization_digest(vc_authorization,{c_Integrity_protected_no}))); //LibSip
		
			//awaiting of 401 and sending 2nd REGISTER and awaiting 200 OK REGISTER
			if (p_auth)
			{
			  // receiving 401 Unauthorized response.
			  // and Re-send REGISTER request with Authorization header
			  tc_ack.start(PX_SIP_TACK);
			  alt
			  {
				[] SIPP.receive	(mw_Response_Base(c_statusLine401, vc_callId, p_cSeq_s)) -> value vc_response
				  {
					tc_ack.stop;
					// set headers via, cseq and authorization
					f_setHeaders_2ndREGISTER(p_cSeq_s);
					f_SendREGISTER(m_REGISTER_Request_IMS(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via_REG, vc_contact, m_add_Authorization_digest(vc_authorization,{c_Integrity_protected_yes}))); //LibSip
	            
					// awaiting 200 OK REGISTER
					f_awaitingOkResponse(p_cSeq_s);
					f_getServiceRouteMapIntoRouteInRegistration(p_cSeq_s, vc_response);
				  }
				[] SIPP.receive	(mw_Response_Base(c_statusLine200, vc_callId, p_cSeq_s))
				  {
					tc_ack.stop;
					log ("Authorization was not requested as expected");
					setverdict(inconc)
				  }
			  }
			}
			else
			{
			  f_awaitingOkResponse(p_cSeq_s);
			  f_getServiceRouteMapIntoRouteInRegistration(p_cSeq_s, vc_response);
			};
		}//end function f_Registration_IMS

		/**
		 * 
		 * @desc  awaiting UE1 registration (with authentication)
		 * @param p_cSeq_s		cseq parameter 
		 */
		function f_awaitingRegistration_IMS(inout CSeq p_cSeq_s) runs on ImsComponent
		var SipUrl v_passociated_url;
		var Authorization p_authorization;
		//Awaiting 1st REGISTER	
		f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);

		// 401 response
		f_sendResponse(m_Response_WWWauthenticate_IMS(c_statusLine401,
			vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via,
			m_wwwAuthenticate(f_calculatecChallenge_forWWWAuthorization
									(PX_IMS_SUT_UE1_QOP,vc_authorization.body[0].digestResponse)))
			);

		//Awaiting 2nd REGISTER	with authorization header
		f_awaitingREGISTER(mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse((c_Integrity_protected_yes,c_Integrity_protected_ip_assoc_pending)))));

		// 200OK to complete the request
		vc_contact := vc_request.msgHeader.contact;
		vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires",int2str(3600)}};
		v_passociated_url := vc_caller_From.addressField.nameAddr.addrSpec;
		f_sendResponse(m_Response_2xxonREGISTER_IMS(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact,f_initSipUrl(c_userProfile_SCSCFwithHomeUE),v_passociated_url));

		}//end function f_awaitingRegistration_IMS

		/**
		 * 
		 * @desc  awaiting UE1 registration (with authentication)
		 * @param p_cSeq_s		cseq parameter 
		 */
		function f_awaitingRegistration_IMS_gm(inout CSeq p_cSeq_s) runs on ImsComponent
		{
            var SipUrl v_passociated_url;
            var Authorization p_authorization;
            vc_ignore_subscribe := true;//handle SUBSCRIBE during the call
    		//Awaiting 1st REGISTER	
    		f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);
    
    		// 401 response
    		f_sendResponse(m_Response_WWWauthenticate_IMS(c_statusLine401,
    			vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via,
    			m_wwwAuthenticate(f_calculatecChallenge_forWWWAuthorization
    									(PX_IMS_SUT_UE1_QOP,vc_authorization.body[0].digestResponse)))
    			);
    
    		//Awaiting 2nd REGISTER	with authorization header
            f_awaitingREGISTER(mw_REGISTER_authorizedRequest_wo_securityheaders_IMS);
    		//f_awaitingREGISTER(mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse((c_Integrity_protected_yes,c_Integrity_protected_ip_assoc_pending)))));
    
    		// 200OK to complete the request
    		vc_contact := vc_request.msgHeader.contact;
    		vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires",int2str(3600)}};
    		v_passociated_url := vc_caller_From.addressField.nameAddr.addrSpec;
    		f_sendResponse(m_Response_2xxonREGISTER_IMS(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact,f_initSipUrl(c_userProfile_SCSCFwithHomeUE),v_passociated_url));
rennoch's avatar
rennoch committed
            vc_DeregDone := false; 
		}//end function f_awaitingRegistration_IMS_gm


	/**
	 * 
	 * @desc remove registration
	 * @param p_cSeq_s cseq parameter
	 */	
	function f_RemoveRegistration_IMS(inout CSeq p_cSeq) runs on SipComponent
	{
	  var CommaParam_List v_challenge;
	  var Credentials v_credentials;
	  var template REGISTER_Request v_request;
	  
	  if (PX_SIP_REGISTRATION)
	  {
		f_setHeaders_deREGISTER(p_cSeq);
		v_request := m_REGISTER_Request_expires_IMS(vc_requestUri, vc_callIdReg,
		p_cSeq,  vc_from, vc_to, vc_via, vc_contact, vc_authorization, "0");
		v_request.msgHeader.route := f_route();
		
		f_SendREGISTER(v_request);
		if (PX_SIP_REGISTER_AUTHENTICATION_ENABLED)
		{
			// receiving 401 Unauthorized response.
			// and Re-send REGISTER request with Authorization header
			tc_ack.start(PX_SIP_TACK);
			alt
			{
			  [] SIPP.receive	(mw_Response_Base(c_statusLine401, vc_callIdReg, p_cSeq)) -> value vc_response
				{
				  tc_ack.stop;
				  // set headers via, cseq and authorization
				  f_setHeaders_2ndREGISTER(p_cSeq);
					v_request := m_REGISTER_Request_expires_IMS(vc_requestUri, vc_callIdReg,
					p_cSeq,  vc_from, vc_to, vc_via, vc_contact, vc_authorization, "0");
					v_request.msgHeader.route := f_route();
				  // Re-send protected REGISTER
				  f_SendREGISTER(v_request);//LibSip
				  
				  // awaiting 200 OK REGISTER
				  f_awaitingResponse(mw_Response_Base(c_statusLine200, vc_callIdReg, p_cSeq));
				}
			  [] SIPP.receive	(mw_Response_Base(c_statusLine200, vc_callIdReg, p_cSeq))-> value vc_response
				{
        			tc_ack.stop;
        			f_setHeadersOnReceiptOfResponse(vc_cSeq, vc_response);
        			log ("Authorization was not requested as expected");
				}
			}
		}
		else
		{
		  f_awaitingResponse(mw_Response_Base(c_statusLine200, vc_callIdReg, p_cSeq));
		}
	  }
	} // end f_RemoveRegistration_IMS
		

	} // end group registration
	
	group preambles {
		
		/*
		 * 
		 * @desc  Sets variables and default initialization for user profile where proxy role is present
		 * @param p_userprofile	user profile of call
		 * @param p_cSeq_s 		cseq parameter
		 */
		function f_IMS_preamble_MGCF(in integer p_userprofile, inout CSeq p_cSeq_s)  runs on ImsComponent
		{
			vc_boo_recordRoute := true;
			vc_boo_route := true;
			f_init_interfaceprofile(c_interfaceProfile_IMS_SUT_MGCF);
			
			f_IMS_preamble_woRegistration(p_userprofile, p_cSeq_s);
		}
		
		/*
		 * 
		 * @desc  Sets variables and default initialization for user profile
		 * @param p_userprofile	user profile of call
		 * @param p_cSeq_s 		cseq parameter
		 */
		function f_IMS_preamble_woRegistration(in integer p_userprofile, inout CSeq p_cSeq_s)  runs on ImsComponent
		{
			// avoid deregistration in default behavior
			vc_DeregDone := true; 
			vc_boo_route := true;
   			vc_boo_recordRoute := true;
		 
			//Variables & defaults initialization
			LibSip_Steps.f_init_component(p_cSeq_s);

			//Preamble
rennoch's avatar
rennoch committed
			f_init_userprofile(p_userprofile); // assignment of PIXIT values to component variable
			vc_sdp_local := valueof(m_SDP_bandwidth(valueof(m_media_dynPT(PX_SIP_SDP_dyn, PX_SIP_SDP_encoding)), vc_userprofile));
			vc_contact := valueof(m_Contact(m_SipUrl_contactIpaddr(vc_userprofile)));
		*
		* @desc  Sets variables and default initialization for user profile and handle registration and authentication with MD5 
		* @param p_userprofile   	user profile of call
		* @param p_cSeq_s		  	cseq parameter
		* @param p_register		register template
		*/
		function f_IMS_preamble_withRegistration (in integer p_userprofile, in integer p_interface, inout CSeq p_cSeq_s, template REGISTER_Request p_register) runs on ImsComponent

            f_init_interfaceprofile(p_interface);
			//Variables & defaults initialization
			f_IMS_preamble_woRegistration(p_userprofile, p_cSeq_s);
	
			//Preamble
			f_Registration(p_cSeq_s, p_register, PX_SIP_REGISTER_AUTHENTICATION_ENABLED);

			//	deregistration in case of successful registration
			vc_DeregDone := false;
						
			f_setHeaders_SUBSCRIBE(p_cSeq_s);
			f_Subscription(p_cSeq_s, m_SUBSCRIBE_Request_UE(vc_requestUri, vc_callId, p_cSeq_s, vc_from, vc_to, vc_via, vc_contact, vc_route_REG));

		 * 
		 * @desc  Sets variables and default initialization for user profile and handle registration and authentication with MD5 
		 *			(basic registration template)
		 * @param p_userprofile   	user profile of call
		 * @param p_cSeq_s		  	cseq parameter
		function f_IMS_preamble_withRegistrationBasic (in integer p_userprofile,in integer p_interface, inout CSeq p_cSeq_s) runs on ImsComponent
            f_init_interfaceprofile(p_interface);		
			//Variables & defaults initialization
			f_IMS_preamble_woRegistration(p_userprofile, p_cSeq_s);
	
			//Preamble
   			f_Registration_IMS(p_cSeq_s, PX_SIP_REGISTER_AUTHENTICATION_ENABLED);
			f_setHeaders_SUBSCRIBE(p_cSeq_s);
			f_Subscription(p_cSeq_s, m_SUBSCRIBE_Request_UE(vc_requestUri, vc_callId, p_cSeq_s, vc_from, vc_to, vc_via, vc_contact, vc_route_REG));
		}		

        /*
         * 
         * @desc  Sets variables and default initialization for user profile and handle registration and authentication with MD5 
         *			(basic registration template)
         * @param p_userprofile   	user profile of call
         * @param p_cSeq_s		  	cseq parameter
         */
        function f_IMS_preamble_AS (in integer p_userprofile, in integer p_interface, inout CSeq p_cSeq_s) runs on ImsComponent
        {
            // avoid deregistration in default behavior
            vc_DeregDone := true; 
            vc_boo_route := true;
            vc_boo_recordRoute := true;
            vc_cSeq := p_cSeq_s;
	
            //Defaults
            vc_def_catchSyncStop := activate(a_Sip_catchSyncStop());
            vc_default := activate (a_altstep_AS());

            //Preamble
            f_init_interfaceprofile(p_interface);
            f_init_userprofile(p_userprofile); // assignment of PIXIT values to component variable
            vc_sdp_local := valueof(m_SDP_bandwidth(valueof(m_media_dynPT(PX_SIP_SDP_dyn, PX_SIP_SDP_encoding)), vc_userprofile));
            vc_contact := valueof(m_Contact(m_SipUrl_contactIpaddr(vc_userprofile)));
        }			
		
	} // end group preambles
	
	group postambles {
		/*
		*
		* @desc  Sets variables and default initialization for user profile and handle deregistration
		* @param p_cSeq_s		  	cseq parameter
		*/
	 	function f_IMS_postamble_withDeRegistration (CSeq p_CSeq) runs on ImsComponent {
	 		f_RemoveRegistration(p_CSeq); // TODO check if applicable for IMS
	 		
    		f_terminate_component();
	 	}
	 
        /*
        *
        * @desc  Sets variables and default initialization for user profile and handle deregistration on AS as TS
        * @param p_cSeq_s		  	cseq parameter
        */
        function f_IMS_postamble_AS_withDeRegistration (boolean p_deRegistration) runs on ImsComponent {
            
            if(p_deRegistration == true)
                {f_awaitingREGISTER_sendReply(mw_REGISTER_Request_Base,true);}
            f_terminate_component();
        }
		
		function f_SIP_postamble_IMS1_withoutRegistration () runs on ImsComponent
		{f_terminate_component()};
			
		function f_IMS_postamble_withoutDeRegistration () runs on ImsComponent
		{f_terminate_component()};
  
  		function f_SIP_postamble_IMS1_awaitDeRegistration () runs on ImsComponent
		{
			var SipUrl v_passociated_url;
			//Awaiting 1st REGISTER	
			f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);

			// 401 response
			f_sendResponse(m_Response_WWWauthenticate_IMS(c_statusLine401,
				vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via,
				m_wwwAuthenticate(f_calculatecChallenge_forWWWAuthorization
										(PX_IMS_SUT_UE1_QOP,vc_authorization.body[0].digestResponse)))
				);

			//Awaiting 2nd REGISTER	with authorization header
			f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);//mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse(c_Integrity_protected_yes))));
//			f_awaitingREGISTER(mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse(c_Integrity_protected_yes))));
//			vc_contact := vc_request.msgHeader.contact;
//			vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires",int2str(0)}};
			v_passociated_url := vc_caller_From.addressField.nameAddr.addrSpec;
			f_sendResponse(m_Response_2xxonREGISTER_IMS(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact,f_initSipUrl(c_userProfile_SCSCFwithHomeUE),v_passociated_url));

			f_terminate_component()
		};
		
  		function f_IMS_postamble_awaitDeRegistration () runs on ImsComponent
		{	
			var SipUrl v_passociated_url;
			//Awaiting 1st REGISTER
  	
			f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);

			// 401 response
			f_sendResponse(m_Response_WWWauthenticate_IMS(c_statusLine401,
				vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via,
				m_wwwAuthenticate(f_calculatecChallenge_forWWWAuthorization
										(PX_IMS_SUT_UE1_QOP,vc_authorization.body[0].digestResponse)))
				);

			//Awaiting 2nd REGISTER	with authorization header
			f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);//mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse(c_Integrity_protected_yes))));

			// 200OK to complete the request
//			vc_contact := vc_request.msgHeader.contact;
//			vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires",int2str(0)}};
			v_passociated_url := vc_caller_From.addressField.nameAddr.addrSpec;
			f_sendResponse(m_Response_2xxonREGISTER_IMS(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact,f_initSipUrl(c_userProfile_SCSCFwithHomeUE),v_passociated_url));
		
        function f_IMS_awaitDeRegistration () runs on ImsComponent
        {	
            var SipUrl v_passociated_url;
            //Awaiting 1st REGISTER
  	
            f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);

            // 401 response
            f_sendResponse(m_Response_WWWauthenticate_IMS(c_statusLine401,
                vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via,
                m_wwwAuthenticate(f_calculatecChallenge_forWWWAuthorization
                                        (PX_IMS_SUT_UE1_QOP,vc_authorization.body[0].digestResponse)))
                );

            //Awaiting 2nd REGISTER	with authorization header
            f_awaitingREGISTER(mw_REGISTER_unauthorizedRequest_IMS);//mw_REGISTER_authorizedRequest_IMS(m_Authorization_digest(mw_digestResponse(c_Integrity_protected_yes))));

            // 200OK to complete the request
//          vc_contact := vc_request.msgHeader.contact;
//          vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires",int2str(0)}};
            v_passociated_url := vc_caller_From.addressField.nameAddr.addrSpec;
            f_sendResponse(m_Response_2xxonREGISTER_IMS(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact,f_initSipUrl(c_userProfile_SCSCFwithHomeUE),v_passociated_url));
        };

		function f_SIP_postamble_UE1_withoutRegistration () runs on ImsComponent
		{f_terminate_component()};
			
		function f_SIP_postamble_UE2_withoutRegistration () runs on ImsComponent
		{f_terminate_component()};
		
		/**
		 * 
		 * @desc sends BYE and awaits response
		 * @param p_CallId parameter for outgoing BYE
		 * @param p_cSeq parameter for outgoing BYE
		 * @param p_from parameter for outgoing BYE
		 * @param p_to parameter for outgoing BYE
		 * @param p_reqHostPort parameter for outgoing BYE
		 */
		function f_terminateCall_IMS(SipUrl p_requestUri, CallId p_CallId, inout CSeq p_cSeq, From p_from,
		  template To p_to) runs on ImsComponent
		{
          LibSip_Steps.f_setHeadersBYE(p_cSeq);
		  // Sending of a BYE request to release the call and expect a final response
		  f_SendBYE(m_BYE_Request_IMS(p_requestUri, p_CallId, p_cSeq, p_from, valueof(p_to), vc_via, vc_route));
      
		  tc_resp.start(PX_SIP_TRESP);
		  alt
		  {
			[] SIPP.receive	(mw_Response_Base(mw_statusLine1xx, p_CallId, p_cSeq))
			  {
				repeat;
			  }
			[] SIPP.receive	(mw_Response_Base(mw_statusLineFinal, p_CallId, p_cSeq))
			  {
				tc_resp.stop;
			  }
			// timeout should be handled in default_alt_step
		  }
		} // end function f_terminateCall
		
		
		/**
		 * 
		 * @desc  sends BYE and awaits response
		 * @param p_CallId parameter for outgoing BYE
		 * @param p_cSeq parameter for outgoing BYE
		 * @param p_from parameter for outgoing BYE
		 * @param p_to parameter for outgoing BYE
		 * @param p_reqHostPort parameter for outgoing BYE
		 */
		function f_terminateCall_UE(SipUrl p_requestUri, CallId p_CallId, inout CSeq p_cSeq, From p_from,
garciay's avatar
garciay committed
		  template To p_to, template RecordRoute p_recordRoute := omit) runs on ImsComponent
poglitsch's avatar
poglitsch committed
		  LibSip_Steps.f_setHeadersBYE(p_cSeq);
		  // Sending of a BYE request to release the call and expect a final response
garciay's avatar
garciay committed
		  if(ispresent(p_recordRoute)) {
		    var Route v_route := { ROUTE_E, valueof(p_recordRoute.routeBody)};
		  	f_SendBYE(m_BYE_Request_UE(p_requestUri, p_CallId, p_cSeq, p_from, valueof(p_to), vc_via, v_route));
		  } else {
		  	f_SendBYE(m_BYE_Request_UE(p_requestUri, p_CallId, p_cSeq, p_from, valueof(p_to), vc_via, vc_route));
		  }
		  
		  tc_resp.start(PX_SIP_TRESP);
		  alt
		  {
			[] SIPP.receive	(mw_Response_Base(mw_statusLine1xx, p_CallId, p_cSeq))
			  {
				repeat;
			  }
			[] SIPP.receive	(mw_Response_Base(mw_statusLineFinal, p_CallId, p_cSeq))
			  {
				tc_resp.stop;
			  }
			// timeout should be handled in default_alt_step
		  }
		} // end function f_terminateCall_UE
		
		
        /**
         * 
         * @desc  sends BYE and awaits response and De-registration
         * @param p_CallId parameter for outgoing BYE
         * @param p_cSeq parameter for outgoing BYE
         * @param p_from parameter for outgoing BYE
         * @param p_to parameter for outgoing BYE
         * @param p_reqHostPort parameter for outgoing BYE
         */
        function f_terminateCall_UE_withDeReg(SipUrl p_requestUri, CallId p_CallId, inout CSeq p_cSeq, From p_from,
          template To p_to) runs on ImsComponent
        {
          LibSip_Steps.f_setHeadersBYE(p_cSeq);
          // Sending of a BYE request to release the call and expect a final response
          f_SendBYE(m_BYE_Request_UE(p_requestUri, p_CallId, p_cSeq, p_from, valueof(p_to), vc_via, vc_route));
      
          tc_resp.start(PX_SIP_TRESP);
          alt
          {
            [] SIPP.receive	(mw_Response_Base(mw_statusLine1xx, p_CallId, p_cSeq))
              {
                repeat;
              }
            [] SIPP.receive	(mw_Response_Base(mw_statusLineFinal, p_CallId, p_cSeq))
              {
                tc_resp.stop;
              }
            // timeout should be handled in default_alt_step
          };
          action("Please de-register");          
          f_IMS_awaitDeRegistration();
          //f_terminate_component();
        } // end function f_terminateCall_UE_withDeReg
		
        altstep a_clearRegistration_IMSuser() runs on ImsComponent
rennoch's avatar
rennoch committed
        {
            var Response v_response;
            var Request v_request;
		 
            [] any timer.timeout 
            {
                setverdict(fail); 
                all timer.stop; 
                //TODO check how to solve release of call 
                //f_SendCANCEL(m_CANCEL_Request(vc_callId, vc_cSeq, vc_from, vc_cancel_To, vc_reqHostPort, vc_via )); // difference between registration state or transaction state
                vc_callId := vc_callIdReg;
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
            }
            // allow repeated INVITEs
            [vc_ignore_invite] SIPP.receive(mw_INVITE_Request_Base)
            {
              repeat
            }
		
            // allow repeated BYEs after ack of the first BYE
            [vc_ignore_bye] SIPP.receive (mw_BYE_Request_Base(?))
            {
              repeat
            }
            [] SIPP.receive (mw_ACK_Request_Base(?))
            {
                repeat
            }
            // allow 100 replies
            [] SIPP.receive(mw_Response_Base(c_statusLine100,?, ?))
              {
                repeat
              }
			  
            //	ignore 181 if flag is set (following TS 183004 §4.5.2.1)		  
            [vc_ignore181] SIPP.receive(mw_Response_Base(c_statusLine181,vc_callId, vc_cSeq))-> value v_response sender vc_sent_label
              { 
                f_setHeadersOnReceiptOfResponse(v_response.msgHeader.cSeq, v_response); 
                repeat;
              } 
	  
            // according to SIP chap.8.1.3.2
            [] SIPP.receive(mw_Response_Base(c_statusLine183,vc_callId, vc_cSeq))
              { 
                repeat;
              } 

            // ignore 484 if flag is set
            [vc_ignore484] SIPP.receive(mw_Response_Base(c_statusLine484,vc_callId, vc_cSeq))
                {
                  repeat
                }
		
            [vc_ignore4xx] SIPP.receive(mw_Response_Base(mw_statusLine4xx,vc_callId, ?))-> value v_response sender vc_sent_label
              { 
                f_setHeadersOnReceiptOfResponse(v_response.msgHeader.cSeq, v_response); 
                f_SendACK(m_ACK_Request_route(vc_requestUri, vc_callId, v_response.msgHeader.cSeq, vc_from, vc_to, vc_via, vc_route));
                repeat
              }			
		
            [vc_ignore200OKinv] SIPP.receive(mw_Response_Base(c_statusLine200, vc_callId, ?))
              { 
                repeat
              }
	
            [] SIPP.receive(mw_INFO_Request_Base(vc_callId))->value v_request sender vc_sent_label
              { 
                f_setHeadersOnReceiptOfRequest(v_request); 
                f_send200OK();
                repeat
              }
		  
            // awaiting of Notify
            [] SIPP.receive(mw_NOTIFY_Request_Base(vc_callId))->value v_request sender vc_sent_label
              { 
                f_setHeadersOnReceiptOfRequest(v_request); 
                f_send200OK();
                repeat
              }
            // awaiting of subscribe from UE
            [vc_ignore_subscribe] SIPP.receive(mw_SUBSCRIBE_Request_Base)-> value v_request sender vc_sent_label
              {
                f_setHeadersOnReceiptOfSUBSCRIBE(v_request);
                f_send200OK();
                repeat;
              }
		  
            //awaiting of subscribe on proxy
            [] SIPP.receive(mw_SUBSCRIBE_Request_Base)->value v_request sender vc_sent_label
              { 
                f_setHeadersOnReceiptOfRequest(v_request); 
                f_sendResponse(m_Response_Contact(c_statusLine200,vc_callId, vc_cSeq,vc_callee_From, vc_callee_To, vc_via,vc_contact));
                //f_setHeadersGeneral(vc_cSeq, "NOTIFY"); // cseq, contact, branch, via
                //f_SendNOTIFY(m_NOTIFY_Request_contact(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_to, vc_via, vc_contact));
                log(v_request.msgHeader.contact.contactBody.contactAddresses[0].addressField.nameAddr.addrSpec);
                f_SendNOTIFY(m_NOTIFY_Request_contact(v_request.msgHeader.contact.contactBody.contactAddresses[0].addressField.nameAddr.addrSpec, vc_callId, vc_cSeq, vc_callee_From, vc_callee_To, vc_via, vc_contact));		
                f_awaitingOkResponse(vc_cSeq);
                repeat
              }            
            // unexpected BYE is acknowledged to avoid retransmissions
            [] SIPP.receive(mw_BYE_Request_Base(?))-> value v_request sender vc_sent_label
              {
                setverdict(fail);
                f_setHeadersOnReceiptOfRequest(v_request); 
                f_send200OK();
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
                }			  
			  
            // unexpected CANCEL is acknowledged to avoid retransmissions
            [] SIPP.receive(mw_CANCEL_Request_Base(?))-> value v_request sender vc_sent_label
              {
                setverdict(fail);
                f_setHeadersOnReceiptOfRequest(v_request);
                //Answer to the CANCEL
                f_send200OK();
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
                }
            // catch 4xx response
            [] SIPP.receive(mw_Response_Base(mw_statusLine4xx, vc_callId, ?))-> value v_response sender vc_sent_label
            { 
                setverdict(fail);
                f_setHeadersOnReceiptOfResponse(v_response.msgHeader.cSeq, v_response); 
                LibSip_Steps.f_setHeadersACK();
                f_SendACK(m_ACK_Request_route(vc_requestUri, vc_callId, v_response.msgHeader.cSeq, vc_from, vc_to, vc_via, vc_route));
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
            }
            // catch 5xx response
            [] SIPP.receive(mw_Response_Base(mw_statusLine5xx, vc_callId, ?))-> value v_response sender vc_sent_label
            { 
                setverdict(fail);
                f_setHeadersOnReceiptOfResponse(v_response.msgHeader.cSeq, v_response); 
                LibSip_Steps.f_setHeadersACK();
                f_SendACK(m_ACK_Request_route(vc_requestUri, vc_callId, v_response.msgHeader.cSeq, vc_from, vc_to, vc_via, vc_route));
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
            }	
            // catch invalid REGISTER	  
            [] SIPP.receive(mw_REGISTER_Request_Base)-> value v_request sender vc_sent_label
            {
                setverdict(fail); 
                f_componentStop(); 
            }
            // any	  
            [] SIPP.receive
            {
                setverdict(fail); 
                all timer.stop; 
//              f_setHeadersCANCEL(vc_cSeq);
//              f_SendCANCEL(m_CANCEL_Request_Base(vc_requestUri, vc_callId, vc_cSeq, vc_from, vc_cancel_To, vc_via )); // difference between registration state or transaction state
                action("Please de-register");          
                f_IMS_awaitDeRegistration();
                f_componentStop(); 
            }
        }

        /**
         * 
         * @desc main default altstep to handle unexpected messages and timeout
         * @verdict fail for all unexpected branches
         */	
        altstep a_altstep_AS() runs on SipComponent
        {
            var Response v_response;
            var Request v_request;
 
            [] any timer.timeout 
            {
                setverdict(fail); 
                all timer.stop; 
            }
        
            // allow repeated INVITEs
            [vc_ignore_invite] SIPP.receive(mw_INVITE_Request_Base)
            {
              repeat
            }
            //handle REGISTER requests	  
            [] SIPP.receive(mw_REGISTER_Request_Base)-> value v_request sender vc_sent_label
            {
                f_setHeadersOnReceiptOfREGISTER(v_request);
                //vc_contact := vc_request.msgHeader.contact;
                f_sendResponse(m_Response_Contact(c_statusLine200,vc_callId, vc_cSeq,vc_caller_From, vc_caller_To, vc_via, vc_contact));
                repeat;
            } 
  
                // according to SIP chap.8.1.3.2
            [] SIPP.receive(mw_Response_Base(c_statusLine183,vc_callId, vc_cSeq))
              { 
                repeat;
              }			  
			  
            // unexpected CANCEL is acknowledged to avoid retransmissions
            [] SIPP.receive(mw_CANCEL_Request_Base(?))-> value v_request sender vc_sent_label
              {
                setverdict(fail);
                f_setHeadersOnReceiptOfRequest(v_request);
                f_send200OK(); 

            // unexpected BYE is acknowledged to avoid retransmissions
            [] SIPP.receive(mw_BYE_Request_Base(?))-> value v_request sender vc_sent_label
              {
                setverdict(fail);
                f_setHeadersOnReceiptOfRequest(v_request); 
                f_send200OK();
              }
  
            [] SIPP.receive(mw_Response_Base(? ,vc_callId, vc_cSeq))-> value vc_response
              { 
                log("Response matched in DEFAULT!!!");
                setverdict(fail);
                repeat;
              }
            // any	  
            [] SIPP.receive
            {
                setverdict(fail); 
                all timer.stop; 
            }
        }
} // module LibIms_Steps