Sfa Manager Module

This module contains the SFA python manager for token parsing, loading, erasing, etc.

class mtf.diag_port.sfa.sfa_manager.EcuModes

The values for the different modes the ecu can be in

PLANT
ENGINEERING
FIELD
class mtf.diag_port.sfa.sfa_manager.FeatureId

This class contains all the sub-fields of FeatureID secure token field

__init__(feature_id_bytes: str)
property value
property type
property subtype
property no
class mtf.diag_port.sfa.sfa_manager.Feature

This class contains all the information related with a feature retrieved from an ECU via discovery

__init__(feature_bytes: str)
property id
property status
property validation
property token_list

Token objects list parsed from specified folder, matching discovered feature id

Returns:

list of Token objects

property token_available

Returns True if a Token is available from parsed folder, False otherwise

Returns:

bool

class mtf.diag_port.sfa.sfa_manager.TokenTimestamp

This class contains a customized timestamp object for the token. In order to be used easily, when retrieving the object as str, the output is the timestamp value in a readable format (Y-m-d H:M:S). The attribute “value” can be used to get the original hexadecimal value.

__init__(timestamp_bytes)
property value

Raw timestamp value

Returns:

int

class mtf.diag_port.sfa.sfa_manager.FeatureSpecificFields

A class to represent a single Feature Specific Field of a token

__init__(token_bytes: str, offset: int)
class mtf.diag_port.sfa.sfa_manager.ValidityCondition

Class to represent the validity condition of the token

__init__(token_bytes: str, offset: int)
class mtf.diag_port.sfa.sfa_manager.Token

This class contains all the relevant fields of a Secure Token

__init__(token_path)
match_ecuid(ecuid)
match_vinid(vinid)
match_ecuid_and_vinid(vinid, ecuid)
property name
property length
property timestamp
property feature_id
property enable_type
property feature_specific_fields
property raw

Bytearray with the raw bytes value of the token

class mtf.diag_port.sfa.sfa_manager.SfaManager

This class implements a manager to handle token parsing, use and all the functionality related with sfa coming from TDFNext. this module run correctly only if diag manager was already started and all needed controllers already added.

__init__()
set_up(token_path: str)

Prepare environment for sfa manager, parse tokens under token_path This method must be called before calling any token related methods :param token_path: path to folder containing tokens :type token_path: str :return: :rtype:

add_ecu(connection_name: str, ecu_id: str | None = None, vin_id: str | None = None)

This function adds an ECU to the list with all its tokens, checks if the tokens are available int the ECU by sending corresponding diagnosis jobs.

:param
  • connection_name * (str): string with the name of the connection as configured in the diag manager config

  • ecu_id * (str): ECU identifier

  • vin_id * (str): Vehicule Identification Number

Returns:

True if process was successful, False otherwise

update_ecu(connection_name)

Updates all the features status for an ECU, performing a discovery job

Parameters:

connection_name – string containing the name of the target ecu

Returns:

clean_ecu_list()

This function cleans the ecu list completely

Returns:

handle_engineering_token_status(engineering_token_status)

Check for Engineering token status. If Engineering token is Disabled (status == 2) or Expired ( status == 03) we need to generate new tokens

handle_plant_token_status(result, plant_token_status, connection_name, switch_mode_retries)
switch_mode(connection_name: str, target_mode: EcuModes, switch_mode_retries: int = 5)

This function set the mode of a target ecu

Parameters:
  • switch_mode_retries (int) – retries to switch ecu mode

  • connection_name – string containing the name of the target ecu

  • target_mode – target EcuModes enum

Returns:

handle_engineering_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
handle_field_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
handle_plant_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
read_mode(connection_name: str)

This function reads the current mode of the target ecu.

Parameters:

connection_name – string containing the target ecu name

Returns:

EcuModes value if success, None otherwise

write_token(connection_name: str, feature_id: hex, retries=1)

This function enables a specified feature in the target ECU, using the parsed token available.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • retries – int value with the number of retries to perform. The manager will start from the oldest

token within that retry window until the newest token available in the list. :return: True if writing process succeeded, False otherwise. Num of tries performed.

write_specific_token(connection_name: str, feature_id: hex, token_index: int) bool

This function enables a specified feature in the target ECU, using the specified token that is selected by the tc

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • token_index – The index of the token in the sfa manager token list that should be used

Returns:

True if writing process succeeded, False otherwise.

set_feature_status(connection_name: str, feature_id: hex, status: int) bool

This function enable or disable a specific feature based on the status value

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • status – 0 in order to disable the provided feature, 1 in order ro enable it.

Returns:

True if writing process succeeded, False otherwise.

read_status(connection_name: str, feature_id: hex)

This function reads the current status of a feature in the target ecu.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

int in hex format with the status value for the feature, None if process failed

read_sensitive_feature_status(connection_name: str, feature_id: hex)

This function reads the current status of a feature in the target ecu.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

int in hex format with the status value for the sensitive feature, None if process failed

write_sensitive_token(connection_name: str, feature_id: hex, retries=1)

This function enables a specified feature in the target ECU, using the parsed token available.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • retries – int value with the number of retries to perform. The manager will start from the oldest

token within that retry window until the newest token available in the list. :return: True if writing process succeeded, False otherwise. Num of tries performed.

clear_feature(connection_name: str, feature_id: hex)

This function clears a specified feature in the target ECU. Keep in mind that ENGINEERING mode is needed to clear features.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

True if process success, False otherwise

clear_all_features(connection_name: str)

This function clears all the features that have been enabled during the current session for an ecu. Last token to clear is the Engineering mode one, as is needed to set the device in that mode to perform these operations.

Parameters:

connection_name – string with the name of the target ecu

Returns:

True if process success, False otherwise

clear_all_features_mode(connection_name: str, original_mode)

This function clears all the features that have been enabled during the current session for an ecu. Last token to clear is the Engineering mode one, as is needed to set the device in that mode to perform these operations.

Parameters:
  • connection_name – string with the name of the target ecu

  • original_mode – current Ecu mode

Returns:

True if process success, False otherwise

fallback_field_mode(connection_name: str, safe_mode=True)

This function sets the ecu back to FIELD mode from ENGINEERING or PLANT mode. If safe_mode parameter is set to False, the function will skip checking if there is at least, one ENG token available to go back to engineering mode if needed for token clearing.

Parameters:
  • connection_name – string with the name of the target ecu

  • safe_mode – boolean to skip ward’s check for ENG tokens

Returns:

True if process success, False otherwise

property vin_id
get_vin_id(connection_name: str)

This function retrieves the VIN (Vehicle Identification Number) id

Parameters:

connection_name – string containing the name of the target ECU

Returns:

The entire VIN ID as a string. Returns None if an error occurs or if attempting to retrieve the VIN ID of the Device Under Test.

property token_list
get_ecu_id(connection_name)