sgsn: Add TC_detach_* for various GPRS DETACH use cases

Change-Id: I2243b850400482b911d687585929a2eef3490954
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 5b6b481..9bd74db 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -65,10 +65,18 @@
 }
 
 /* send template fro Mobile Identity (TMSI) */
-template MobileIdentityTLV ts_MI_TMSI_TLV(OCT4 tmsi) := {
-	elementIdentifier := '0100011'B,
-	spare1 := '0'B,
-	mobileIdentityLV := ts_MI_TMSI_LV(tmsi)
+function ts_MI_TMSI_TLV(template (omit) OCT4 tmsi) return template (omit) MobileIdentityTLV {
+	var template (omit) MobileIdentityTLV ret;
+	if (istemplatekind(tmsi, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '0100011'B,
+			spare1 := '0'B,
+			mobileIdentityLV := ts_MI_TMSI_LV(valueof(tmsi))
+		}
+		return ret;
+	}
 }
 
 template MobileIdentityTLV ts_MI_IMEISV_TLV(hexstring imeisv) := {
@@ -1689,12 +1697,42 @@
 const BIT3 c_GMM_DTT_MO_IMSI := '010'B;
 const BIT3 c_GMM_DTT_MO_GPRS_IMSI_COMBINED := '011'B;
 
-template (value) DetachTypeV ts_GMM_DetType(BIT3 dtt) := {
+template (value) DetachTypeV ts_GMM_DetType(BIT3 dtt, boolean power_off := false) := {
 	detachType := dtt,
-	powerOffFlag := '0'B
+	powerOffFlag := bool2bit(power_off)
 }
 
-template (value) PDU_L3_MS_SGSN ts_GMM_DET_REQ_MO(BIT3 dtt := c_GMM_DTT_MO_GPRS) := {
+function ts_PtmsiSigTV(template (omit) OCT3 val) return template (omit) P_TMSISignatureTV {
+	var template (omit) P_TMSISignatureTV ret;
+	if (istemplatekind(val, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '19'O,
+			valueField := valueof(val)
+		}
+		return ret;
+	}
+}
+
+function ts_PtmsiSigTLV(template (omit) OCT3 val) return template (omit) P_TMSISignature2TLV {
+	var template (omit) P_TMSISignature2TLV ret;
+	if (istemplatekind(val, "omit")) {
+		return omit;
+	} else {
+		ret := {
+			elementIdentifier := '19'O,
+			lengthIndicator := 3,
+			valueField := valueof(val)
+		}
+		return ret;
+	}
+}
+
+template (value) PDU_L3_MS_SGSN ts_GMM_DET_REQ_MO(BIT3 dtt := c_GMM_DTT_MO_GPRS,
+						  boolean power_off := false,
+						  template (omit) OCT4 p_tmsi := omit,
+						  template (omit) OCT3 p_tmsi_sig := omit) := {
 	discriminator := '0000'B, /* overwritten */
 	tiOrSkip := {
 		skipIndicator := '0000'B
@@ -1703,10 +1741,26 @@
 		gprs_mm := {
 			detachRequest_MS_SGSN := {
 				messageType := '00000000'B, /* overwritten */
-				detachType := valueof(ts_GMM_DetType(dtt)),
+				detachType := valueof(ts_GMM_DetType(dtt, power_off)),
 				spare := '0000'B,
-				ptmsi := omit, /* TODO */
-				ptmsiSignature := omit /* TODO */
+				ptmsi := ts_MI_TMSI_TLV(p_tmsi),
+				ptmsiSignature := ts_PtmsiSigTLV(p_tmsi_sig)
+			}
+		}
+	}
+}
+
+template PDU_L3_SGSN_MS tr_GMM_DET_ACCEPT_MT := {
+	discriminator := '1000'B,
+	tiOrSkip := {
+		skipIndicator := '0000'B
+	},
+	msgs := {
+		gprs_mm := {
+			detachAccept_SGSN_MS := {
+				messageType := '00000110'B,
+				forceToStandby := ?,
+				spare := '0000'B
 			}
 		}
 	}