Main Content

Configure AUTOSAR Sender-Receiver Interface Ports for End-to-End Protection

AUTOSAR end-to-end (E2E) protection for sender and receiver ports is based on the E2E library. E2E is a C library that you use to transmit data securely between AUTOSAR components. E2E protection adds additional information to an outbound data packet. The component receiving the packet can then verify independently that the received data packet matches the sent packet. Potentially, the receiving component can detect errors and take action.

For easier integration of AUTOSAR generated code with AUTOSAR E2E protection, Embedded Coder® supports AUTOSAR E2E protection. In Simulink®, you can:

  • Import AUTOSAR sender ports and receiver ports that are configured for E2E protection.

  • Configure an AUTOSAR sender or receiver port for E2E protection.

  • Generate C and ARXML code for AUTOSAR sender and receiver ports that are configured for E2E protection.

Simulink supports using either the E2E Transformer Error method or the E2E Protection Wrapper to implement E2E protection in the generated code. You can get the configured E2E protection method by using the function getDataDefaults. You set the E2E protection method by using the function setDataDefaults.

The E2E Transformer Error method is invoked by the AUTOSAR runtime environment (RTE). By using the E2E Transformer Error method Rte_Write and Rte_Read calls are created in the generated code that take an additional transformer error argument, Rte_TransformerError, to indicate error status. You can optionally extract the ErrorStatus codes by changing the data type of the ErrorStatus port to uint16.

Note

The E2E Transformer Error method is supported only for AUTOSAR schema version 4.2 or later.

The E2E Protection Wrapper method inserts a wrapper around the Rte_Write and Rte_Read functions. The body of the E2E Protection Wrapper that contains the Rte_Write and Rte_Read calls is implemented external to the generated code. The software defaults to using the E2E Protection Wrapper method if not method is specified.

Configure E2E Protection for individual AUTOSAR sender and receiver ports that use explicit write and read data access modes. When you change the data access mode of an AUTOSAR port from ExplicitWrite to EndToEndWrite, or from ExplicitRead to EndToEndRead, simulation behavior is unaffected. Code generation is similar to ExplicitWrite and ExplicitRead data access modes, with these differences:

Generated ItemE2E Protection WrapperE2E Transformer Error
Generated code for initializationCalls E2EPW_ReadInit_<Port> or E2EPW_WriteInit_<Port>No action
Generated code for function signatureUses uint32 E2EPW_Read_<Port>(data*) or (void) E2EPW_Write_<Port>

When using uint8 or uint16 Rte_Read_<Port>(data*, Rte_TransformerError*) or (void)Rte_Write_<Port>(data, Rte_TransformerError*)

ARXML exporter for receiver and sender COM-SPECsGenerates property USES-END-TO-END-PROTECTION with value trueGenerates property USES-END-TO-END-PROTECTION with value true
ARXML exporter for receiver and sender API extensions PORT-API-OPTIONSNo actionGenerates property ERROR-HANDLING with value TRANSFORMER-ERROR-HANDLING

Configure EndToEndRead and EndToEndWrite Using E2E Transformer Error Protection Method

This example shows how to configure an AUTOSAR sender or receiver port using the Transformer Error E2E protection method.

  1. Open example model autosar_swc_counter or a model that is configured with an AUTOSAR sender-receiver interface.

    modelName = "autosar_swc_counter";
    openExample(modelName);

  2. In the MATLAB Command Window, set TransformerError as the default E2E protection method.

    slMap = autosar.api.getSimulinkMapping(modelName);
    setDataDefaults(slMap,"InportsOutports", ...
        "EndToEndProtectionMethod","TransformerError");

  3. In Simulink, open the Configuration Parameters dialog box. Under Code Generation > AUTOSAR Code Generation verify that the AUTOSAR schema version is 4.2 or later.

  4. In the model, select the input port that enters the Amplifier block.

    Input block on Amplifier block is selected in autosar_swc_counter model.

  5. Open the Code Mappings Editor, in the Inports tab set the AUTOSAR data access mode of the input block to EndToEndRead.

    Inports tab of Code Mappings editor.

  6. In the Outports tab set the AUTOSAR data access mode of the output block to EndToEndWrite.

    Outports tab of Code Mappings editor.

  7. To validate the AUTOSAR component configuration, click the Validate button .

  8. Build the model and inspect the generated code.

    The generated C code contains RTE read and write API calls that pass the transformer error argument.

    void Runnable(void)
    {
      Rte_TransformerError transformerError_Input;
      float64 tmpRead;
      …
      /* Inport: '<Root>/Input' */
        (void)Rte_Read_RPort_InData(&tmpRead, &transformerError_Input);
    
        /* Outport: '<Root>/Output' incorporates:
         *  Gain: '<S1>/Gain'
         *
         * Block description for '<S1>/Gain':
         *  This block references an AUTOSAR calibration parameter, which is
         *  accessed using the AUTOSAR Rte_Calprm function signature.
         */
        (void)Rte_Write_SPort_OutData(Rte_CData_K() * tmpRead,
          &transformerError_Input);
    }
    

    The generated header file Rte_model.h contains the transformer error declaration.

    /* Transformer Classes */
    typedef enum {
      RTE_TRANSFORMER_UNSPECIFIED = 0x00,
      RTE_TRANSFORMER_SERIALIZER = 0x01,
      RTE_TRANSFORMER_SAFETY = 0x02,
      RTE_TRANSFORMER_SECURITY = 0x03,
      RTE_TRANSFORMER_CUSTOM = 0xff
    } Rte_TransformerClass;
    	
    typedef uint8 Rte_TransformerErrorCode;
    
    typedef struct {
      Rte_TransformerErrorCode errorCode;
      Rte_TransformerClass transformerClass;
    } Rte_TransformerError;
    

    The exported ARXML code contains the E2E protection settings for the AUTOSAR receiver and sender ports.

    <REQUIRED-COM-SPECS>
      <NONQUEUED-RECEIVER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>
      …
      <NONQUEUED-SENDER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>
      …
    </REQUIRED-COM-SPECS>
    …
    <PORT-API-OPTIONS>
        <PORT-API-OPTION>
            <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS>
            <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING>
            <INDIRECT-API>false</INDIRECT-API>
            <PORT-REF DEST="R-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/RPort</PORT-REF>
        </PORT-API-OPTION>
        <PORT-API-OPTION>
            <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS>
            <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING>
            <INDIRECT-API>false</INDIRECT-API>
            <PORT-REF DEST="P-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/SPort</PORT-REF>
        </PORT-API-OPTION>
    </PORT-API-OPTIONS>

Configure ErrorStatus Ports using Transformer Error Protection Method

This example shows how to configure an AUTOSAR sender-receiver ErrorStatus port for Transformer Error E2E protection, and optionally extract ErrorStatus codes.

  1. Open example model autosar_swc_counter or a model that is configured with an AUTOSAR sender-receiver interface.

    modelName = "autosar_swc_counter";
    openExample(modelName);

  2. In the MATLAB Command Window, set TransformerError as the default E2E protection method.

    slMap = autosar.api.getSimulinkMapping(modelName);
    setDataDefaults(slMap,"InportsOutports", ...
        "EndToEndProtectionMethod","TransformerError");

  3. Inside the Amplifier subsystem add a Signal Conversion block using the Signal Copy configuration. Connect the Signal Copy block to the input from Input_ErrorStatus and to the output Out_ErrorStatus.

    Contents of the Amplifier block, the Input_ErrorStatus signal being passed through a Signal Copy block with data type uint8.

  4. Add a new Inport block to the Amplifier block and name it Input_ErrorStatus. Set the data type of the Inport block to uint16. Add an Outport block and name it Out_ErrorStatus.

    Amplifier block with the Input_ErrorStatus inport.

  5. Return to the top model and open the Code Mappings editor. On the Inports tab, select Input_ErrorStatus and change the AUTOSAR data access mode to ErrorStatus. Set Port and Element to RPort and InData respectively.

    The Inports tab of the Code Mappings editor. The DataAccessMode of the Input_ErrorStatus is set to ErrorStatus.

  6. On the Outports tab, select Out_ErrorStatus and set DataAccessMode to ImplicitSend, Port to Out_ErrorStatus, and Element to Out_ErrorStatus.

    The Outports tab of the Code Mappings editor. The DataAccessMode of the Out_ErrorStatus is set to ImplicitSend. The element and port are Out_ErrorStatus.

  7. To validate the AUTOSAR component configuration, click the Validate button .

  8. Build the model and inspect the generated code.

    The generated C code contains rtb calls as well as the RTE calls that pass the transformer error argument. The complete error status code is returned by rtb_TmpSignalConversionAtInput_.

    void Runnable_Step(void)
    {
      /* local block i/o variables */
      sint32 rtb_TmpSignalConversionAtInputO;
      uint16 rtb_TmpSignalConversionAtInput_;
      Rte_TransformerError transformerError_Input;
      uint8 error_Input;
    
      /* SignalConversion generated from: '<Root>/Input' incorporates:
       *  Inport: '<Root>/Input'
       */
      error_Input = Rte_Read_RPort_InData(&rtb_TmpSignalConversionAtInputO,
        &transformerError_Input);
      rtb_TmpSignalConversionAtInput_ = (uint16)(transformerError_Input.errorCode <<
        8 | error_Input);
    

    The generated header file Rte_model.h contains the transformer error declaration.

    /* Transformer Classes */
    typedef enum {
      RTE_TRANSFORMER_UNSPECIFIED = 0x00,
      RTE_TRANSFORMER_SERIALIZER = 0x01,
      RTE_TRANSFORMER_SAFETY = 0x02,
      RTE_TRANSFORMER_SECURITY = 0x03,
      RTE_TRANSFORMER_CUSTOM = 0xff
    } Rte_TransformerClass;
    	
    typedef uint8 Rte_TransformerErrorCode;
    
    typedef struct {
      Rte_TransformerErrorCode errorCode;
      Rte_TransformerClass transformerClass;
    } Rte_TransformerError;
    

    The exported ARXML code contains the E2E protection settings for the AUTOSAR receiver and sender ports.

    <REQUIRED-COM-SPECS>
      <NONQUEUED-RECEIVER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>
      …
      <NONQUEUED-SENDER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>
      …
    </REQUIRED-COM-SPECS>
    …
    <PORT-API-OPTIONS>
        <PORT-API-OPTION>
            <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS>
            <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING>
            <INDIRECT-API>false</INDIRECT-API>
            <PORT-REF DEST="R-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/RPort</PORT-REF>
        </PORT-API-OPTION>
        <PORT-API-OPTION>
            <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS>
            <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING>
            <INDIRECT-API>false</INDIRECT-API>
            <PORT-REF DEST="P-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/SPort</PORT-REF>
        </PORT-API-OPTION>
    </PORT-API-OPTIONS>

Configure EndToEndRead and EndToEndWrite Ports Using E2E Protection Wrapper Method

This example shows how to configure an AUTOSAR sender or receiver port using the E2E Protection Wrapper method.

  1. Open example model autosar_swc_counter or a model for which an AUTOSAR sender-receiver interface is configured.

    modelName = "autosar_swc_counter";
    openExample(modelName);

  2. In the MATLAB Command Window, configure ProtectionWrapper as the default E2E protection method.

    slMap = autosar.api.getSimulinkMapping(modelName);
    setDataDefaults(slMap,"InportsOutports", ...
        "EndToEndProtectionMethod","ProtectionWrapper");

  3. In the model, select the input port that enters the Amplifier block.

    Input block on Amplifier block is selected in autosar_swc_counter model.

  4. Open the Code Mappings editor. On the Inports tab set the AUTOSAR data access mode of the input block to EndToEndRead.

  5. On the Outports tab set the AUTOSAR data access mode of the output block to EndToEndWrite.

  6. To validate the AUTOSAR component configuration, click the Validate button .

  7. Build the model and inspect the generated code. The generated C code contains E2E API calls.

    void Runnable_Step(void)
    {
      …
      /* Inport: '<Root>/Input' */
        (void)E2EPW_Read_RPort_InData(&tmpRead);
    
      /* Outport: '<Root>/Output' incorporates:
         *  Gain: '<S1>/Gain'
         *
         * Block description for '<S1>/Gain':
         *  This block references an AUTOSAR calibration parameter, which is
         *  accessed using the AUTOSAR Rte_Calprm function signature.
         */
        (void)E2EPW_Write_SPort_OutData(Rte_CData_K() * tmpRead);
    }
    …
    void Runnable_Init(void)
    {
      /* End-to-End (E2E) Protection Wrapper initialization */
      E2EPW_ReadInit_RPort_InData();
      E2EPW_WriteInit_SPort_OutData();
      …
    }
    

    The exported ARXML code contains the E2E settings for the AUTOSAR receiver and sender ports.

    <NONQUEUED-RECEIVER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>
    …
    <NONQUEUED-SENDER-COM-SPEC>
        …
        <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION>

See Also

Objects

Functions

Related Examples

More About