From f4c0d6e8199bf778b6ad0ecba263f4c036eb5c07 Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Thu, 2 Oct 2014 13:12:10 +0000
Subject: [PATCH] To resolv mnc length

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5830 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/MME_APP/mme_app_authentication.c | 25 +++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/openair-cn/MME_APP/mme_app_authentication.c b/openair-cn/MME_APP/mme_app_authentication.c
index 99c6089ade..1e06be4225 100644
--- a/openair-cn/MME_APP/mme_app_authentication.c
+++ b/openair-cn/MME_APP/mme_app_authentication.c
@@ -40,6 +40,7 @@
 
 #include "mme_app_ue_context.h"
 #include "mme_app_defs.h"
+#include "mcc_mnc_itu.h"
 
 #include "assertions.h"
 
@@ -341,6 +342,7 @@ mme_app_handle_nas_auth_param_req(
     plmn_t              *visited_plmn  = NULL;
     struct ue_context_s *ue_context    = NULL;
     uint64_t             imsi          = 0;
+    int                  mnc_length    = 0;
     plmn_t               visited_plmn_from_req = {
             .MCCdigit3 = 0,
             .MCCdigit2 = 0,
@@ -355,13 +357,28 @@ mme_app_handle_nas_auth_param_req(
     //visited_plmn = &visited_plmn_dongle;
     visited_plmn = &visited_plmn_from_req;
 
-#warning "assume MNC on 2 digits only"
     visited_plmn_from_req.MCCdigit3 = nas_auth_param_req_pP->imsi[0];
     visited_plmn_from_req.MCCdigit2 = nas_auth_param_req_pP->imsi[1];
     visited_plmn_from_req.MCCdigit1 = nas_auth_param_req_pP->imsi[2];
-    visited_plmn_from_req.MNCdigit1 = 0;
-    visited_plmn_from_req.MNCdigit2 = nas_auth_param_req_pP->imsi[3];
-    visited_plmn_from_req.MNCdigit3 = nas_auth_param_req_pP->imsi[4];
+
+    mnc_length = find_mnc_length(nas_auth_param_req_pP->imsi[0],
+            nas_auth_param_req_pP->imsi[1],
+            nas_auth_param_req_pP->imsi[2],
+            nas_auth_param_req_pP->imsi[3],
+            nas_auth_param_req_pP->imsi[4],
+            nas_auth_param_req_pP->imsi[5]
+            );
+    if (mnc_length == 2) {
+        visited_plmn_from_req.MNCdigit1 = 0;
+        visited_plmn_from_req.MNCdigit2 = nas_auth_param_req_pP->imsi[3];
+        visited_plmn_from_req.MNCdigit3 = nas_auth_param_req_pP->imsi[4];
+    } else if (mnc_length == 3) {
+        visited_plmn_from_req.MNCdigit1 = nas_auth_param_req_pP->imsi[3];
+        visited_plmn_from_req.MNCdigit2 = nas_auth_param_req_pP->imsi[4];
+        visited_plmn_from_req.MNCdigit3 = nas_auth_param_req_pP->imsi[5];
+    } else {
+        AssertFatal(0, "MNC Not found (mcc_mnc_list)");
+    }
 
     MME_APP_STRING_TO_IMSI(nas_auth_param_req_pP->imsi, &imsi);
 
-- 
GitLab