Commit 94bced26 authored by Yann Garcia's avatar Yann Garcia
Browse files

Reorder postamble to get UE deregistration

parent a17613c0
Loading
Loading
Loading
Loading
+11 −6
Changes for ttcn/AtsNGAP/NGAP_Steps.ttcn: 11 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -179,9 +179,10 @@ module NGAP_Steps { // TODO FSCOM f_xxx_UE_SecurityMode to be mmoved into NAG_NG

        /**
         * @brief  Postamble of the test cases where the SUT is a gNB.
         * @details Releases the UE context from the AMF side (f_postambleNGAP_gNB): with a real UE
         *          (PICS_USE_AT_COMMANDS) with the cause "normal release", otherwise with p_Cause. A real UE is
         *          then switched to flight mode and its deregistration served (f_NGAP_gnb_UE_Deregister). With
         * @details A real UE (PICS_USE_AT_COMMANDS) is first switched to flight mode and its deregistration
         *          served, which releases its UE context (f_NGAP_gnb_UE_Deregister); the UE context, if still
         *          there, is then released from the AMF side (f_postambleNGAP_gNB) with the cause "normal
         *          release". Without a real UE, the UE context is released with p_Cause. With
         *          PICS_USE_UERANSIMU, also stops the UERANSIM UE and gNB. Deactivates the defaults.
         * @param  p_Cause The cause of the UE context release when no real UE is used.
         */
@@ -190,8 +191,11 @@ module NGAP_Steps { // TODO FSCOM f_xxx_UE_SecurityMode to be mmoved into NAG_NG
                                      ) runs on gNBNGAPComponent {

            if (PICS_USE_AT_COMMANDS) {
                f_postambleNGAP_gNB(m_cause_nas(normal_release));
                // Deregister first, while the UE may still be in CM-CONNECTED: in CM-IDLE, the RM520N-GL
                // detaches locally, without any DEREGISTRATION REQUEST. A served deregistration releases the
                // UE context, and f_postambleNGAP_gNB then has nothing left to release (vc_ueContextReleased)
                f_NGAP_gnb_UE_Deregister();
                f_postambleNGAP_gNB(m_cause_nas(normal_release));
            } else {
                f_postambleNGAP_gNB(p_Cause);
            }
@@ -910,8 +914,9 @@ module NGAP_Steps { // TODO FSCOM f_xxx_UE_SecurityMode to be mmoved into NAG_NG
         *          this modem detaches locally, without signalling, on AT+CFUN=4 alone in 5GMM-IDLE), without
         *          waiting for the confirmation, then serves the
         *          deregistration the UE starts on its own (f_await_deregistration_request_send_ue_context_release):
         *          its DEREGISTRATION REQUEST, the DEREGISTRATION ACCEPT unless it is a switch off, and the release
         *          of its UE context. The UE does not stay registered with, or connected to, the gNB between tests,
         *          its DEREGISTRATION REQUEST (in an UPLINK NAS TRANSPORT if the UE context is not released yet, in
         *          an INITIAL UE MESSAGE otherwise), the DEREGISTRATION ACCEPT unless it is a switch off, and the
         *          release of its UE context. The UE does not stay registered with, or connected to, the gNB between tests,
         *          its PDU sessions are released, and its stored 5G-GUTI and security context are those of a
         *          completed deregistration. The next test restarts the modem (f_NGAP_gnb_UE_Register).
         *          Best effort: a UE that does not deregister within PX_UT_DEREGISTER_TIMEOUT (e.g. it was not
+72 −38
Changes for ttcn/LibNGAP/lib_system/LibNGAP_Functions.ttcn: 72 added lines, 38 removed lines.
Original line number Diff line number Diff line
@@ -2109,24 +2109,41 @@ module LibNGAP_Functions {
    } // End of function f_send_ue_context_release_command_await_service_request_send_service_accept

    /**
     * @brief  Serve the deregistration of a UE in 5GMM-IDLE, then release its UE context (test system = AMF).
     * @details Best effort, for the end of a test: awaits, for up to p_timeout, an INITIAL UE MESSAGE carrying a
     *          DEREGISTRATION REQUEST (UE originating, TS 24.501 clause 5.5.2.2). Unless it is a switch off, the
     *          DEREGISTRATION ACCEPT (UE originating, clause 8.2.13), integrity protected and ciphered, is sent
     *          in a DOWNLINK NAS TRANSPORT. The UE context is then released with the cause "deregister" (UE
     *          CONTEXT RELEASE COMMAND/COMPLETE, the COMPLETE being checked).
     *          Nothing received in time, or another NAS message, is only logged: the verdict is left unchanged.
     *          vc_RAN_UE_ID is updated.
     * @param  p_timeout Time, in seconds, to wait for the INITIAL UE MESSAGE.
     * @brief  Serve the deregistration of a UE, then release its UE context (test system = AMF).
     * @details Best effort, for the end of a test: awaits, for up to p_timeout, a DEREGISTRATION REQUEST (UE
     *          originating, TS 24.501 clause 5.5.2.2), in an UPLINK NAS TRANSPORT if the UE is in CM-CONNECTED
     *          (its UE context is not released, vc_ueContextReleased false), or in an INITIAL UE MESSAGE if it is in
     *          CM-IDLE (vc_RAN_UE_ID is then updated). Unless it is a switch off, the DEREGISTRATION ACCEPT (UE
     *          originating, clause 8.2.13), integrity protected and ciphered, is sent in a DOWNLINK NAS TRANSPORT.
     *          The UE context is then released with the cause "deregister" (UE CONTEXT RELEASE COMMAND/COMPLETE,
     *          the COMPLETE being checked).
     *          Nothing received in time, or another NAS message, is only logged and nothing is released: the
     *          verdict is left unchanged.
     * @param  p_timeout Time, in seconds, to wait for the DEREGISTRATION REQUEST.
     * @return true if the UE deregistered and its context was released.
     */
    function f_await_deregistration_request_send_ue_context_release(in float p_timeout) runs on NGNASComponent return boolean {
        var NGAP_PDU v_pdu;
        var NG_NAS_UL_Message_Type v_message;
        timer t_dereg := p_timeout;

        log(">>> f_await_deregistration_request_send_ue_context_release");
        // The timer runs for the whole wait: other NAS messages the UE sends first (e.g. the release of its
        // PDU sessions) are only logged
        t_dereg.start;
        while (true) {
            alt {
                [not vc_ueContextReleased] N2_gNBaMF_P.receive(
                                                               mw_ngap_initMsg(
                                                                               {
                                                                                   procedureCode := id_UplinkNASTransport,
                                                                                   criticality   := ?,
                                                                                   value_        := ?
                                                                               }
                                                               )) -> value v_pdu {
                    // CM-CONNECTED: on the current UE-associated signalling connection
                    f_NGAPPDU_Get(v_pdu);
                }
                [] N2_gNBaMF_P.receive(
                                       mw_ngap_initMsg(
                                                       {
@@ -2135,24 +2152,26 @@ module LibNGAP_Functions {
                                                           value_        := ?
                                                       }
                                       )) -> value v_pdu {
                t_dereg.stop;
                    // CM-IDLE: on a new signalling connection
                    f_NGAPPDU_Get(v_pdu);
                    vc_RAN_UE_ID := vc_recvNGAP_PDU.initiatingMessage.value_.InitialUEMessage.protocolIEs[f_NGAP_getIEIndex(vc_recvNGAP_PDU, id_RAN_UE_NGAP_ID)].value_.rAN_UE_NGAP_ID;
                }
                [] t_dereg.timeout {
                log("f_await_deregistration_request_send_ue_context_release: INFO: no INITIAL UE MESSAGE within ", p_timeout, " s");
                    log("f_await_deregistration_request_send_ue_context_release: INFO: no DEREGISTRATION REQUEST within ", p_timeout, " s");
                    return false;
                }
            }
        vc_RAN_UE_ID := vc_recvNGAP_PDU.initiatingMessage.value_.InitialUEMessage.protocolIEs[f_NGAP_getIEIndex(vc_recvNGAP_PDU, id_RAN_UE_NGAP_ID)].value_.rAN_UE_NGAP_ID;

            // In CM-CONNECTED, the message is ciphered: f_NASPDU_Get only removes an integrity protection
            f_NASPDU_Get(vc_recvNGAP_PDU);
        if (not ischosen(vc_recvNgNasUl_Msg.deregistration_RequestMO)) {
            log("f_await_deregistration_request_send_ue_context_release: INFO: not a DEREGISTRATION REQUEST: ", vc_recvNgNasUl_Msg);
            return false;
            if (f_NG_NAS_UL_GetPlainMessage(v_message) and ischosen(v_message.deregistration_RequestMO)) {
                t_dereg.stop;
                break;
            }
        log("f_await_deregistration_request_send_ue_context_release: DEREGISTRATION REQUEST, type: ", vc_recvNgNasUl_Msg.deregistration_RequestMO.deregistrationType);
            log("f_await_deregistration_request_send_ue_context_release: INFO: not a DEREGISTRATION REQUEST, still waiting: ", v_message);
        }
        log("f_await_deregistration_request_send_ue_context_release: DEREGISTRATION REQUEST, type: ", v_message.deregistration_RequestMO.deregistrationType);

        if (vc_recvNgNasUl_Msg.deregistration_RequestMO.deregistrationType.switchOff == '0'B) {
        if (v_message.deregistration_RequestMO.deregistrationType.switchOff == '0'B) {
            var NG_SECURITY_PROTECTED_NAS_MESSAGE v_security_Protected_Nas_Message;
            vc_sendNAS_PDU := f_EncodeAndCipher_NG_NasPdu_v(
                                                            tsc_SHT_IntegrityProtected_Ciphered,
@@ -2174,6 +2193,40 @@ module LibNGAP_Functions {
        return f_send_ue_context_release_command_await_ue_context_release_complete(m_cause_nas(deregister));
    } // End of function f_await_deregistration_request_send_ue_context_release

    /**
     * @brief  Decode the last uplink NAS message received (vc_recvNAS_PDU), removing its security protection.
     * @details A security protected message is deciphered first if it is ciphered (current 5G NAS security
     *          context, uplink), then its plain NAS message is decoded. Its MAC is not checked.
     * @param  p_message The plain NAS message.
     * @return false if the message cannot be decoded.
     */
    function f_NG_NAS_UL_GetPlainMessage(out NG_NAS_UL_Message_Type p_message) runs on NGNASComponent return boolean {
        var bitstring v_bs := oct2bit(vc_recvNAS_PDU);

        if (decvalue(v_bs, p_message) != 0) {
            log("f_NG_NAS_UL_GetPlainMessage: decvalue failure: ", vc_recvNAS_PDU);
            return false;
        }
        if (ischosen(p_message.security_Protected_Nas_Message)) {
            var octetstring v_cleartext := p_message.security_Protected_Nas_Message.plainNASMessage;
            if (p_message.security_Protected_Nas_Message.securityHeaderType == tsc_SHT_IntegrityProtected_Ciphered) {
                v_cleartext := fx_NG_NasDeciphering(p_message.security_Protected_Nas_Message.plainNASMessage,
                                                    vc_ng_nas_security_params_type.NAS_Ciphering.Algorithm,
                                                    vc_ng_nas_security_params_type.NAS_Ciphering.K_NAS,
                                                    p_message.security_Protected_Nas_Message.messageAuthenticationCode,
                                                    PX_BEARER_ID,
                                                    tsc_DirectionUL
                                                    );
            }
            v_bs := oct2bit(v_cleartext);
            if (decvalue(v_bs, p_message) != 0) {
                log("f_NG_NAS_UL_GetPlainMessage: decvalue failure on the protected message: ", v_cleartext);
                return false;
            }
        }
        return true;
    } // End of function f_NG_NAS_UL_GetPlainMessage

    /**
     * @brief  Get the PDU session identity and the procedure transaction identity of the last PDU SESSION ESTABLISHMENT REQUEST.
     * @details The request is carried in an UL NAS TRANSPORT protected with the current security context
@@ -2187,32 +2240,13 @@ module LibNGAP_Functions {
                                                         out O1_Type p_psi,
                                                         out O1_Type p_pti
                                                         ) runs on NGNASComponent return boolean {
        var bitstring v_bs := oct2bit(vc_recvNAS_PDU);
        var NG_NAS_UL_Message_Type v_message;

        p_psi := '00'O;
        p_pti := '00'O;
        if (decvalue(v_bs, v_message) != 0) {
            log("f_get_pdu_session_establishment_request_ids: decvalue failure");
        if (not f_NG_NAS_UL_GetPlainMessage(v_message)) {
            return false;
        }
        if (ischosen(v_message.security_Protected_Nas_Message)) {
            var octetstring v_cleartext := v_message.security_Protected_Nas_Message.plainNASMessage;
            if (v_message.security_Protected_Nas_Message.securityHeaderType == tsc_SHT_IntegrityProtected_Ciphered) {
                v_cleartext := fx_NG_NasDeciphering(v_message.security_Protected_Nas_Message.plainNASMessage,
                                                    vc_ng_nas_security_params_type.NAS_Ciphering.Algorithm,
                                                    vc_ng_nas_security_params_type.NAS_Ciphering.K_NAS,
                                                    v_message.security_Protected_Nas_Message.messageAuthenticationCode,
                                                    PX_BEARER_ID,
                                                    tsc_DirectionUL
                                                    );
            }
            v_bs := oct2bit(v_cleartext);
            if (decvalue(v_bs, v_message) != 0) {
                log("f_get_pdu_session_establishment_request_ids: decvalue failure on the protected message");
                return false;
            }
        }
        if (not ischosen(v_message.ul_Nas_Transport)) {
            log("f_get_pdu_session_establishment_request_ids: not an UL NAS TRANSPORT: ", v_message);
            return false;