library/GSUP_Types.ttcn: fix MSISDN / SMSC coding in SM-RP-OA/DA

Unlike IMSI, both MSISDN and SMSC address in SM-RP-OA/DA not only
contain the BCD encoded digits, but also a little header with
NPI (Numbering Plan Identification), ToN (Type of Number), and
Extension fields.

Change-Id: I3f55834489f3e613f541cf1e216027e8d48ccaf0
Related: OS#4324
diff --git a/library/GSUP_Types.ttcn b/library/GSUP_Types.ttcn
index 8977d9f..d4b1db1 100644
--- a/library/GSUP_Types.ttcn
+++ b/library/GSUP_Types.ttcn
@@ -869,6 +869,38 @@
 	OSMO_GSUP_SM_RP_ODA_ID_NULL		('FF'O)
 } with { variant "FIELDLENGTH(8)" };
 
+/* See 3GPP TS 24.011, figures 8.5 and 8.6 */
+type record GSUP_SM_RP_Addr {
+	BIT1		ext, /* Extension? */
+	BIT3		ton, /* Type of Number */
+	BIT4		npi, /* Numbering Plan Identification */
+	hexstring	number length (1..20)
+} with {
+	variant "PADDING(yes)";
+	variant "PADDING_PATTERN('1111'B)"
+};
+
+private function f_pad_SM_RP_Addr(template hexstring number)
+return template hexstring {
+	if (isvalue(number) and not istemplatekind(number, "omit")) {
+		return f_pad_bcd_number(valueof(number));
+	} else {
+		return number;
+	}
+}
+
+template GSUP_SM_RP_Addr t_GSUP_SM_RP_Addr(template hexstring number,
+					   template BIT4 npi := '0001'B,
+					   template BIT3 ton := '001'B,
+					   template BIT1 ext := '1'B) := {
+	ext := ext,
+	ton := ton,
+	npi := npi,
+	/* Work around TITAN's padding problems: encoding works fine,
+	 * but it does not consider 'F'H as padding in decoded data. */
+	number := f_pad_SM_RP_Addr(number)
+}
+
 /**
  * SM-RP-DA represents the SM Destination Address, see 7.6.8.1.
  * It can be either of the following:
@@ -879,9 +911,9 @@
  *  - service centre address
  */
 type union GSUP_SM_RP_DA_ID {
-	hexstring	imsi,
-	hexstring	msisdn,
-	hexstring	smsc_addr
+	hexstring		imsi,
+	GSUP_SM_RP_Addr		msisdn,
+	GSUP_SM_RP_Addr		smsc_addr
 };
 
 type record GSUP_SM_RP_DA {
@@ -904,20 +936,20 @@
 	id_enc := { imsi := imsi }
 }
 
-template (value) GSUP_SM_RP_DA ts_GSUP_SM_RP_DA_MSISDN(hexstring msisdn) := {
+template (value) GSUP_SM_RP_DA ts_GSUP_SM_RP_DA_MSISDN(GSUP_SM_RP_Addr msisdn) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_MSISDN,
 	id_enc := { msisdn := msisdn }
 }
-template GSUP_SM_RP_DA tr_GSUP_SM_RP_DA_MSISDN(template hexstring msisdn) := {
+template GSUP_SM_RP_DA tr_GSUP_SM_RP_DA_MSISDN(template GSUP_SM_RP_Addr msisdn) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_MSISDN,
 	id_enc := { msisdn := msisdn }
 }
 
-template (value) GSUP_SM_RP_DA ts_GSUP_SM_RP_DA_SMSC_ADDR(hexstring smsc_addr) := {
+template (value) GSUP_SM_RP_DA ts_GSUP_SM_RP_DA_SMSC_ADDR(GSUP_SM_RP_Addr smsc_addr) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_SMSC_ADDR,
 	id_enc := { smsc_addr := smsc_addr }
 }
-template GSUP_SM_RP_DA tr_GSUP_SM_RP_DA_SMSC_ADDR(template hexstring smsc_addr) := {
+template GSUP_SM_RP_DA tr_GSUP_SM_RP_DA_SMSC_ADDR(template GSUP_SM_RP_Addr smsc_addr) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_SMSC_ADDR,
 	id_enc := { smsc_addr := smsc_addr }
 }
@@ -953,8 +985,8 @@
  *  - service centre address
  */
 type union GSUP_SM_RP_OA_ID {
-	hexstring	msisdn,
-	hexstring	smsc_addr
+	GSUP_SM_RP_Addr		msisdn,
+	GSUP_SM_RP_Addr		smsc_addr
 };
 
 type record GSUP_SM_RP_OA {
@@ -967,20 +999,20 @@
 	)"
 };
 
-template (value) GSUP_SM_RP_OA ts_GSUP_SM_RP_OA_MSISDN(hexstring msisdn) := {
+template (value) GSUP_SM_RP_OA ts_GSUP_SM_RP_OA_MSISDN(GSUP_SM_RP_Addr msisdn) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_MSISDN,
 	id_enc := { msisdn := msisdn }
 }
-template GSUP_SM_RP_OA tr_GSUP_SM_RP_OA_MSISDN(template hexstring msisdn) := {
+template GSUP_SM_RP_OA tr_GSUP_SM_RP_OA_MSISDN(template GSUP_SM_RP_Addr msisdn) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_MSISDN,
 	id_enc := { msisdn := msisdn }
 }
 
-template (value) GSUP_SM_RP_OA ts_GSUP_SM_RP_OA_SMSC_ADDR(hexstring smsc_addr) := {
+template (value) GSUP_SM_RP_OA ts_GSUP_SM_RP_OA_SMSC_ADDR(GSUP_SM_RP_Addr smsc_addr) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_SMSC_ADDR,
 	id_enc := { smsc_addr := smsc_addr }
 }
-template GSUP_SM_RP_OA tr_GSUP_SM_RP_OA_SMSC_ADDR(template hexstring smsc_addr) := {
+template GSUP_SM_RP_OA tr_GSUP_SM_RP_OA_SMSC_ADDR(template GSUP_SM_RP_Addr smsc_addr) := {
 	id_type := OSMO_GSUP_SM_RP_ODA_ID_SMSC_ADDR,
 	id_enc := { smsc_addr := smsc_addr }
 }