From a827db0c32e0b62ab0fc8815e6f2b6e533562fb8 Mon Sep 17 00:00:00 2001
From: roux <roux@mycompany.com>
Date: Thu, 2 Jul 2015 10:25:37 +0000
Subject: [PATCH] Reply RRCConnectionReestablishementReject to all
 RRCConnectionReestablishmentRequest so that the UE disconnects a bit more
 properly.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7681 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/RRC/LITE/MESSAGES/asn1_msg.c | 59 +++++++++++++++++++++++++++
 openair2/RRC/LITE/MESSAGES/asn1_msg.h | 10 +++++
 openair2/RRC/LITE/proto.h             | 11 +++++
 openair2/RRC/LITE/rrc_eNB.c           | 51 ++++++++++++++++++++++-
 4 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/openair2/RRC/LITE/MESSAGES/asn1_msg.c b/openair2/RRC/LITE/MESSAGES/asn1_msg.c
index 5ce5203014..0ec3a29590 100644
--- a/openair2/RRC/LITE/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/LITE/MESSAGES/asn1_msg.c
@@ -2045,6 +2045,64 @@ do_RRCConnectionReconfiguration(
   return((enc_rval.encoded+7)/8);
 }
 
+//------------------------------------------------------------------------------
+uint8_t
+do_RRCConnectionReestablishmentReject(
+  uint8_t                    Mod_id,
+  uint8_t*                   const buffer)
+//------------------------------------------------------------------------------
+{
+
+  asn_enc_rval_t enc_rval;
+
+  DL_CCCH_Message_t dl_ccch_msg;
+  RRCConnectionReestablishmentReject_t *rrcConnectionReestablishmentReject;
+
+  memset((void *)&dl_ccch_msg,0,sizeof(DL_CCCH_Message_t));
+  dl_ccch_msg.message.present           = DL_CCCH_MessageType_PR_c1;
+  dl_ccch_msg.message.choice.c1.present = DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject;
+  rrcConnectionReestablishmentReject    = &dl_ccch_msg.message.choice.c1.choice.rrcConnectionReestablishmentReject;
+
+  // RRCConnectionReestablishmentReject
+  rrcConnectionReestablishmentReject->criticalExtensions.present = RRCConnectionReestablishmentReject__criticalExtensions_PR_rrcConnectionReestablishmentReject_r8;
+
+#ifdef XER_PRINT
+  xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
+#endif
+  enc_rval = uper_encode_to_buffer(&asn_DEF_DL_CCCH_Message,
+                                   (void*)&dl_ccch_msg,
+                                   buffer,
+                                   100);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+
+#if defined(ENABLE_ITTI)
+# if !defined(DISABLE_XER_SPRINT)
+  {
+    char        message_string[20000];
+    size_t      message_string_size;
+
+    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) {
+      MessageDef *msg_p;
+
+      msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
+      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
+      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
+
+      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p);
+    }
+  }
+# endif
+#endif
+
+#ifdef USER_MODE
+  LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %d bits (%d bytes)\n",
+        enc_rval.encoded,(enc_rval.encoded+7)/8);
+#endif
+
+  return((enc_rval.encoded+7)/8);
+}
+
 uint8_t do_RRCConnectionRelease(
   uint8_t                             Mod_id,
   uint8_t                            *buffer,
@@ -2630,6 +2688,7 @@ EXPORT_SYMBOL(do_RRCConnectionRequest);
 EXPORT_SYMBOL(do_RRCConnectionSetupComplete);
 EXPORT_SYMBOL(do_RRCConnectionReconfigurationComplete);
 EXPORT_SYMBOL(do_RRCConnectionSetup);
+EXPORT_SYMBOL(do_RRCConnectionReestablishmentReject);
 EXPORT_SYMBOL(do_RRCConnectionReconfiguration);
 EXPORT_SYMBOL(asn_DEF_UL_DCCH_Message);
 EXPORT_SYMBOL(asn_DEF_UL_CCCH_Message);
diff --git a/openair2/RRC/LITE/MESSAGES/asn1_msg.h b/openair2/RRC/LITE/MESSAGES/asn1_msg.h
index 250712948a..d1516feccc 100644
--- a/openair2/RRC/LITE/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/LITE/MESSAGES/asn1_msg.h
@@ -208,6 +208,16 @@ do_RRCConnectionReconfiguration(
 #endif
                                         );
 
+/**
+\brief Generate an RRCConnectionReestablishmentReject DL-CCCH-Message (eNB).
+@param Mod_id Module ID of eNB
+@param buffer Pointer to PER-encoded ASN.1 description of DL-CCCH-Message PDU
+@returns Size of encoded bit stream in bytes*/
+uint8_t
+do_RRCConnectionReestablishmentReject(
+    uint8_t                    Mod_id,
+    uint8_t*                   const buffer);
+
 /**
 \brief Generate an RRCConnectionRequest UL-CCCH-Message (UE) based on random string or S-TMSI.  This
 routine only generates an mo-data establishment cause.
diff --git a/openair2/RRC/LITE/proto.h b/openair2/RRC/LITE/proto.h
index 80ed256f6e..9fbfadbd85 100644
--- a/openair2/RRC/LITE/proto.h
+++ b/openair2/RRC/LITE/proto.h
@@ -208,6 +208,17 @@ rrc_eNB_generate_RRCConnectionSetup(
   const int                    CC_id
 );
 
+/**\brief Generate RRCConnectionReestablishmentReject
+   \param ctxt_pP       Running context
+   \param ue_context_pP UE context
+   \param CC_id         Component Carrier ID*/
+void
+rrc_eNB_generate_RRCConnectionReestablishmentReject(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_t* const ue_context_pP,
+  const int                    CC_id
+);
+
 /**\brief Process the RRCConnectionSetupComplete based on information coming from UE
    \param ctxt_pP       Running context
    \param ue_context_pP RRC UE context
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index 082f8bad44..ecbfb5c9e7 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -946,6 +946,49 @@ rrc_eNB_generate_UECapabilityEnquiry(
 
 }
 
+//-----------------------------------------------------------------------------
+void
+rrc_eNB_generate_RRCConnectionReestablishmentReject(
+  const protocol_ctxt_t* const ctxt_pP,
+  rrc_eNB_ue_context_t*          const ue_context_pP,
+  const int                    CC_id
+)
+//-----------------------------------------------------------------------------
+{
+#ifdef RRC_MSG_PRINT
+  int                                 cnt;
+#endif
+
+  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
+    do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
+                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload);
+
+#ifdef RRC_MSG_PRINT
+  LOG_F(RRC,"[MSG] RRCConnectionReestablishmentReject\n");
+
+  for (cnt = 0; cnt < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
+    LOG_F(RRC,"%02x ", ((uint8_t*)eNB_rrc_inst[ctxt_pP->module_id].Srb0.Tx_buffer.Payload)[cnt]);
+  }
+
+  LOG_F(RRC,"\n");
+#endif
+
+  MSC_LOG_TX_MESSAGE(
+    MSC_RRC_ENB,
+    MSC_RRC_UE,
+    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Header,
+    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size,
+    MSC_AS_TIME_FMT" RRCConnectionReestablishmentReject UE %x size %u",
+    MSC_AS_TIME_ARGS(ctxt_pP),
+    ue_context_pP == NULL ? -1 ; ue_context_pP->ue_context.rnti,
+    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);
+
+  LOG_I(RRC,
+        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishmentReject (bytes %d)\n",
+        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+        eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);
+}
+
 //-----------------------------------------------------------------------------
 void
 rrc_eNB_generate_RRCConnectionRelease(
@@ -3521,11 +3564,15 @@ rrc_eNB_decode_ccch(
 
       if ((eNB_rrc_inst[enb_mod_idP].phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
       (ue_mod_id != UE_INDEX_INVALID)){
-      rrc_eNB_generate_RRCConnectionReestablishement(enb_mod_idP, frameP, ue_mod_id);
+      rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
       }else {
-      rrc_eNB_generate_RRCConnectionReestablishementReject(enb_mod_idP, frameP, ue_mod_id);
+      rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
       }
       */
+      /* reject all reestablishment attempts for the moment */
+      rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
+                       rrc_eNB_get_ue_context(&eNB_rrc_inst[ctxt_pP->module_id], ctxt_pP->rnti),
+                       CC_id);
       break;
 
     case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
-- 
2.26.2