/**
 *  @author     ETSI / STF422_EETS
 *  @version    $URL:$
 *              $Id:$
 *  @desc       Templates definitions for ITS station management (ISO 24102-3)
 */
module LibItsMgt_Templates {
    
    // LibCommon 
    import from LibCommon_BasicTypesAndValues { 
        type 
            UInt8, UInt16; 
    }; 
    
    // LibIts
    import from CALMiitsscu language "ASN.1:1997" { 
        type 
            PduCounter 
    }; 
    import from CALMmanagement language "ASN.1:1997" { 
        type ITS_scuId 
    }; 
    // FIXME Check why TTWB raises an error on ErrStatus (not found)?
    import from CALMllsap language "ASN.1:1997" all;/*{ 
        type 
            ErrStatus, 
            MedType , CIaClass, CIclass 
    };*/
    import from CALMmsap language "ASN.1:1997" all; 
    import from CALMfntp language "ASN.1:1997" { 
        type PortNumber 
    }; 
    import from LibItsMgt_Pixits {
        modulepar PX_PDU_REQUEST_FILL_FIELD_VALUE
    };
    import from LibItsCalm_Interface { 
        type 
            MgtMFSapCommandReq, MgtMFSapCommandConfirm, MgtMFSapRequestReq, MgtMFSapRequestConfirm, 
            MgtMNSapCommandReq, MgtMNSapCommandConfirm, MgtMNSapRequestReq, MgtMNSapRequestConfirm 
    }; 
    
    group mgtSapTemplates { 
        
        /**
         * @desc MF-SAP service primitives templates
         * @see ISO 24102-3 Clause 8
         */
        group mgtMFSapTemplates {
            
            /**
             * @desc  Send template for MF-SAP service primitives
             * @param p_msg MF-REQUEST.request service primitive to be sent
             */
            template (value) MgtMFSapRequestReq m_mgtMFSapRequestReq(
                in template (value) MF_Request_request p_msg
            ) := {
                msgInOut := p_msg
            }
            
            /**
             * @desc  Receive template for MF-SAP service primitives
             * @param p_msg MF-REQUEST.request service primitive to be received
             */
            template MgtMFSapRequestReq mw_mgtMFSapRequestReq(
                in template (present) MF_Request_request p_msg
            ) := {
                msgInOut := p_msg
            }
            
            /**
             * @desc  Receive template for MF-SAP service primitives
             * @param p_command_request MF-COMMAND.request service primitive to be sent
             */
            template MgtMFSapCommandReq mw_mgtMFSapCommandReq(
                in template (present) MF_Command_request p_command_request
            ) := {
                msgIn := p_command_request
            }
            
            /**
             * @desc  Receive template for MF-SAP service primitives
             * @param p_command_request MF-COMMAND.confirm service primitive to be sent
             */
            template MgtMFSapCommandConfirm mw_mgtMFSapCommandConfirm(
                in template (present) MF_Command_confirm p_command_confirm
            ) := {
                msgIn := p_command_confirm
            }
            
//            /**
//             * @desc  Receive template for MF-SAP service primitives
//             * @param p_msg MF-COMMAND.request service primitive to be sent
//             */
//            template MgtMFSapCommandInd mw_mgtMFSapCommandInd(
//                in template (present) MF_Command_request p_msg
//            ) := {
//                msgIn := p_msg
//            }
//            
            /**
             * @desc  Receive template for MF-SAP service primitives
             * @param p_msg MF-REQUEST.confirm service primitive to be received
             */
            template MgtMFSapRequestConfirm mw_mgtMFSapRequestConfirm(
                in template (present) MF_Request_confirm p_msg
            ) := {
                msgIn := p_msg
            }
            
            /**
             * @desc Templates for MF-SAP
             * @see ISO 24102-3 Clause 8.2
             */
            group mfCommandRequest {
                
                /**
                 * @desc Unspecified receive template for MF-COMMAND.request service primitive
                 * Used for:
                 * <li>modifying restrictif template</li>
                 * <li>default altstep</li>
                 * @see  a_mgtMFSapPortDefault altstep statement
                 */
                template MF_Command_request mw_mfCommandRequest_any := {
                    commandRef := ?,
                    command_param := {
                        fill := ?,
                        mfCmd := ?
                    } // End of 'command_param' field
                } // End of template mw_mfCommandRequest_any
                
                /**
                 * @desc Unspecified receive template for MF-Request.confirm service primitive
                 * Used for:
                 * <li>modifying restrictif template</li>
                 * <li>default altstep</li>
                 * @param   p_errorStatus Error status in response of MF-REQUEST.request service primitive
                 * @see  a_mgtMFSapPortDefault altstep statement
                 */
                template MF_Command_confirm mw_mfCommandConfirm(
                    in template (value) ErrStatus p_errorStatus
                ) := {
                    commandRef := ?,
                    cmdConfirm := {
                        fill := ?,
                        mfCmdConf := ?
                    }, // End of field 'cmdConfirm'
                    errStatus := p_errorStatus
                } // End of template mw_mfCommandConfirm
                
                template MF_Command_confirm mdw_mfCommandConfirm_gCSAMctx(
                    in template (value) ErrStatus p_errorStatus
                ) modifies mw_mfCommandConfirm := {
                    cmdConfirm := {
                        mfCmdConf := { 
                            gCsamctx := ?
                        } // End of field 'mfCmdConf'
                    } // End of field 'cmdConfirm'
                } // End of template mdw_mfCommandConfirm_gCSAMctx
                
                /**
                 * @desc Generic receive template for MF-COMMAND.request service primitive
                 * @param   p_commandRef    TODO
                 * @param   p_mfCmd         TODO
                 */
                template MF_Command_request mdw_CommandRequest( 
                    in template (present) CommandRef p_commandRef, 
                    in template (present) MF_Command p_mfCmd 
                ) := { 
                    commandRef := p_commandRef, 
                    command_param := p_mfCmd
                }  // End of template mdw_CommandRequest
                
            } // End of group mfCommandRequest
            
            group mfRequestRequest {
                
                group mfRequestRequestSend {
                    
                    template (value) MF_Request_request m_RequestRequest( 
                        in template (value) CommandRef p_commandRef, 
                        in template (value) MF_Request p_mfRequest 
                    ) := { 
                        commandRef := p_commandRef, 
                        request_param := p_mfRequest 
                    }  // End of template m_RequestRequest
                    
                } // End of group mfRequestRequestSend
                
                group mfRequestRequestRecv {
                    
                    /**
                     * @desc Unspecified receive template for MF-REQUEST.request service primitive
                     * Used for:
                     * <li>modifying restrictif template</li>
                     * <li>default altstep</li>
                     * @see  a_mgtMFSapPortDefault altstep statement
                     */
                    template MF_Request_request mw_mfRequestRequest_any := {
                        commandRef := ?,
                        request_param := {
                            fill := ?,
                            mfReq := ?
                        } // End of 'request_param' field
                    } // End of template mw_mfRequestRequest_any
                    
                    /**
                     * @desc Unspecified receive template for MF-Request.confirm service primitive
                     * Used for:
                     * <li>modifying restrictif template</li>
                     * <li>default altstep</li>
                     * @param   p_errorStatus Error status in response of MF-REQUEST.request service primitive
                     * @see  a_mgtMFSapPortDefault altstep statement
                     */
                    template MF_Request_confirm mw_mfRequestConfirm(
                        in template ErrStatus p_errorStatus
                    ) := {
                        commandRef := ?,
                        reqConfirm := {
                            fill := ?,
                            mfReqConf := ?
                        }, // End of field 'reqConfirm'
                        errStatus := p_errorStatus
                    } // End of template mw_mfRequestConfirm
                    
                    /**
                     * @desc Generic receive template for MF-REQUEST.request service primitive
                     * @param   p_commandRef    Unique cyclic reference number of command. Same value as in related MN-REQUEST.request
                     * @param   p_mfReq         Command issued by the ITS-S facilities layer and sent to the ITS-S management entity via the MF-SAP
                     */
                    template MF_Request_request mdw_RequestRequest( 
                        in template (present) CommandRef p_commandRef, 
                        in template (present) MF_Request p_mfReq 
                    ) modifies mw_mfRequestRequest_any := { 
                        commandRef := p_commandRef, 
                        request_param := p_mfReq
                    }  // End of template mdw_RequestRequest
                    
                } // End of group mfRequestRequestRecv
                
            } // End of group mfRequestRequest
            
        } // End of group mgtMFSapTemplates
        
        /**
         * @desc MN-SAP service primitives templates
         * @see ISO 24102-3 Clause 7
         */
        group mgtMNSapTemplates {
            
            group mgtMNSapTemplatesSend {
                
                /**
                 * @desc  Send template for MN-SAP service primitives. used to send MN-COMMAND.request when Management is the IUT
                 * @param p_msg MF-COMMAND.request service primitive to be sent
                 * @see ISO 24102-3 Clause 7.2.2
                 */
                template (value) MgtMNSapCommandReq m_mgtMNSapCommandReq(
                    in template (value) MN_Command_request p_msg
                ) := {
                    msgInOut := p_msg
                }
                
                /**
                 * @desc  Send template for MN-SAP service primitives
                 * @param p_msg MF-REQUEST.confirm service primitive to be received
                 * @see ISO 24102-3 Clause 7.3.2
                 */
                template (value) MgtMNSapRequestReq m_mgtMNSapRequestReq(
                    in template (value) MN_Request_request p_msg
                ) := {
                    msgInOut := p_msg
                }
                
            } // End of group mgtMNSapTemplatesSend
            
            group mgtMNSapTemplatesRecv {
                
                /**
                 * @desc  Receive template for MN-SAP service primitives. Used to monitor MN-SAP
                 * @param p_msg MF-COMMAND.request service primitive to be sent
                 * @see ISO 24102-3 Clause 7.2.2
                 */
                template MgtMNSapCommandReq mw_mgtMNSapCommandReq(
                    in template (present) MN_Command_request p_msg
                ) := {
                    msgInOut := p_msg
                }
                
                /**
                 * @desc  Receive template for MN-SAP service primitives
                 * @param p_msg MF-COMMAND.confirm service primitive to be received
                 * @see ISO 24102-3 Clause 7.2.3
                 */
                template MgtMNSapCommandConfirm mw_mgtMNSapCommandConfirm(
                    in template (present) MN_Command_confirm p_msg
                ) := {
                    msgIn := p_msg
                }
                
                /**
                 * @desc  Receive template for MN-SAP service primitives
                 * @param p_msg MF-REQUEST.request service primitive to be received
                 * @see ISO 24102-3 Clause 7.3.2
                 */
                template MgtMNSapRequestReq mw_mgtMNSapRequestReq(
                    in template (present) MN_Request_request p_msg
                ) := {
                    msgInOut := p_msg
                }
                
                /**
                 * @desc  Receive template for MN-SAP service primitives
                 * @param p_msg MF-REQUEST.request service primitive to be received
                 * @see ISO 24102-3 Clause 7.3.3
                 */
                template MgtMNSapRequestConfirm mw_mgtMNSapRequestConfirm(
                    in template (present) MN_Request_confirm p_msg
                ) := {
                    msgIn := p_msg
                }
                
                /**
                 * @desc Unspecified receive template for MN-COMMAND.confirm service primitive
                 * @see a_mgtMNSapPortDefault altstep statement
                 * @see ISO 24102-3 Clause 7.3.3
                 */
                template MN_Command_confirm mw_mnCommandConfirm_any := {
                    commandRef := ?,
                    cmdConfirm := ?,
                    errStatus := ?
                } // End of template mw_mnCommandConfirm_any
                
                /**
                 * @desc Unspecified receive template for MN-REQUEST.request service primitive
                 * Used for:
                 * <li>modifying restrictif template</li>
                 * <li>default altstep</li>
                 * @see a_mgtMNSapPortDefault altstep statement
                 */
                template MN_Request_request mw_mnRequestRequest_any := {
                    commandRef := ?,
                    request_param := ?
                } // End of template mw_mnRequestRequest_any
                
                /**
                 * @desc Unspecified receive template for MN-REQUEST.confirm service primitive
                 * Used for:
                 * <li>modifying restrictif template</li>
                 * <li>default altstep</li>
                 * @see a_mgtMNSapPortDefault altstep statement
                 */
                template MN_Request_confirm mw_mnRequestConfirm_any := {
                    commandRef := ?,
                    reqConfirm := ?,
                    errStatus := ?
                } // End of template mw_mnRequestConfirm_any
                
            } // End of group mgtMNSapTemplatesRecv
            
            group fWTNotifies { 
                
                /**
                 * @desc  Receive "FWTsetNot message" to notify the creation of an entry in a forwarding table
                 * @see ISO 24102-3 Clause E.2.3
                 */
                template (present) MN_Request_request mdw_fWTSetNotRequestReq 
                modifies mw_mnRequestRequest_any := {
                    request_param := {
                        mfReq := {
                            fWTsetNot := {
                                fill := ?,
                                setNot := ?
                            } // End of field 'fWTsetNot'
                        } // End of field 'mfReq'
                    } // End of field 'request_param'
                } // End of template mdw_fWTSetNotRequestReq
                
                /**
                 * @desc  Receive "FWTupdateNot message" to notify update in the FNTP Forwarding Table
                 * @see ISO 24102-3 Clause E.2.4
                 */
//                template MN_Request_request mdw_fWTupdateNotRequestReq 
//                modifies mw_mnRequestRequest_any := {
//                    request_param := {
//                        fWTupdateNot := {
//                            fast := ?
//                        }
//                    }
//                } // End of template mdw_fWTUpdateNotRequestReq
                
                /**
                 * @desc  Receive "FWTdeleteNot message" to notify deletion of an entry in the FNTP Forwarding Table
                 * @see ISO 24102-3 Clause E.2.5
                 */
                 // FIXME To be removed - Moved on NF-SAP
//                template MN_Request_request mdw_fWTdeleteNotRequestReq 
//                modifies mw_mnRequestRequest_any := {
//                    request_param := {
//                        fWTdeleteNot := {
//                            fast := ?
//                        }
//                    }
//                } // End of template mdw_fWTdeleteNotRequestReq
                
            } // End of group fWTNotifies
            
            group fWTcommands {
                
                /**
                 * @desc    Received template on forwarding table update request
                 * @see     ISO 24102-3 Clause D.2.4
                 */
                template MN_Command_request mw_fWTUpdateCommandReq := {
                    commandRef := ?,
                    command_param := {
                        fill := ?,
                        mnCmd := {
                            fWTupdate := mw_fWTupdate
                        } // End of field 'mnCmd'
                    } // End of field 'command_param'
                } // End of template mw_fWTUpdateCommandReq
                
                /**
                 * @desc    Received template on forwarding table change request
                 * @see     ISO 24102-3 D.2.3 FWTset
                 */
                template MN_Command_request mw_fWTSetCommandReq := {
                    commandRef := ?,
                    command_param := {
                        fill := ?,
                        mnCmd := {
                            fWTset := mw_fWTset_any
                        } // End of field 'mnCmd'
                    } // End of field 'command_param'
                } // End of template mw_fWTSetCommandReq
                
                /**
                 * @desc  Receive a "FWTupdate message" to update the FNTP forwarding table
                 * @see ISO 24102-3 Clause E.2.4
                 */
                template FWTupdate mw_fWTupdate := {
                    fill := ?,
                    update := {
                        fntp := {
                            reference := ?
                        } // End of field 'fntp'
                    } // End of field 'update'
                } // End of template mw_fWTupdate
                
                /**
                 * @desc    Generic received template on setting an entry in the forwarding table of a networking protocol
                 * Used for:
                 * <li>modifying restrictif template</li>
                 * <li>default altstep</li>
                 * @see     ISO 24102-3 D.2.3 FWTset
                 */
                template FWTset mw_fWTset_any := {
                        fill := ?,
                        set_ := {
                            fntp := {
                                remotePort := ?,
                                linkID := ?,
                                ciStatus := ?,
                                linkPort := ?,
                                serviceInfo := ?,
                                priority := ?,
                                timeout_ := ?
                            } // End of field 'fntp'
                        } // End of field 'set_'
                } // End of template mw_fWTset_any
                
                /**
                 * @desc    Received template on setting an entry in the forwarding table of a networking protocol
                 * @see     ISO 24102-3 D.2.3 FWTset
                 */
                template FWTset mdw_fWTset( 
                    in template (present) PortNumber p_remotePort
                ) modifies mw_fWTset_any := {
                        set_ := {
                            fntp := {
                                remotePort := p_remotePort
                            } // End of field 'fntp'
                        } // End of field 'set_'
                } // End of template mdw_fWTset
                
            } // End of group fWTcommands
            
        } // End of group mgtMNSapTemplates
        
    } // End of group mgtSapTemplates
    
} // End of module LibItsMgt_Templates