hnodeb: Add initial infra to emulate HNB LL socket iface

Change-Id: Ia864a672643a0e42f5afea6fd901e621478c87c0
diff --git a/library/HNBLLIF_Types.ttcn b/library/HNBLLIF_Types.ttcn
new file mode 100644
index 0000000..f9c8cc5
--- /dev/null
+++ b/library/HNBLLIF_Types.ttcn
@@ -0,0 +1,275 @@
+/* Osmocom HNBLL Interface Types, as per osmo-hnodeb/include/osmocom/hnodeb/hnb_prim.h
+ * (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * All rights reserved.
+ * Author: Pau Espin Pedrol <pespin@sysmocom.de>
+ *
+ * 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 HNBLLIF_Types {
+
+import from General_Types all;
+import from Osmocom_Types all;
+import from Native_Functions all;
+
+modulepar {
+	/* HNBLLIF version supported by the IUT */
+	HNBLLIF_Version mp_hnbllif_version := 0;
+};
+
+const charstring HNBLL_SOCK_DEFAULT := "/tmp/hnb_prim_sock";
+type integer HNBLLIF_Version (0); /* supported versions */
+
+/**********************
+ * CTL SAPI
+ **********************/
+
+
+type enumerated HNBLLIF_CTL_MsgType {
+	HNBLL_IF_CTL_MSG_HELLO	('0000'O)
+} with { variant "FIELDLENGTH(16)" };
+
+type record HNBLLIF_CTL_hello_req {
+	HNBLLIF_Sapi	sapi,
+	uint16_t	api_version
+} with { variant "" };
+
+type record HNBLLIF_CTL_hello_cnf {
+	HNBLLIF_Sapi	sapi,
+	uint16_t	api_version
+} with { variant "" };
+
+type union HNBLLIF_CTL_PrimOpUnion_hello {
+	HNBLLIF_CTL_hello_req	req,
+	HNBLLIF_CTL_hello_cnf	cnf,
+	octetstring		other
+} with { variant "" };
+
+type record HNBLLIF_CTL_PrimOp_hello  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_CTL_PrimOpUnion_hello	u
+} with { variant (u) "CROSSTAG( req, 	op = HNBLL_IF_OP_REQUEST;
+				cnf, 	op = HNBLL_IF_OP_CONFIRM;
+				other,	OTHERWISE)"
+};
+
+type union HNBLLIF_CTL_PrimUnion {
+	HNBLLIF_CTL_PrimOp_hello	hello,
+	octetstring		other
+} with { variant "" };
+
+type record HNBLLIF_CTL_PrimHdr  {
+	HNBLLIF_CTL_MsgType	prim,
+	HNBLLIF_CTL_PrimUnion	u
+} with { variant (u) "CROSSTAG( hello, 	prim = HNBLL_IF_CTL_MSG_HELLO;
+				other,	OTHERWISE)"
+};
+
+/**********************
+ * IUH SAPI
+ **********************/
+type enumerated HNBLLIF_IUH_MsgType {
+	HNBLL_IF_IUH_MSG_CONFIGURE	('0000'O),
+	HNBLL_IF_IUH_MSG_CONN_ESTABLISH	('0001'O),
+	HNBLL_IF_IUH_MSG_CONN_RELEASE	('0002'O),
+	HNBLL_IF_IUH_MSG_CONN_DATA	('0003'O),
+	HNBLL_IF_IUH_MSG_UNITDATA	('0004'O)
+} with { variant "FIELDLENGTH(16)" };
+
+/* CONFIGURE */
+type record HNBLLIF_IUH_configure_ind {
+	uint16_t mcc,
+	uint16_t mnc,
+	uint16_t cell_identity,
+	uint16_t lac,
+	uint8_t rac,
+	uint8_t reserved,
+	uint16_t sac,
+	uint16_t rnc_id
+} with { variant "" };
+
+type union HNBLLIF_IUH_PrimOpUnion_configure {
+	HNBLLIF_IUH_configure_ind ind,
+	octetstring		other
+} with { variant "" };
+
+type record HNBLLIF_IUH_PrimOp_configure  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_IUH_PrimOpUnion_configure	u
+} with { variant (u) "CROSSTAG( ind, 	op = HNBLL_IF_OP_INDICATION;
+				other,	OTHERWISE)"
+};
+
+/* CONN_ESTABLISH */
+type record HNBLLIF_IUH_conn_establish_req {
+	uint32_t context_id,
+	uint8_t domain,
+	uint8_t est_cause,
+	uint16_t reserved, //uint16_t nas_node_selector_bitlen;
+	//uint8_t nas_node_selector[128]; /* TODO: check whether we can decrease this buffer size */
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+type record HNBLLIF_IUH_conn_establish_cnf {
+	uint32_t context_id,
+	uint8_t domain,
+	uint8_t est_cause
+} with { variant "" };
+
+type union HNBLLIF_IUH_PrimOpUnion_conn_establish {
+	HNBLLIF_IUH_conn_establish_req req,
+	HNBLLIF_IUH_conn_establish_cnf cnf,
+	octetstring		other
+} with { variant "" };
+type record HNBLLIF_IUH_PrimOp_conn_establish  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_IUH_PrimOpUnion_conn_establish	u
+} with { variant (u) "CROSSTAG( req, 	op = HNBLL_IF_OP_REQUEST;
+				cnf, 	op = HNBLL_IF_OP_CONFIRM;
+				other,	OTHERWISE)"
+};
+
+/* CONN_RELEASE */
+type record HNBLLIF_IUH_conn_release_req {
+	uint32_t context_id,
+	uint8_t domain,
+	uint8_t spare1,
+	uint8_t cause_type,
+	uint8_t cause,
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+
+type union HNBLLIF_IUH_PrimOpUnion_conn_release {
+	HNBLLIF_IUH_conn_release_req req,
+	octetstring		other
+} with { variant "" };
+type record HNBLLIF_IUH_PrimOp_conn_release  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_IUH_PrimOpUnion_conn_release	u
+} with { variant (u) "CROSSTAG( req, 	op = HNBLL_IF_OP_REQUEST;
+				other,	OTHERWISE)"
+};
+
+/* CONN_DATA */
+type record HNBLLIF_IUH_conn_data_ind {
+	uint32_t context_id,
+	uint8_t domain,
+	uint8_t spare1,
+	uint16_t spare2,
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+type record HNBLLIF_IUH_conn_data_req {
+	uint32_t context_id,
+	uint8_t domain,
+	uint8_t spare1,
+	uint16_t spare2,
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+type union HNBLLIF_IUH_PrimOpUnion_conn_data {
+	HNBLLIF_IUH_conn_data_req req,
+	HNBLLIF_IUH_conn_data_ind ind,
+	octetstring		other
+} with { variant "" };
+type record HNBLLIF_IUH_PrimOp_conn_data  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_IUH_PrimOpUnion_conn_data	u
+} with { variant (u) "CROSSTAG( req, 	op = HNBLL_IF_OP_REQUEST;
+				ind, 	op = HNBLL_IF_OP_INDICATION;
+				other,	OTHERWISE)"
+};
+
+/* UNITDATA */
+type record HNBLLIF_IUH_unitdata_ind {
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+type record HNBLLIF_IUH_unitdata_req {
+	uint32_t data_len,
+	octetstring data /* RANAP message */
+} with { variant (data_len) "LENGTHTO (data)" };
+
+type union HNBLLIF_IUH_PrimOpUnion_unitdata {
+	HNBLLIF_IUH_unitdata_req req,
+	HNBLLIF_IUH_unitdata_ind ind,
+	octetstring		other
+} with { variant "" };
+type record HNBLLIF_IUH_PrimOp_unitdata  {
+	HNBLLIF_Operation	op,
+	HNBLLIF_IUH_PrimOpUnion_unitdata	u
+} with { variant (u) "CROSSTAG( req, 	op = HNBLL_IF_OP_REQUEST;
+				ind, 	op = HNBLL_IF_OP_INDICATION;
+				other,	OTHERWISE)"
+};
+
+type union HNBLLIF_IUH_PrimUnion {
+	HNBLLIF_IUH_PrimOp_configure		configure,
+	HNBLLIF_IUH_PrimOp_conn_establish	conn_establish,
+	HNBLLIF_IUH_PrimOp_conn_release		conn_release,
+	HNBLLIF_IUH_PrimOp_conn_data		conn_data,
+	HNBLLIF_IUH_PrimOp_unitdata		unitdata,
+	octetstring		other
+} with { variant "" };
+
+type record HNBLLIF_IUH_PrimHdr  {
+	HNBLLIF_IUH_MsgType	prim,
+	HNBLLIF_IUH_PrimUnion	u
+} with { variant (u) "CROSSTAG( configure, 	prim = HNBLL_IF_IUH_MSG_CONFIGURE;
+				conn_establish,	prim = HNBLL_IF_IUH_MSG_CONN_ESTABLISH;
+				conn_release,	prim = HNBLL_IF_IUH_MSG_CONN_RELEASE;
+				conn_data,	prim = HNBLL_IF_IUH_MSG_CONN_DATA;
+				unitdata,	prim = HNBLL_IF_IUH_MSG_UNITDATA;
+				other,	OTHERWISE)"
+};
+
+
+/**********************
+* General
+**********************/
+type enumerated HNBLLIF_Sapi {
+	HNBLL_IF_SAPI_CTL		(-1),
+	HNBLL_IF_SAPI_IUH		('00000001'O)//,
+	//HNBLL_IF_SAPI_GTP		('00000002'O),
+	//HNBLL_IF_SAPI_AUDIO		('00000003'O),
+} with { variant "FIELDLENGTH(32)"
+	 variant "COMP(2scompl)"
+};
+
+type enumerated HNBLLIF_Operation {
+	HNBLL_IF_OP_REQUEST	('0000'O),
+	HNBLL_IF_OP_RESPONSE	('0001'O),
+	HNBLL_IF_OP_INDICATION	('0002'O),
+	HNBLL_IF_OP_CONFIRM	('0003'O)
+} with { variant "FIELDLENGTH(16)" };
+
+type union HNBLLIF_SapiUnion {
+	HNBLLIF_CTL_PrimHdr		ctl,
+	HNBLLIF_IUH_PrimHdr		iuh,
+	octetstring			other
+} with { variant "" };
+
+type record HNBLLIF_Message {
+	HNBLLIF_Sapi sapi,
+	HNBLLIF_SapiUnion u
+} with { variant (u) "CROSSTAG( ctl, 		sapi = HNBLL_IF_SAPI_CTL;
+				iuh, 		sapi = HNBLL_IF_SAPI_IUH;
+				other,	OTHERWISE)"
+};
+
+external function enc_HNBLLIF_Message(in HNBLLIF_Message pdu) return octetstring
+	with { extension "prototype(convert) encode(RAW)" };
+external function dec_HNBLLIF_Message(in octetstring stream) return HNBLLIF_Message
+	with { extension "prototype(convert) decode(RAW)" };
+
+
+} with { encode "RAW" variant "BYTEORDER(first)" };