GSUP: implement TCAP-like session management

Unlike TCAP/MAP, GSUP is just a transport layer without the
dialogue/context. This prevents us from having session based
communication, required e.g. for USSD. But we can emulate
TCAP dialogue by adding additional IEs, which would allow
to relate each message to a particular session.

This change introduces the following IEs:

  - OSMO_GSUP_SESSION_ID_IE,
  - OSMO_GSUP_SESSION_STATE_IE,

which optionally can be used to indicate that the message is
related to a session with given ID, and to manage session
state, i.e. initiate, continue, and finish.

Change-Id: I1cee271fed0284a134ffed103c0d4bebbcfde2a8
Related: OS#1597
diff --git a/include/osmocom/gsm/gsup.h b/include/osmocom/gsm/gsup.h
index a7fa820..5f45699 100644
--- a/include/osmocom/gsm/gsup.h
+++ b/include/osmocom/gsm/gsup.h
@@ -82,6 +82,9 @@
 	OSMO_GSUP_AUTS_IE			= 0x26,
 	OSMO_GSUP_RES_IE			= 0x27,
 	OSMO_GSUP_CN_DOMAIN_IE			= 0x28,
+
+	OSMO_GSUP_SESSION_ID_IE			= 0x30,
+	OSMO_GSUP_SESSION_STATE_IE		= 0x31,
 };
 
 /*! GSUP message type */
@@ -132,6 +135,18 @@
 	OSMO_GSUP_CN_DOMAIN_CS			= 2,
 };
 
+/*! TCAP-like session state */
+enum osmo_gsup_session_state {
+	/*! Undefined session state */
+	OSMO_GSUP_SESSION_STATE_NONE		= 0x00,
+	/*! Initiation of a new session */
+	OSMO_GSUP_SESSION_STATE_BEGIN		= 0x01,
+	/*! Communication of an existing session */
+	OSMO_GSUP_SESSION_STATE_CONTINUE	= 0x02,
+	/*! Indication of the session end */
+	OSMO_GSUP_SESSION_STATE_END		= 0x03,
+};
+
 /*! parsed/decoded PDP context information */
 struct osmo_gsup_pdp_info {
 	unsigned int			context_id;
@@ -176,6 +191,12 @@
 	enum osmo_gsup_cn_domain	cn_domain;
 	const uint8_t			*pdp_charg_enc;
 	size_t				pdp_charg_enc_len;
+
+	/*! Session state \ref osmo_gsup_session_state */
+	enum osmo_gsup_session_state	session_state;
+	/*! Unique session identifier and origination flag.
+         * Encoded only when \ref session_state != 0x00 */
+	uint32_t			session_id;
 };
 
 int osmo_gsup_decode(const uint8_t *data, size_t data_len,