Commit 22d86add authored by Yann Garcia's avatar Yann Garcia
Browse files

Adding ttcn/Lib_NG_NAS/LIB_NG_NAS_Functions.ttcn

parent 7192b54b
Loading
Loading
Loading
Loading
+133 −0
Original line number Diff line number Diff line
module LIB_NG_NAS_Functions {

    // NG_NAS
    import from NG_NAS_MsgContainers all;
    import from NG_NAS_TypeDefs all;

    // LibNGAP
    import from NGAP_IEs language "ASN.1:2002" all;
    import from NGAP_Constants language "ASN.1:2002" all;
    import from NGAP_PDU_Descriptions language "ASN.1:1997" all;

    function f_Check_5GAKA_AuthenticationRequest(
                                                 in NGAP_PDU p_ngap_pdu,
                                                 in integer p_id,
                                                 out NG_AUTHENTICATION_REQUEST p_ng_authentication_request
                                                 ) return boolean {
        log(">>> f_Check_5GAKA_AuthenticationRequest: ", p_ngap_pdu);

        var integer i;
        for (i := 0; i < lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs); i := i + 1) { // TODO Create a find protocolIEs based on id
            if (p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].id == p_id) {
                break;
            }
        }
        if (i == lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs)) {
            log("f_Check_5GAKA_AuthenticationRequest: IE not found");
            return false;
        }

        var NAS_PDU v_nas_pdu := valueof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].value_.nAS_PDU);
        log("f_Check_5GAKA_AuthenticationRequest: v_nas_pdu: ", v_nas_pdu);
        var bitstring v_bs := oct2bit(v_nas_pdu);
        var NG_NAS_DL_Message_Type v_request;
        if (decvalue(v_bs, v_request) != 0) {
            log("f_Check_5GAKA_AuthenticationRequest: decvalue failure");
            return false;
        }
        log("f_Check_5GAKA_AuthenticationRequest: v_request: ", v_request);
        if (not(ischosen(v_request.authentication_Request))) {
            log("f_Check_5GAKA_AuthenticationRequest: Wrong variant");
            return false;           
        }
        p_ng_authentication_request := v_request.authentication_Request;
        log("f_Check_5GAKA_AuthenticationRequest: p_ng_authentication_request: ", p_ng_authentication_request);

        return true;
    }

    function f_Check_5GAKA_AuthenticationResponse(
                                                  in NGAP_PDU p_ngap_pdu,
                                                  in integer p_id,
                                                  out NG_AUTHENTICATION_RESPONSE p_ng_authentication_response
                                                  ) return boolean {
        log(">>> f_Check_5GAKA_AuthenticationResponse: ", p_ngap_pdu);

        var integer i;
        for (i := 0; i < lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs); i := i + 1) { // TODO Create a find protocolIEs based on id
            if (p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].id == p_id) {
                break;
            }
        }
        if (i == lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs)) {
            log("f_Check_5GAKA_AuthenticationResponse: IE not found");
            return false;
        }

        var NAS_PDU v_nas_pdu := valueof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].value_.nAS_PDU);
        log("f_Check_5GAKA_AuthenticationResponse: v_nas_pdu: ", v_nas_pdu);
        var bitstring v_bs := oct2bit(v_nas_pdu);
        var NG_NAS_UL_Message_Type v_response;
        if (decvalue(v_bs, v_response) != 0) {
            log("f_Check_5GAKA_AuthenticationResponse: decvalue failure");
            return false;
        }
        log("f_Check_5GAKA_AuthenticationResponse: v_response: ", v_response);
        if (not(ischosen(v_response.authentication_Response))) {
            log("f_Check_5GAKA_AuthenticationResponse: Wrong variant");
            return false;           
        }
        p_ng_authentication_response := v_response.authentication_Response;
        log("f_Check_5GAKA_AuthenticationResponse: p_ng_authentication_response: ", p_ng_authentication_response);

        return true;
    }

    function f_Check_5GAKA_SecurityModeCommand(
                                                  in NGAP_PDU p_ngap_pdu,
                                                  in integer p_id,
                                                  out NG_SECURITY_MODE_COMMAND p_ng_security_mode_command
                                                  ) return boolean {
        log(">>> f_Check_5GAKA_SecurityModeCommand: ", p_ngap_pdu);

        var integer i;
        for (i := 0; i < lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs); i := i + 1) { // TODO Create a find protocolIEs based on id
            if (p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].id == p_id) {
                break;
            }
        }
        if (i == lengthof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs)) {
            log("f_Check_5GAKA_SecurityModeCommand: IE not found");
            return false;
        }

        var NAS_PDU v_nas_pdu := valueof(p_ngap_pdu.initiatingMessage.value_.downlinkNASTransport.protocolIEs[i].value_.nAS_PDU);
        log("f_Check_5GAKA_SecurityModeCommand: v_nas_pdu: ", v_nas_pdu);
        var bitstring v_bs := oct2bit(v_nas_pdu);
        var NG_NAS_DL_Message_Type v_response;
        var NG_SECURITY_PROTECTED_NAS_MESSAGE v_security_Protected_Nas_Message;
        if (decvalue(v_bs, v_security_Protected_Nas_Message) == 0) {
            log("f_Check_5GAKA_SecurityModeCommand: v_response: ", v_security_Protected_Nas_Message);
            v_nas_pdu := v_security_Protected_Nas_Message.plainNASMessage;
            log("f_Check_5GAKA_SecurityModeCommand: Next v_nas_pdu: ", v_nas_pdu);
            v_bs := oct2bit(v_nas_pdu);
            if (decvalue(v_bs, v_response) != 0) {
                log("f_Check_5GAKA_SecurityModeCommand: decvalue failure");
                return false;
            }
        } else {
            log("f_Check_5GAKA_SecurityModeCommand: decvalue failure");
            return false;
        }
        log("f_Check_5GAKA_SecurityModeCommand: v_response: ", v_response);
        if (not(ischosen(v_response.security_Mode_Command))) {
            log("f_Check_5GAKA_SecurityModeCommand: Wrong variant");
            return false;           
        }
        p_ng_security_mode_command := v_response.security_Mode_Command;
        log("f_Check_5GAKA_SecurityModeCommand: p_ng_security_mode_command: ", p_ng_security_mode_command);

        return true;
    }

} // End of module LIB_NG_NAS_Functions
 No newline at end of file