/* HNBAP Templates in TTCN-3
 * (C) 2021 Pau Espin Pedrol <pespin@sysmocom.de>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

module HNBAP_Templates {

import from General_Types all;
import from Osmocom_Types all;

import from HNBAP_IEs all;
import from HNBAP_CommonDataTypes all;
import from HNBAP_Constants all;
import from HNBAP_Containers all;
import from HNBAP_PDU_Contents all;
import from HNBAP_PDU_Descriptions all;

/*********************************************************************************
 * 3GPP TS 25.469
 *********************************************************************************/

template (value) Cause ts_HnbapCause(template (value) CauseRadioNetwork c) := {
	radioNetwork := c
}

/* 9.1.3 HNB REGISTER REQUEST */
template (present) HNBAP_PDU
tr_HNBAP_HNBRegisterRequest(template (present) octetstring hNB_Identity_Info := ?,
		 template (present) OCT3 plmnid := ?,
		 template (present) BIT28 cell_identity := ?,
		 template (present) OCT2 lac := ?,
		 template (present) OCT1 rac := ?,
		 template (present) OCT2 sac := ?) := {
	initiatingMessage := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			hNBRegisterRequest := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_HNB_Identity,
						criticality := reject,
						value_ := {
							hNB_Identity := {
								hNB_Identity_Info := hNB_Identity_Info,
								iE_Extensions := omit
							}
						}
					}, {
						id := 8,
						criticality := reject,
						value_ := {
							hNB_Location_Information := {
									macroCoverageInfo := omit,
									geographicalCoordinates := omit,
									iE_Extensions := omit
							}
						}
					}, {
						id := 9,
						criticality := reject,
						value_ := { pLMNidentity := plmnid }
					}, {
						id := 11,
						criticality := reject,
						value_ := { cellIdentity := cell_identity }
					}, {
						id := 6,
						criticality := reject,
						value_ := { lAC := lac }
					}, {
						id := 7,
						criticality := reject,
						value_ := { rAC := rac }
					}, {
						id := 10,
						criticality := reject,
						value_ := { sAC := sac }
					}
				},
				protocolExtensions := *
			}
		}
	}
}

template (value) HNBAP_PDU
ts_HNBAP_HNBRegisterRequest(template (value) octetstring hNB_Identity_Info,
		 template (value) OCT3 plmnid,
		 template (value) BIT28 cell_identity,
		 template (value) OCT2 lac,
		 template (value) OCT1 rac,
		 template (value) OCT2 sac) := {
	initiatingMessage := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			hNBRegisterRequest := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_HNB_Identity,
						criticality := reject,
						value_ := {
							hNB_Identity := {
								hNB_Identity_Info := hNB_Identity_Info,
								iE_Extensions := omit
							}
						}
					}, {
						id := 8,
						criticality := reject,
						value_ := {
							hNB_Location_Information := {
									macroCoverageInfo := omit,
									geographicalCoordinates := omit,
									iE_Extensions := omit
							}
						}
					}, {
						id := 9,
						criticality := reject,
						value_ := { pLMNidentity := plmnid }
					}, {
						id := 11,
						criticality := reject,
						value_ := { cellIdentity := cell_identity }
					}, {
						id := 6,
						criticality := reject,
						value_ := { lAC := lac }
					}, {
						id := 7,
						criticality := reject,
						value_ := { rAC := rac }
					}, {
						id := 10,
						criticality := reject,
						value_ := { sAC := sac }
					}
				},
				protocolExtensions := omit
			}
		}
	}
}


/* 9.1.4 HNB REGISTER ACCEPT */
template (present) HNBAP_PDU
tr_HNBAP_HNBRegisterAccept(template (present) uint16_t rnc_id := ?) := {
	successfulOutcome := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			hNBRegisterAccept := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_RNC_ID,
						criticality := reject,
						value_ := { RNC_ID := rnc_id }
					}
				},
				protocolExtensions := * /* TODO: Mux Port Number (optional) 9.2.29 */
			}
		}
	}
}

template (value) HNBAP_PDU
ts_HNBAP_HNBRegisterAccept(template (value) uint16_t rnc_id) := {
	successfulOutcome := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			hNBRegisterAccept := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_RNC_ID,
						criticality := reject,
						value_ := { RNC_ID := rnc_id }
					}
				},
				protocolExtensions := omit /* TODO: Mux Port Number (optional) 9.2.29 */
			}
		}
	}
}

/* 9.1.5 HNB REGISTER REJECT */
template (present) HNBAP_PDU
tr_HNBAP_HNBRegisterReject(template (present) Cause cause := ?) := {
	unsuccessfulOutcome := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			HNBRegisterReject := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_Cause,
						criticality := ignore,
						value_ := { Cause := cause }
					}
				},
				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

template (value) HNBAP_PDU
ts_HNBAP_HNBRegisterReject(template (value) Cause cause) := {
	unsuccessfulOutcome := {
		procedureCode := id_HNBRegister,
		criticality := reject,
		value_ := {
			HNBRegisterReject := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_Cause,
						criticality := ignore,
						value_ := { Cause := cause }
					}
				},
				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

/* 9.1.6 UE REGISTER REQUEST */
template (present) HNBAP_PDU
tr_HNBAP_UERegisterRequest(template (present) UE_Identity ue_id) := {
	initiatingMessage := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterRequest := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Registration_Cause,
						criticality := ignore,
						value_ := { Registration_Cause := normal }
					}, {
						id := HNBAP_Constants.id_UE_Capabilities,
						criticality := ignore,
						value_ := {
							UE_Capabilities := {
								access_stratum_release_indicator := ?,
								csg_capability := ?
							}
						}
					}
				},
				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

template (value) HNBAP_PDU
ts_HNBAP_UERegisterRequest(template (value) UE_Identity ue_id) := {
	initiatingMessage := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterRequest := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Registration_Cause,
						criticality := ignore,
						value_ := { Registration_Cause := normal }
					}, {
						id := HNBAP_Constants.id_UE_Capabilities,
						criticality := ignore,
						value_ := {
							UE_Capabilities := {
								access_stratum_release_indicator := rel_8_and_beyond,
								csg_capability := not_csg_capable,
								iE_Extensions := omit
							}
						}
					}
				},
				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

/* 9.1.7 UE REGISTER ACCEPT */
template (present) HNBAP_PDU
tr_HNBAP_UERegisterAccept(template (present) UE_Identity ue_id) := {
	successfulOutcome := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterAccept := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Context_ID,
						criticality := reject,
						value_ := { Context_ID := ? }
					}, *
				},
				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

template (value) HNBAP_PDU
ts_HNBAP_UERegisterAccept(template (value) UE_Identity ue_id,
			  template (value) BIT24 context_id) := {
	successfulOutcome := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterAccept := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Context_ID,
						criticality := reject,
						value_ := { Context_ID := context_id }
					}
				},
				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

/* 9.1.8 UE REGISTER REJECT */
template (present) HNBAP_PDU
tr_HNBAP_UERegisterReject(template (present) UE_Identity ue_id, template (present) Cause cause := ?) := {
	unsuccessfulOutcome := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterReject := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Cause,
						criticality := ignore,
						value_ := { Cause := cause }
					}, *
				},
				protocolExtensions := * /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}
template (value) HNBAP_PDU
ts_HNBAP_UERegisterReject(template (value) UE_Identity ue_id, template (value) Cause cause) := {
	unsuccessfulOutcome := {
		procedureCode := id_UERegister,
		criticality := reject,
		value_ := {
			uERegisterReject := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_UE_Identity,
						criticality := reject,
						value_ := { UE_Identity := ue_id }
					}, {
						id := HNBAP_Constants.id_Cause,
						criticality := ignore,
						value_ := { Cause := cause }
					}
				},
				protocolExtensions := omit /* TODO: CriticalityDiagnostics, BackoffTimer */
			}
		}
	}
}

/* 9.1.9 HNB DE-REGISTER */
template (value) HNBAP_PDU
ts_HNBAP_HNBDe_Register(template (value) Cause cause) := {
	initiatingMessage := {
		procedureCode := id_HNBDe_Register,
		criticality := reject,
		value_ := {
			HNBDe_Register := {
				protocolIEs := {
					{
						id := HNBAP_Constants.id_Cause,
						criticality := ignore,
						value_ := { Cause := cause }
					}
				},
				protocolExtensions := omit /* TODO: BackoffTimer */
			}
		}
	}
}

}
