hnb: Introduce HNB_Tests testsuite

A new Iuh CodecPort + Emulation is introduced to (de)mux RANAP and RUA
in the same SCTP socket.
The Iuh_CodecPort.ttcn file has currently a hack to be able to test
HNBAP, since titan seem to be reporting sinfo_ppid=0 when in fact it
received sinfo_ppid=20 (HNBAP).

A couple tests are added to validate HNBAP HNBRegister Request  + Accept
or Reject. In current osmo-hnodeb state, both tests pass if run
separately, but fail if run sequentially since osmo-hnodeb still doesn't
re-connect properly after first test finishes and connection is dropped.

Related: SYS#5516
Change-Id: I7227917148e98a2c777f4b05d8d2eca6e9c121b7
diff --git a/library/hnbap/HNBAP_Templates.ttcn b/library/hnbap/HNBAP_Templates.ttcn
new file mode 100644
index 0000000..44704f8
--- /dev/null
+++ b/library/hnbap/HNBAP_Templates.ttcn
@@ -0,0 +1,135 @@
+/* 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 := omit
+			}
+		}
+	}
+}
+
+
+/* 9.1.4 HNB REGISTER ACCEPT */
+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 (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 */
+			}
+		}
+	}
+}
+
+}