asterisk: Implement support to handle 2nd REGISTER through ipsec

This patch implements the necessary infra to set up ipsec tunnel towards
the asterisk IMS client, and receive the 2nd REGISTER through the ipsec
tun plus answer it acking the registration successfully.

Change-Id: Ic042422788ee406f5b71ca3878bc5617e5455579
diff --git a/library/PIPEasp_Templates.ttcn b/library/PIPEasp_Templates.ttcn
index af4e434..0775a5e 100644
--- a/library/PIPEasp_Templates.ttcn
+++ b/library/PIPEasp_Templates.ttcn
@@ -3,6 +3,20 @@
 import from PIPEasp_PortType all;
 import from PIPEasp_Types all;
 
+template (value) ASP_PExecute ts_PExecute(template (value) charstring command,
+					  template (value) charstring stdin) := {
+	command := command,
+	stdin := stdin
+}
+
+template (present) ASP_PResult tr_PResult(template (present) charstring stdout,
+					  template (present) charstring stderr,
+					  template (present) integer code) := {
+	stdout := stdout,
+	stderr := stderr,
+	code   := code
+}
+
 template (value) ASP_PExecuteBackground ts_ExecBg(charstring cmd) := {
 	command := cmd
 }
@@ -24,4 +38,36 @@
 [] pt.receive(tr_Stderr(?)) { repeat; }
 }
 
+/* User should map(component_name:PIPE, system:PIPE) before using this function. */
+function f_PIPEasp_exec_sync_PResult(PIPEasp_PT pt,
+				    charstring cmdline,
+				    template (present) ASP_PResult res_exp := tr_PResult(?,?,0),
+				    float time_out := 10.0) return ASP_PResult {
+	var ASP_PResult res;
+	timer t;
+
+	if (time_out > 0.0) {
+		t.start(time_out);
+	}
+
+	log ("Executing: ", cmdline);
+	pt.send(ts_PExecute(cmdline, ""));
+
+	alt {
+	[] pt.receive(res_exp) -> value res;
+	[time_out > 0.0] t.timeout {
+		setverdict(fail, "Timeout: ", cmdline);
+		mtc.stop;
+	}
+	}
+	log ("Result: ", res);
+	return res;
+}
+
+function f_PIPEasp_exec_sync(PIPEasp_PT pt,
+			     charstring cmdline,
+			     template (present) integer rc := 0) return ASP_PResult {
+	return f_PIPEasp_exec_sync_PResult(pt, cmdline, tr_PResult(?, ?, rc));
+}
+
 }
diff --git a/library/SIP_Templates.ttcn b/library/SIP_Templates.ttcn
index 37dee4b..7ef49cf 100644
--- a/library/SIP_Templates.ttcn
+++ b/library/SIP_Templates.ttcn
@@ -76,6 +76,9 @@
 	methods := methods
 }
 
+template (present) Credentials tr_Credentials_DigestResponse(template (present) CommaParam_List digestResponse) := {
+	digestResponse := digestResponse
+}
 template (value) Credentials ts_Credentials_DigestResponse(template (value) CommaParam_List digestResponse) := {
 	digestResponse := digestResponse
 }
@@ -114,6 +117,10 @@
 	otherResponse := otherResponse
 }
 
+template (present) Authorization tr_Authorization(template (present) Credentials body) := {
+	fieldName := AUTHORIZATION_E,
+	body := body
+}
 template (value) Authorization ts_Authorization(template (value) Credentials body) := {
 	fieldName := AUTHORIZATION_E,
 	body := body
@@ -618,6 +625,7 @@
 		template ContentLength content_length := *,
 		template ContentType content_type := *,
 		template Allow allow := *,
+		template Authorization authorization := *,
 		template Expires expires := *,
 		template Require require := *,
 		template Security_client security_client := *,
@@ -628,6 +636,7 @@
 		template WwwAuthenticate wwwAuthenticate := *
 		) modifies t_SIP_msgHeader_any := {
 	allow := allow,
+	authorization := authorization,
 	callId := {
 		fieldName := CALL_ID_E,
 		callid := call_id
@@ -696,6 +705,7 @@
 		template (present) SipAddr to_addr := ?,
 		template (present) Via via := tr_Via_from(f_tr_HostPort_opt_defport(?)),
 		template integer seq_nr := *,
+		template Authorization authorization := *,
 		template Contact contact := *,
 		template Expires expires := *,
 		template Require require := *,
@@ -705,6 +715,7 @@
 	requestLine := tr_SIP_ReqLine(REGISTER_E, sip_url_host_port),
 	msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact,
 				     via, "REGISTER", seq_nr,
+				     authorization := authorization,
 				     expires := expires,
 				     require := require,
 				     security_client := security_client,
@@ -835,12 +846,22 @@
 		integer seq_nr,
 		charstring reason,
 		Via via,
+		template (omit) Allow allow := omit,
+		template (omit) Require require := omit,
+		template (omit) Server server := omit,
+		template (omit) Supported supported := omit,
+		template (omit) UserAgent userAgent := omit,
 		template (omit) charstring body := omit) := {
 	statusLine := ts_SIP_StatusLine(status_code, reason),
 	msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr,
 				     via,
 				     content_length := f_ContentLength(body),
-				     content_type := f_ContentTypeOrOmit(ts_CT_SDP, body)),
+				     content_type := f_ContentTypeOrOmit(ts_CT_SDP, body),
+				     allow := allow,
+				     require := require,
+				     server := server,
+				     supported := supported,
+				     userAgent := userAgent),
 	messageBody := body,
 	payload := omit
 }