msc: Initial SMS testing (MO + MT SMS, successful case, no SMPP)

Change-Id: I707330454ffab87daebf22ba83e6ba2873996424
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 3203b0e..3304662 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -2,7 +2,7 @@
 
 /* L3 Templates, building on top of MobileL3*_Types from Ericsson.
  *
- * (C) 2017 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
  * All rights reserved.
  *
  * Released under the terms of GNU General Public License, Version 2 or
@@ -17,7 +17,7 @@
 import from MobileL3_RRM_Types all;
 import from MobileL3_CC_Types all;
 import from MobileL3_GMM_SM_Types all;
-//import from MobileL3_SMS_Types all;
+import from MobileL3_SMS_Types all;
 
 /* TS 24.007 Table 11.3 TI Flag */
 const BIT1 c_TIF_ORIG := '0'B;
@@ -2168,4 +2168,284 @@
 	with { extension "prototype(convert) encode(RAW)" };
 
 
+
+/* SMS TPDU Layer */
+
+template (value) TPDU_RP_DATA_MS_SGSN ts_SMS_SUBMIT(OCT1 msg_ref, template (value) TP_DA dst_addr,
+					  template (value) OCT1 pid, template (value) OCT1 dcs,
+					  integer length_ind, octetstring user_data) := {
+	sMS_SUBMIT := {
+		tP_MTI := '01'B,	/* SUBMIT */
+		tP_RD := '1'B,		/* reject duplicates */
+		tP_VPF := '00'B,	/* not present */
+		tP_SRR := '0'B,		/* no status report requested */
+		tP_UDHI := '0'B,	/* no user data header in UD */
+		tP_RP := '0'B,		/* no reply path */
+		tP_MR := msg_ref,
+		tP_DA := dst_addr,
+		tP_PID := pid,
+		tP_DCS := dcs,
+		tP_VP := omit,
+		tP_UDL_UD := {
+			tP_LengthIndicator := length_ind,
+			tP_UD := user_data
+		}
+	}
+}
+
+template TPDU_RP_DATA_SGSN_MS tr_SMS_DELIVER(template TP_OA src_addr := ?,
+				    template octetstring user_data := ?,
+				    template OCT1 pid := ?, template OCT1 dcs := ?,
+				    template BIT1 mms := ?
+				) := {
+	sMS_DELIVER := {
+		tP_MTI := '00'B,	/* DELIVER */
+		tP_MMS := mms,		/* more messages to send */
+		tP_LP := ?,		/* ?!? */
+		tP_Spare := '0'B,
+		tP_SRI := '0'B,		/* status report indication */
+		tP_UDHI := '0'B,	/* no user data header in UD */
+		tP_RP := '0'B,		/* no reply path */
+		tP_OA := src_addr,
+		tP_PID := pid,
+		tP_DCS := dcs,
+		tP_SCTS := ?,
+		tP_UDL_UD := {
+			tP_LengthIndicator := ?,
+			tP_UD := user_data
+		}
+	}
+}
+
+/* RP Layer */
+
+private function ts_RpOrig(template (omit) RP_NumberingPlan_and_NumberDigits rp_orig)
+return RP_OriginatorAddressLV {
+	var RP_OriginatorAddressLV ret;
+	if (istemplatekind(rp_orig, "omit")) {
+		ret := { 0, omit };
+	} else {
+		ret := { 0, valueof(rp_orig) };
+	}
+	return ret;
+}
+
+private function ts_RpDst(template (omit) RP_NumberingPlan_and_NumberDigits rp_dst)
+return RP_DestinationAddressLV {
+	var RP_DestinationAddressLV ret;
+	if (istemplatekind(rp_dst, "omit")) {
+		ret := { 0, omit };
+	} else {
+		ret := { 0, valueof(rp_dst) };
+	}
+	return ret;
+}
+
+template (value) RPDU_MS_SGSN ts_RP_DATA_MO(OCT1 msg_ref,
+					    template (omit) RP_NumberingPlan_and_NumberDigits rp_orig,
+					    template (omit) RP_NumberingPlan_and_NumberDigits rp_dst,
+					    template (value) TPDU_RP_DATA_MS_SGSN tpdu) := {
+	rP_DATA_MS_SGSN := {
+		rP_MTI := '000'B,
+		rP_Spare := '00000'B,
+		rP_MessageReference := msg_ref,
+		rP_OriginatorAddress := ts_RpOrig(rp_orig),
+		rP_DestinationAddress := ts_RpDst(rp_dst),
+		rP_User_Data := {
+			rP_LengthIndicator := 0, /* overwritten */
+			rP_TPDU := tpdu
+		}
+	}
+}
+
+template RPDU_SGSN_MS tr_RP_DATA_MT(template OCT1 msg_ref,
+				    template RP_NumberingPlan_and_NumberDigits rp_orig,
+				    template RP_NumberingPlan_and_NumberDigits rp_dst,
+				    template TPDU_RP_DATA_SGSN_MS tpdu) := {
+	rP_DATA_SGSN_MS := {
+		rP_MTI := '001'B,
+		rP_Spare := '00000'B,
+		rP_MessageReference := msg_ref,
+		rP_OriginatorAddress := { ?, rp_orig },
+		rP_DestinationAddress := { ?, rp_dst },
+		rP_User_Data := {
+			rP_LengthIndicator := ?,
+			rP_TPDU := tpdu
+		}
+
+	}
+}
+
+template (value) RPDU_MS_SGSN ts_RP_ACK_MO(OCT1 msg_ref) := {
+	rP_ACK_MS_SGSN := {
+		rP_MTI := '010'B,
+		rP_Spare := '00000'B,
+		rP_MessageReference := msg_ref,
+		rP_User_Data := omit /* FIXME: report */
+	}
+}
+
+template RPDU_SGSN_MS tr_RP_ACK_MT(template OCT1 msg_ref) := {
+	rP_ACK_SGSN_MS := {
+		rP_MTI := '011'B,
+		rP_Spare := '00000'B,
+		rP_MessageReference := msg_ref,
+		rP_User_Data := omit /* FIXME: report */
+	}
+}
+
+template (value) RPDU_MS_SGSN ts_RP_ERROR_MO(OCT1 msg_ref, uint7_t cause) := {
+	rP_ERROR_MS_SGSN := {
+		rP_MTI := '100'B,
+		rP_Spare := '00000'B,
+		rP_Message_Reference := msg_ref,
+		rP_CauseLV := {
+			rP_LengthIndicator := 0, /* overwritten */
+			rP_CauseV := {
+				causeValue := int2bit(cause, 7),
+				ext := '0'B
+			},
+			rP_diagnisticField := omit
+		},
+		rP_User_Data := omit /* FIXME: report */
+	}
+}
+
+private function f_cause_or_wc(template uint7_t cause) return template BIT7 {
+	if (istemplatekind(cause, "?")) {
+		return ?;
+	} else if (istemplatekind(cause, "*")) {
+		return *;
+	} else {
+		return int2bit(valueof(cause), 7);
+	}
+}
+
+template RPDU_SGSN_MS tr_RP_ERROR_MT(template OCT1 msg_ref, template uint7_t cause) := {
+	rP_ERROR_SGSN_MS := {
+		rP_MTI := '101'B,
+		rP_Spare := '00000'B,
+		rP_Message_Reference := msg_ref,
+		rP_CauseLV := {
+			rP_LengthIndicator := 0, /* overwritten */
+			rP_CauseV := {
+				causeValue := f_cause_or_wc(cause),
+				ext := '0'B
+			},
+			rP_diagnisticField := omit
+		},
+		rP_User_Data := omit /* FIXME: report */
+	}
+}
+
+
+template (value) RPDU_MS_SGSN ts_RP_SMMA_MO(OCT1 msg_ref) := {
+	rP_SMMA := {
+		rP_MTI := '110'B,
+		rP_Spare := '00000'B,
+		rP_MessageReference := msg_ref
+	}
+}
+
+
+
+
+/* CP Layer */
+
+template (value) L3_SMS_MS_SGSN ts_CP_DATA_MO(template (value) RPDU_MS_SGSN rpdu) := {
+	cP_DATA := {
+		cP_messageType := '00000001'B,
+		cP_User_Data := {
+			lengthIndicator := 0, /* overwritten */
+			cP_RPDU := rpdu
+		}
+	}
+}
+
+template (value) L3_SMS_MS_SGSN ts_CP_ACK_MO := {
+	cP_ACK := {
+		cP_messageType := '00000100'B
+	}
+}
+
+template (value) L3_SMS_MS_SGSN ts_CP_ERROR_MO(OCT1 cause) := {
+	cP_ERROR := {
+		cP_messageType := '00010000'B,
+		cP_Cause := {
+			causeValue := cause
+		}
+	}
+}
+
+template L3_SMS_SGSN_MS tr_CP_DATA_MT(template RPDU_SGSN_MS rpdu) := {
+	cP_DATA := {
+		cP_messageType := '00000001'B,
+		cP_User_Data := {
+			lengthIndicator := ?,
+			cP_RPDU := rpdu
+		}
+	}
+}
+
+template L3_SMS_SGSN_MS tr_CP_ACK_MT := {
+	cP_ACK := {
+		cP_messageType := '00000100'B
+	}
+}
+
+template L3_SMS_SGSN_MS tr_CP_ERROR_MT(template OCT1 cause) := {
+	cP_ERROR := {
+		cP_messageType := '00010000'B,
+		cP_Cause := {
+			causeValue := cause
+		}
+	}
+}
+
+/* L3 Wrapper */
+
+template (value) PDU_ML3_MS_NW ts_ML3_MO_SMS(uint3_t tid, BIT1 ti_flag,
+					     template (value) L3_SMS_MS_SGSN sms_mo) := {
+	discriminator := '1001'B,
+	tiOrSkip := {
+		transactionId := {
+			tio := int2bit(tid, 3),
+			tiFlag := ti_flag,
+			tIExtension := omit
+		}
+	},
+	msgs := {
+		sms := sms_mo
+	}
+}
+
+private function f_tid_or_wc(template uint3_t tid) return template BIT3 {
+	var template BIT3 ret;
+	if (istemplatekind(tid, "*")) {
+		return *;
+	} else if (istemplatekind(tid, "?")) {
+		return ?;
+	} else {
+		return int2bit(valueof(tid), 3);
+	}
+}
+
+template PDU_ML3_NW_MS tr_ML3_MT_SMS(template uint3_t tid, template BIT1 ti_flag,
+				     template L3_SMS_SGSN_MS sms_mt) := {
+	discriminator := '1001'B,
+	tiOrSkip := {
+		transactionId := {
+			tio := f_tid_or_wc(tid),
+			tiFlag := ti_flag,
+			tIExtension := omit
+		}
+	},
+	msgs := {
+		sms := sms_mt
+	}
+}
+
+
+
+
 }