library/M3UA: support TCP transport, implement desegmentation

Change-Id: If1dcdb185d08a08dc5a06c37d9d6ffe7d6da9325
Related: libosmo-sccp.git I8c76d271472befacbeb998a93bbdc9e8660d9b5d
Related: SYS#5424
diff --git a/library/M3UA_CodecPort.ttcn b/library/M3UA_CodecPort.ttcn
index 94d16d6..e88b6a0 100644
--- a/library/M3UA_CodecPort.ttcn
+++ b/library/M3UA_CodecPort.ttcn
@@ -15,6 +15,7 @@
 
 	import from IPL4asp_PortType all;
 	import from IPL4asp_Types all;
+	import from M3UA_CodecPort_CtrlFunct all;
 	import from M3UA_Types all;
 
 	type record M3UA_RecvFrom {
@@ -37,7 +38,7 @@
 
 	type record M3UA_Send {
 		ConnectionId	connId,
-		integer		stream,
+		integer		stream optional,
 		PDU_M3UA	msg
 	}
 
@@ -59,14 +60,18 @@
 
 	private function M3UA_to_IPL4_Send(in M3UA_Send pin, out ASP_Send pout) {
 		pout.connId := pin.connId;
-		pout.proto := {
-			sctp := {
-				sinfo_stream := pin.stream,
-				sinfo_ppid := 3,
-				remSocks := omit,
-				assocId := omit
-			}
-		};
+		if (ispresent(pin.stream)) {
+			pout.proto := {
+				sctp := {
+					sinfo_stream := pin.stream,
+					sinfo_ppid := 3,
+					remSocks := omit,
+					assocId := omit
+				}
+			};
+		} else {
+			pout.proto := { tcp := { } };
+		}
 		pout.msg := enc_PDU_M3UA(pin.msg);
 	} with { extension "prototype(fast)" };
 
@@ -80,5 +85,12 @@
 		in(ASP_RecvFrom -> M3UA_RecvFrom: function(IPL4_to_M3UA_RecvFrom);
 		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
 		   ASP_Event -> ASP_Event: simple)"
+	};
+
+	function f_set_tcp_segmentation(M3UA_CODEC_PT pt, ConnectionId connId) {
+		/* Set function for dissecting the binary stream into packets */
+		var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
+		/* Offset: 4, size of length: 4, delta: 0, multiplier: 1, big-endian */
+		M3UA_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(pt, connId, vl_f, {4, 4, 0, 1, 0});
 	}
 }
diff --git a/library/M3UA_CodecPort_CtrlFunct.ttcn b/library/M3UA_CodecPort_CtrlFunct.ttcn
index fc38e43..6f06e2c 100644
--- a/library/M3UA_CodecPort_CtrlFunct.ttcn
+++ b/library/M3UA_CodecPort_CtrlFunct.ttcn
@@ -40,5 +40,12 @@
     out UserData userData
   ) return Result;
 
+  external function f_IPL4_setGetMsgLen(
+    inout M3UA_CODEC_PT portRef,
+    in ConnectionId id,
+    inout f_IPL4_getMsgLen f,
+    in ro_integer msgLenArgs
+  )
+
 }
 
diff --git a/library/M3UA_CodecPort_CtrlFunctDef.cc b/library/M3UA_CodecPort_CtrlFunctDef.cc
index 62533de..7ddacdc 100644
--- a/library/M3UA_CodecPort_CtrlFunctDef.cc
+++ b/library/M3UA_CodecPort_CtrlFunctDef.cc
@@ -51,6 +51,15 @@
   {
     return f__IPL4__PROVIDER__getUserData(portRef, connId, userData);
   }
+
+  void f__IPL4__setGetMsgLen(
+    M3UA__CodecPort::M3UA__CODEC__PT& portRef,
+    const IPL4asp__Types::ConnectionId& connId,
+    Socket__API__Definitions::f__getMsgLen& f,
+    const Socket__API__Definitions::ro__integer& msgLenArgs)
+  {
+    return f__IPL4__PROVIDER__setGetMsgLen(portRef, connId, f, msgLenArgs);
+  }
   
 }