// ***************************************************************************
// @copyright   Copyright Notification
//   No part may be reproduced except as authorized by written permission.
//   The copyright and the foregoing restriction extend to reproduction in all media.
//   Trademark 2010, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_10wk37
// * $Date: 2010-07-17 04:11:00 +0200 (Sat, 17 Jul 2010) $
// * $Rev: 3560 $
// ***************************************************************************

module NAS_Paging {

  import from EUTRA_Component all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_SecurityFunctions all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_Paging all;
  import from EPS_NAS_Constants all;
  import from EPS_NAS_Templates all;
  import from EUTRA_RRCSteps all;
  import from EPS_NAS_MsgContainers all;
  import from EUTRA_ASP_SrbDefs all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_SRB_Templates all;


  group LocalTemplates {

  template InitialUE_Identity cr_InitialUE_Identity_S_TMSI ( MMEC p_Mmec,
                                                           M_TMSI_Type p_M_Tmsi ) :=
  { /* @status    APPROVED */
    s_TMSI := {
      mmec := p_Mmec,
      m_TMSI := p_M_Tmsi
    }
  };

  } // group LocalTemplates

  group LocalFunctions {
  } // group LocalFunctions

  group TestcaseImplementations {

  ///////////////////////////////////////////////////////////////////////////////
  // TC 9.3.2.1
  ///////////////////////////////////////////////////////////////////////////////
  /*
   * @desc      REFERENCE TS 36.523-1 clause 9.3.2.1
   * @status    APPROVED
   */
  function f_TC_9_3_2_1_EUTRA() runs on EUTRA_PTC
  {
    /// @desc Paging procedure

    // (1)
    // with { UE in ECM-IDLE }
    // ensure that {
    // when { the network initiates a paging procedure for EPS services using S-TMSI }
    // then { the UE responds to the paging with a SERVICE REQUEST message providing correct S-TMSI in the RRCConnectionRequest }
    //           }



    // Pre-test conditions
    // -------------------
    // System Simulator:
    //   - Cell A
    // UE:
    //   - None.

    f_EUTRA_NAS_Init(LTE_AllCellsOnSamePLMN, LTEsinglecell);

    // create cell and send out system information
    f_EUTRA_CellConfig_Def (eutra_CellA);

    // Preamble: The UE is in Registered, Idle Mode (state 2)
    // ==========================================================================
    f_EUTRA_Preamble(eutra_CellA, STATE2_IDLEUPDATE);
    f_EUTRA_TestBody_Set(true);

    fl_TC_9_3_2_1_Body();

    // Postamble
    f_EUTRA_TestBody_Set(false);
    f_EUTRA_Postamble(eutra_CellA, E2_CONNECTED);//@sic R5-103875 sic@
  } // function f_TC_9_3_2_1_EUTRA

  /*
   * @desc      test body of 9.3.2.1
   * @status    APPROVED
   */
  function fl_TC_9_3_2_1_Body() runs on EUTRA_PTC
  {
    // ==========================================================================
    // initialize component specific data structures
    // ==========================================================================
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var SRB_COMMON_IND v_ReceivedAsp;
    // get all data which are required for a GUTI
    var GutiParameters_Type v_GutiParams := f_EUTRA_CellInfo_GetGuti(eutra_CellA);
    // initialize security parameters
    var EUTRA_SecurityParams_Type v_SecurityParams := f_EUTRA_Security_Get();
    // ==========================================================================


    //+   SS pages the UE using S-TMSI with CN domain indicator set to 'PS'
    //@siclog "Step 1" siclog@
    f_EUTRA_UE_Page(eutra_CellA,
                    cs_NasPaging_OneRecord(cs_PagingUE_Identity_S_TMSI(v_GutiParams.MME_Code,
                                                                       v_GutiParams.M_TMSI)));

    //+   Check: Does the UE respond with a SERVICE REQUEST message?
    //+   Check: Does the UE provide correct S-TMSI in the
    //+          RRCConnectionRequest? --> SERVICE REQUEST [1,P]
    //@siclog "Steps 2 - 3" siclog@
    SRB.receive(car_SRB0_RrcPdu_IND(eutra_CellA,
                                    cr_RRCConnectionRequest_withUE_Identity(cr_InitialUE_Identity_S_TMSI(v_GutiParams.MME_Code,
                                                                                                         v_GutiParams.M_TMSI),cr_EstablishmentCause_mt_Access)));
    f_EUTRA_RRC_ConnectionSetup_Def (eutra_CellA, cs_TimingInfo_Now, tsc_RRC_TI_Def);
    SRB.receive(car_SRB1_RrcNasPdu_IND(eutra_CellA,
                                     cr_508_RRCConnectionSetupComplete(tsc_RRC_TI_Def, ?),
                                       cr_NAS_Indication(tsc_SHT_IntegrityProtected,
                                                         cr_508_SERVICE_REQUEST(v_SecurityParams.KSIasme))))
            -> value v_ReceivedAsp;                    // @sic R5-102180 sic@
    f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Step 2");

    // Step 4-7: @sic R5-102180 sic@
    // Steps 6 to 9 of the generic radio bearer establishment procedure (TS 36.508 5.4.3.3-1) are executed
    // to successfully complete the service request procedure
    //@siclog "Steps 4 - 7" siclog@
    v_NAS_Ind := v_ReceivedAsp.Signalling.Nas[0];
    f_EUTRA_ServiceReqPostamble_508Steps6_9 (eutra_CellA, v_NAS_Ind);



  } // function fl_TC_9_3_2_1_Body

  } // group TestcaseImplementations

} // module NAS_Paging
