Harald Welte has submitted this change and it was merged.

Change subject: GSUP: Fix handling of odd-length IMSI and 0xF filler digit
......................................................................


GSUP: Fix handling of odd-length IMSI and 0xF filler digit

Change-Id: I4e0a9f1236504ce6026c6e34fd97fda6fefa832c
---
M library/GSUP_Types.ttcn
M library/IPA_Emulation.ttcn
2 files changed, 24 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/GSUP_Types.ttcn b/library/GSUP_Types.ttcn
index 15560c7..a8134eb 100644
--- a/library/GSUP_Types.ttcn
+++ b/library/GSUP_Types.ttcn
@@ -138,6 +138,26 @@
 external function dec_GSUP_PDU(in octetstring msg) return GSUP_PDU
        with { extension "prototype(convert) decode(RAW)" };
 
+function f_gsup_postprocess_decoded(inout GSUP_PDU gsup) {
+       if (gsup.ies[0].tag == OSMO_GSUP_IMSI_IE) {
+               /* if last digit is 'F', then there's an odd number of digits 
and we must strip the F */
+               var integer num_digits := lengthof(gsup.ies[0].val.imsi);
+               if (gsup.ies[0].val.imsi[num_digits-1] == 'F'H) {
+                       gsup.ies[0].val.imsi := substr(gsup.ies[0].val.imsi, 0, 
num_digits-1);
+               }
+       }
+}
+
+function f_gsup_preprocess_encoded(inout GSUP_PDU gsup) {
+       if (ischosen(gsup.ies[0].val.imsi)) {
+               /* if number of digits is odd, add a 'F' as padding at the end 
*/
+               var integer num_digits := lengthof(gsup.ies[0].val.imsi);
+               if (num_digits rem 2 == 1) {
+                       gsup.ies[0].val.imsi := gsup.ies[0].val.imsi & 'F'H;
+               }
+       }
+}
+
 
 template GSUP_IE ts_GSUP_IE_AuthTuple2G(octetstring rand, octetstring sres,
                                        octetstring kc) := {
diff --git a/library/IPA_Emulation.ttcn b/library/IPA_Emulation.ttcn
index b40818f..b3e28e9 100644
--- a/library/IPA_Emulation.ttcn
+++ b/library/IPA_Emulation.ttcn
@@ -370,7 +370,9 @@
 }
 
 private function f_gsup_to_user(octetstring msg) runs on IPA_Emulation_CT {
-       IPA_GSUP_PORT.send(dec_GSUP_PDU(msg));
+       var GSUP_PDU gsup := dec_GSUP_PDU(msg);
+       f_gsup_postprocess_decoded(gsup);
+       IPA_GSUP_PORT.send(gsup);
 }
 
 private function f_mgcp_to_ud(octetstring payload) runs on IPA_Emulation_CT 
return ASP_IPA_Unitdata {
@@ -480,6 +482,7 @@
                }
 
                [] IPA_GSUP_PORT.receive(GSUP_PDU:?) -> value gsup_msg {
+                       f_gsup_preprocess_encoded(gsup_msg);
                        payload := enc_GSUP_PDU(gsup_msg);
                        ipa_ud := valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, 
payload, IPAC_PROTO_EXT_GSUP));
                        IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud));

-- 
To view, visit https://gerrit.osmocom.org/6040
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4e0a9f1236504ce6026c6e34fd97fda6fefa832c
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder

Reply via email to